BlameableBehavior::className(), 'createdByAttribute' => 'user_id', 'updatedByAttribute' => false, ], [ 'class' => TimestampBehavior::className(), 'createdAtAttribute' => 'date_add', 'updatedAtAttribute' => false, 'value' => new Expression('NOW()'), ], ]; } /** * @inheritdoc */ public function rules() { return [ [ [ 'name', 'description', 'city', 'link' ], 'required', ], [ [ 'description' ], 'string', ], [ [ 'employmentInput', 'specializationInput' ], 'safe', ], [ [ 'employmentInput', 'specializationInput' ], 'default', 'value' => [], ], [ [ 'view_count' ], 'default', 'value' => 0, ], [ [ 'name', 'link', 'user_name', 'city', ], 'string', 'max' => 255, ], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'vacancy_id' => Yii::t('app', 'Vacancy ID'), 'user_id' => Yii::t('app', 'User ID'), 'name' => Yii::t('app', 'Название'), 'link' => Yii::t('app', 'URL'), 'date_add' => Yii::t('app', 'Дата добавления'), 'user_add_id' => Yii::t('app', 'User Add ID'), 'view_count' => Yii::t('app', 'Количество просмотров'), 'user_name' => Yii::t('app', 'Контактное лицо'), 'city' => Yii::t('app', 'Город'), 'description' => Yii::t('app', 'Описание'), 'employmentInput' => Yii::t('app', 'Вид занятости'), 'phone' => Yii::t('app', 'Телефон'), 'salary' => Yii::t('app', 'Заработная плата'), 'salary_currency' => Yii::t('app', 'Валюта'), ]; } /** * @return \yii\db\ActiveQuery */ public function getVacancyEmployments() { return $this->hasMany(VacancyEmployment::className(), [ 'vacancy_id' => 'vacancy_id' ]); } public function getEmployments() { return $this->hasMany(Employment::className(), [ 'employment_id' => 'employment_id' ]) ->viaTable('vacancy_employment', [ 'vacancy_id' => 'vacancy_id' ]); } public function getEmploymentInput() { return $this->getEmployments() ->asArray() ->column(); } public function setEmploymentInput($value) { $this->employmentInput = $value; } public function getRequirements() { return Fields::getData($this->vacancy_id, Vacancy::className(), 'requirements'); } /** * @return ActiveQuery */ public function getSpecializations() { return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ]) ->viaTable('vacancy_specialization', [ 'vacancy_id' => 'vacancy_id' ]); } /** * Return array of Vacancy's specialization IDs * @return integer[] */ public function getSpecializationInput() { return $this->getSpecializations() ->asArray() ->indexBy('specialization_id') ->column(); } /** * Setter which allow to set Vacancy's specializations for further saving to the DB. * * @param integer[] $value */ public function setSpecializationInput($value) { $this->specializationInput = $value; } }