TimestampBehavior::class, 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => new Expression('NOW()'), ], ]; } /** * {@inheritdoc} */ public function rules() { return [ [['title', 'status'], 'required'], [['status'], 'integer'], [['created_at', 'updated_at'], 'safe'], [['title'], 'string', 'max' => 255], ['status', 'default', 'value' => self::STATUS_ACTIVE], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'title' => 'Название категории', 'status' => 'Статус', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * @return \yii\db\ActiveQuery */ public function getQuestionnaires() { return $this->hasMany(Questionnaire::className(), ['category_id' => 'id']); } public function getStatuses() { return [ self::STATUS_PASSIVE => 'Не используется', self::STATUS_ACTIVE => 'Активна' ]; } /** * @return string status text label */ public function getStatusText() { return $this->statuses[$this->status]; } public function getIdTitlesArr() { $categories = self::find()->select(['id', 'title'])->where(['status' => '1'])->all(); return ArrayHelper::map($categories,'id','title'); } }