diff --git a/common/models/Job.php b/common/models/Job.php index 8bb288a..f15732c 100755 --- a/common/models/Job.php +++ b/common/models/Job.php @@ -1,108 +1,123 @@ [ - 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'name', - 'out_attribute' => 'link', - 'translit' => true - ] - ]; - } + /** + * @inheritdoc + */ + public static function tableName() + { + return 'job'; + } - public function beforeSave($insert) - { - $this->date_start = \Yii::$app->formatter->asDatetime($this->date_start, 'Y-MM-d HH:mm:ss'); + /** + * @inheritdoc + */ + public function behaviors() + { + return [ - if($this->date_end) { - $this->date_end = \Yii::$app->formatter->asDatetime($this->date_end, 'Y-MM-d HH:mm:ss'); + ]; } + public function beforeSave($insert) + { + $this->date_start = \Yii::$app->formatter->asDatetime($this->date_start, 'Y-MM-d HH:mm:ss'); - return parent::beforeSave($insert); // TODO: Change the autogenerated stub - } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['name'], 'required'], - [['date_start', 'date_end'], 'safe'], - [['user_id', 'total_count', 'complete_count', 'current'], 'integer'], - [['name', 'link', 'position'], 'string', 'max' => 255] - ]; - } - + if($this->date_end) { + $this->date_end = \Yii::$app->formatter->asDatetime($this->date_end, 'Y-MM-d HH:mm:ss'); + } + return parent::beforeSave($insert); // TODO: Change the autogenerated stub + } - public function getExpTime() - { - if($this->date_end && $this->date_start){ - $date = new \DateTime(date('Y-m-d H:i:s', $this->date_start)); - return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime(date('Y-m-d H:i:s', $this->date_end)))); - } elseif($this->date_start) { - $now = new \DateTime(); - $date = new \DateTime(date('Y-m-d H:i:s', strtotime($this->date_start))); - return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime())); - } else { - return 'неизвестна дата начала'; + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'name' ], + 'required', + ], + [ + [ + 'date_start', + 'date_end', + ], + 'safe', + ], + [ + [ + 'user_id', + 'total_count', + 'complete_count', + 'current', + ], + 'integer', + ], + [ + [ + 'name', + 'link', + 'position', + ], + 'string', + 'max' => 255, + ], + ]; } - } + public function getExpTime() + { + if($this->date_end && $this->date_start) { + $date = new \DateTime(date('Y-m-d H:i:s', $this->date_start)); + return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime(date('Y-m-d H:i:s', $this->date_end)))); + } elseif($this->date_start) { + $now = new \DateTime(); + $date = new \DateTime(date('Y-m-d H:i:s', strtotime($this->date_start))); + return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime())); + } else { + return 'неизвестна дата начала'; + } + } - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'job_id' => Yii::t('app', 'Job ID'), - 'name' => Yii::t('app', 'Name'), - 'link' => Yii::t('app', 'Link'), - 'date_start' => Yii::t('app', 'Date Start'), - 'date_end' => Yii::t('app', 'Date End'), - 'position' => Yii::t('app', 'Position'), - 'user_id' => Yii::t('app', 'User ID'), - 'total_count' => Yii::t('app', 'Total Count'), - 'complete_count' => Yii::t('app', 'Complete Count'), - 'current' => Yii::t('app', 'Current'), - ]; + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'job_id' => Yii::t('app', 'Job ID'), + 'name' => Yii::t('app', 'Name'), + 'link' => Yii::t('app', 'Link'), + 'date_start' => Yii::t('app', 'Date Start'), + 'date_end' => Yii::t('app', 'Date End'), + 'position' => Yii::t('app', 'Position'), + 'user_id' => Yii::t('app', 'User ID'), + 'total_count' => Yii::t('app', 'Total Count'), + 'complete_count' => Yii::t('app', 'Complete Count'), + 'current' => Yii::t('app', 'Current'), + ]; + } } -} diff --git a/common/models/User.php b/common/models/User.php index a0d46bf..78120e2 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -133,6 +133,14 @@ 'default', 'value' => 1, ], + [ + [ + 'specializationInput', + 'paymentInput', + ], + 'default', + 'value' => [ ], + ], ]; } @@ -513,7 +521,7 @@ */ public function getJobs() { - return $this->hasMany(Job::className(), [ 'user_id' => 'id' ]); + return $this->hasMany(Job::className(), [ 'user_id' => 'id' ])->orderBy(['current' => SORT_DESC]); } /** @@ -771,4 +779,30 @@ ]); }); } + + public function getBookmarksVacancies() + { + return $this->hasMany(Vacancy::className(), [ 'vacancy_id' => 'model_id' ]) + ->viaTable('{{%bookmark}}', [ 'user_id' => 'id' ], function($query) { + /** + * @var ActiveQuery $query + */ + $query->andWhere([ + 'model' => Vacancy::className(), + 'type' => Bookmark::TYPE_VACANCY, + ]); + }); + } + + public function getChatCount() + { + return Chat::find() + ->select('COUNT(*)') + ->where([ + 'or', + [ 'from_user' => $this->id ], + [ 'to_user' => $this->id ], + ]) + ->scalar(); + } } diff --git a/common/models/UserInfo.php b/common/models/UserInfo.php index 1af7f1b..7b14f76 100755 --- a/common/models/UserInfo.php +++ b/common/models/UserInfo.php @@ -315,4 +315,9 @@ $this->geographies = $value; } + public function getCurrency() + { + return $this->hasOne(Currency::className(), ['currency_id' => 'salary_currency']); + } + } diff --git a/common/modules/comment/Controller.php b/common/modules/comment/Controller.php index d0ce56f..d2db544 100644 --- 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/models/CommentProject.php b/common/modules/comment/models/CommentProject.php index 635bb3d..eb57c36 100644 --- a/common/modules/comment/models/CommentProject.php +++ b/common/modules/comment/models/CommentProject.php @@ -25,6 +25,7 @@ * @property float $budget_to * @property int $term_from * @property int $term_to + * @property int $state * @property Currency $currency * @package common\modules\comment\models */ @@ -38,8 +39,16 @@ 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 @@ -108,6 +117,29 @@ '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, + ], ]; } @@ -125,6 +157,9 @@ self::SCENARIO_GUEST => [ ], + self::SCENARIO_STATE => [ + 'state', + ], ]; } @@ -370,7 +405,20 @@ */ public function getUser() { - return $this->hasOne(User::className(), ['id' => 'user_id']); + 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/rbac/ArtboxCommentCreateRule.php b/common/modules/comment/rbac/ArtboxCommentCreateRule.php index 6f481fc..1f7ee06 100644 --- a/common/modules/comment/rbac/ArtboxCommentCreateRule.php +++ b/common/modules/comment/rbac/ArtboxCommentCreateRule.php @@ -11,7 +11,24 @@ 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) + { + $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/widgets/CommentWidget.php b/common/modules/comment/widgets/CommentWidget.php index cf8b2a3..41b8ccd 100644 --- 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); diff --git a/common/modules/comment/widgets/views/_project_comment_view.php b/common/modules/comment/widgets/views/_project_comment_view.php index 1f68b07..d35e120 100644 --- a/common/modules/comment/widgets/views/_project_comment_view.php +++ b/common/modules/comment/widgets/views/_project_comment_view.php @@ -82,7 +82,7 @@ - = Html::a(count($user->comments). ' отзывов', $user->getLink('review'), ['class' => 'link-to-comm']) ?> + = Html::a(count($user->comments) . ' отзывов', $user->getLink('review'), [ 'class' => 'link-to-comm' ]) ?>