diff --git a/.gitignore b/.gitignore index cc82398..8f6344e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/tests # yii console command /yii diff --git a/common/config/main.php b/common/config/main.php index 3a6bf4e..721a1c5 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -36,6 +36,9 @@ return [ ] ], ], + 'authManager' => [ + 'class' => 'yii\rbac\DbManager', + ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], diff --git a/common/modules/comment/Controller.php b/common/modules/comment/Controller.php index d0ce56f..d2db544 100755 --- a/common/modules/comment/Controller.php +++ b/common/modules/comment/Controller.php @@ -93,4 +93,5 @@ \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; \Yii::$app->response->send(); } + } \ No newline at end of file diff --git a/common/modules/comment/assets/CommentAsset.php b/common/modules/comment/assets/CommentAsset.php index edf61a8..3db5e5c 100755 --- a/common/modules/comment/assets/CommentAsset.php +++ b/common/modules/comment/assets/CommentAsset.php @@ -3,6 +3,7 @@ class CommentAsset extends \yii\web\AssetBundle { + public $sourcePath = '@common/modules/comment/resources'; public $css = [ @@ -18,4 +19,8 @@ '\yii\web\JqueryAsset', ]; + public $jsOptions = [ + 'position' => \yii\web\View::POS_READY, + ]; + } \ No newline at end of file diff --git a/common/modules/comment/models/Comment.php b/common/modules/comment/models/Comment.php index 8796389..ee0708a 100755 --- a/common/modules/comment/models/Comment.php +++ b/common/modules/comment/models/Comment.php @@ -1,6 +1,7 @@ model == User::className()) { + if($user = User::findOne($this->model_id)) { + /** + * @var User $user + */ + $user->updateRating(); + } + } + parent::afterSave($insert, $changedAttributes); + } + + /** + * @inheritdoc + */ public static function tableName() { return '{{%comment}}'; @@ -157,7 +176,7 @@ 'comment.model' => $model, 'comment.model_id' => $model_id, 'comment.status' => 1, - ]); + ])->with('rating'); } public function postComment() @@ -294,7 +313,7 @@ 'model' => $this->className(), ]) ->one(); - if(!$rating instanceof \common\modules\comment\models\Rating) { + if(!$rating instanceof \common\modules\comment\models\Rating && !empty($this->primaryKey)) { $rating = new \common\modules\comment\models\Rating([ 'model' => $this->className(), 'model_id' => $this->comment_id, @@ -331,4 +350,9 @@ } } + public function getUser() + { + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); + } + } diff --git a/common/modules/comment/models/CommentProject.php b/common/modules/comment/models/CommentProject.php index 7cc3793..173e2d8 100755 --- a/common/modules/comment/models/CommentProject.php +++ b/common/modules/comment/models/CommentProject.php @@ -3,26 +3,32 @@ use common\models\Currency; use common\models\File; + use common\models\Project; + use common\models\User; use yii\db\ActiveQuery; + use yii\db\ActiveRecord; use yii\web\UploadedFile; /** * Class Comment - * @property bool $guestComment - * @property integer $comment_id - * @property string $text - * @property int $user_id - * @property int $status - * @property string $date_add - * @property string $date_update - * @property string $date_delete - * @property string $model - * @property int $model_id - * @property string $files - * @property float $budget_from - * @property float $budget_to - * @property int $term_from - * @property int $term_to + * @property bool $guestComment + * @property integer $comment_id + * @property string $text + * @property int $user_id + * @property int $status + * @property string $date_add + * @property string $date_update + * @property string $date_delete + * @property string $model + * @property int $model_id + * @property string $files + * @property float $budget_from + * @property float $budget_to + * @property int $term_from + * @property int $term_to + * @property int $state + * @property Currency $currency + * @property Project $project * @package common\modules\comment\models */ class CommentProject extends \yii\db\ActiveRecord @@ -35,13 +41,22 @@ const STATUS_PERSONAL = 3; const STATUS_ANONYMOUS = 4; + const STATE_NEW = 1; + const STATE_CANDIDATE = 2; + const STATE_PERFORMER = 3; + const STATE_DENY = 4; + const STATE_TRASH = 5; + const SCENARIO_USER = 'user'; const SCENARIO_GUEST = 'guest'; + const SCENARIO_STATE = 'state'; + const SCENARIO_OWNER = 'owner'; /** * @var bool */ public $guestComment = false; + public $file; public function rules() @@ -84,7 +99,7 @@ [ [ 'budget_currency' ], 'exist', - 'targetClass' => Currency::className(), + 'targetClass' => Currency::className(), 'targetAttribute' => 'currency_id', ], [ @@ -104,6 +119,32 @@ 'default', 'value' => 1, ], + [ + [ 'state' ], + 'integer', + 'max' => 4, + 'min' => 1, + 'on' => self::SCENARIO_STATE, + ], + [ + [ 'state' ], + 'required', + 'on' => self::SCENARIO_STATE, + ], + [ + [ 'state' ], + 'required', + 'on' => self::SCENARIO_OWNER, + ], + [ + [ 'state' ], + 'in', + 'range' => [ + 1, + 5, + ], + 'on' => self::SCENARIO_OWNER, + ], ]; } @@ -118,9 +159,15 @@ 'term_to', 'file', ], - self::SCENARIO_GUEST => [ + self::SCENARIO_GUEST => [ ], + self::SCENARIO_STATE => [ + 'state', + ], + self::SCENARIO_OWNER => [ + 'state', + ], ]; } @@ -150,11 +197,11 @@ public function attributeLabels() { return [ - 'text' => \Yii::t('app', 'Текст ответа'), + 'text' => \Yii::t('app', 'Текст ответа'), 'budget_from' => \Yii::t('app', 'от'), - 'budget_to' => \Yii::t('app', 'до'), - 'term_from' => \Yii::t('app', 'от'), - 'term_to' => \Yii::t('app', 'до'), + 'budget_to' => \Yii::t('app', 'до'), + 'term_from' => \Yii::t('app', 'от'), + 'term_to' => \Yii::t('app', 'до'), ]; } @@ -163,10 +210,10 @@ return $this->guestComment; } -// public function setGuestComment($value) -// { -// $this->guestComment = $value; -// } + // public function setGuestComment($value) + // { + // $this->guestComment = $value; + // } /** * @param string $model @@ -181,27 +228,28 @@ 'comment_project.model' => $model, 'comment_project.model_id' => $model_id, 'comment_project.status' => 1, - ]); + ]) + ->with('currency', 'user', 'user.userInfo', 'user.companyInfo', 'user.comments'); } public function postComment() { if($this->checkCreate()) { - if(!empty(\Yii::$app->request->post($this->formName())['anonymous'])) { + if(!empty( \Yii::$app->request->post($this->formName())[ 'anonymous' ] )) { $this->status = self::STATUS_ANONYMOUS; } $this->file = UploadedFile::getInstances($this, 'file'); - if(!empty($this->file)) { - $file_id = []; - if(is_array($this->file)){ - foreach($this->file as $file){ - if($file instanceof UploadedFile){ + if(!empty( $this->file )) { + $file_id = [ ]; + if(is_array($this->file)) { + foreach($this->file as $file) { + if($file instanceof UploadedFile) { $file_model = new File(); $file_id[] = $file_model->saveFile($file); } } } else { - if($this->file instanceof UploadedFile){ + if($this->file instanceof UploadedFile) { $file_model = new File(); $file_id[] = $file_model->saveFile($this->file); } @@ -325,4 +373,65 @@ // } } + /** + * @return ActiveQuery + */ + public function getCurrency() + { + return $this->hasOne(Currency::className(), [ 'currency_id' => 'budget_currency' ]); + } + + /** + * @return File[] + */ + public function getFilesList() + { + $files = json_decode($this->files); + if(!empty( $files )) { + return File::findAll($files); + } else { + return [ ]; + } + } + + /** + * @return ActiveRecord + * @throws \TypeError + */ + public function getOwner() + { + $model = new $this->model(); + if($model instanceof ActiveRecord) { + return $model->findOne($this->model_id); + } else { + throw new \TypeError('Model must extends Active Record Class'); + } + } + + public function getProject() + { + return $this->hasOne(Project::className(), [ 'project_id' => 'model_id' ]); + } + + /** + * @return User + */ + public function getUser() + { + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); + } + + public function changeState() + { + if($this->isAttributeChanged('state')) { + if($this->save()) { + return true; + } else { + return false; + } + } else { + return true; + } + } + } diff --git a/common/modules/comment/models/CommentProjectSearch.php b/common/modules/comment/models/CommentProjectSearch.php new file mode 100644 index 0000000..aae75ab --- /dev/null +++ b/common/modules/comment/models/CommentProjectSearch.php @@ -0,0 +1,92 @@ + 5, + 'min' => 1, + ], + [ + [ + 'state', + ], + 'default', + 'value' => self::STATE_NEW, + ], + ]; + } + + public function scenarios() + { + return array_merge(parent::scenarios(), [ + self::SCENARIO_SEARCH => [ + 'state', + ], + ]); + } + + public function search($params) + { + $query = CommentProject::find() + ->with('project') + ->with('project.budgetCurrency') + ->with('project.comments') + ->where([ 'user_id' => \Yii::$app->user->getId() ]); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if(!$this->validate()) { + $query->andWhere('0=1'); + return $dataProvider; + } + + $query->andWhere([ 'state' => $this->state ]); + + return $dataProvider; + } + + } diff --git a/common/modules/comment/rbac/ArtboxCommentCreateRule.php b/common/modules/comment/rbac/ArtboxCommentCreateRule.php index 6f481fc..9dbf0a3 100755 --- a/common/modules/comment/rbac/ArtboxCommentCreateRule.php +++ b/common/modules/comment/rbac/ArtboxCommentCreateRule.php @@ -11,7 +11,28 @@ public function execute($user, $item, $params) { + if($params[ 'model' ] == \common\models\Project::className()) { + return $this->checkProject($user, $item, $params); + } return true; } + public function checkProject($user, $item, $params) + { + $project = \common\models\Project::findOne($params['model_id']); + if($project->user_id == $user) { + return false; + } + $comment = \common\modules\comment\models\CommentProject::find() + ->where([ 'model' => $params[ 'model' ], + 'model_id' => $params[ 'model_id' ], + 'user_id' => $user, + ])->one(); + if(empty($comment)) { + return true; + } else { + return false; + } + } + } \ No newline at end of file diff --git a/common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php b/common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php index 27d8b11..7d921e3 100755 --- a/common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php +++ b/common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php @@ -11,7 +11,7 @@ public function execute($user, $item, $params) { - return true; + return false; } } \ No newline at end of file diff --git a/common/modules/comment/widgets/CommentWidget.php b/common/modules/comment/widgets/CommentWidget.php index 52c316f..9c9dd6e 100755 --- a/common/modules/comment/widgets/CommentWidget.php +++ b/common/modules/comment/widgets/CommentWidget.php @@ -167,7 +167,7 @@ $this->parts[ 'list' ] = Html::tag($tag, $this->renderItems($view), $this->list_options); } - if($this->display_comment_form) { + if($this->display_comment_form && $this->comment_class->checkCreate()) { $tag = ArrayHelper::remove($this->form_options, 'tag', 'div'); $view = ArrayHelper::remove($this->form_options, 'view'); $this->parts[ 'form' ] = Html::tag($tag, $this->renderForm($view), $this->form_options); @@ -197,12 +197,16 @@ if(empty( $view )) { throw new \yii\base\InvalidConfigException("form_options[view] must be set"); } - return $this->render($view, [ - 'model' => $this->comment_class, - 'rating' => $this->rating_class, - 'user' => \Yii::$app->user->identity, - 'dataProvider' => $this->dataProvider, - ]); + if($this->comment_class->guestComment || !empty(\Yii::$app->user->identity)) { + return $this->render($view, [ + 'model' => $this->comment_class, + 'rating' => $this->rating_class, + 'user' => \Yii::$app->user->identity, + 'dataProvider' => $this->dataProvider, + ]); + } else { + return ''; + } } public function renderWidget() @@ -221,8 +225,11 @@ { $data = \Yii::$app->request->post(); if($this->comment_class->load($data) && $this->comment_class->postComment()) { - if(is_object($this->rating_class) && $this->comment_class->rating->load($data) && $this->comment_class->rating->save()) { - $this->isSuccess = true; + if(is_object($this->rating_class)) { + $this->comment_class->checkRating(); + if($this->comment_class->rating->load($data) && $this->comment_class->rating->save()) { + $this->isSuccess = true; + } } } } diff --git a/common/modules/comment/widgets/views/_project_comment_view.php b/common/modules/comment/widgets/views/_project_comment_view.php index 8e3c04f..d35e120 100755 --- a/common/modules/comment/widgets/views/_project_comment_view.php +++ b/common/modules/comment/widgets/views/_project_comment_view.php @@ -10,13 +10,7 @@ * @var \yii\widgets\ListView $widget current ListView instance * @var User $user */ - $user = NULL; - if(!empty( $model->user_id )) { - $user = User::find() - ->where([ 'id' => $model->user_id ]) - ->with('userInfo') - ->one(); - } + $user = $model->user; ?>
1.1 Строительная площадка расположена по адресу: г. Киев.
-1.2 Существующий объект представляет собой помещение общей площадью ориентировочно – 140 м2.
-1.3. Цель проекта состоит в проведении внутренних общестроительных и отделочных работ.
-1.4. При разработке методов строительства и выборе материалов, используемых в настоящем проекте, необходимо учитывать климатические условия, характерные для г. Киева.
-1.5. Требования к проектированию и производству работ определяются следующими документами:
-- Техническим заданием.
-- Строительными нормами и правилами.
-Все проектные решения и все разделы рабочего проекта должны быть согласованы с Заказчиком в объеме, необходимом для последующей сдачи инженерных систем и коммуникаций.
+ = $model->text ?>