'Новый', 1 => 'Обрабатывается', 2 => 'Нет ответа', 3 => 'Завершен', ]; const SCENARIO_FEEDBACK = 'feedback'; const SCENARIO_CALLBACK = 'callback'; /** * @inheritdoc */ public static function tableName() { return 'feedback'; } /** * @inheritdoc */ public function scenarios() { $scenarios = parent::scenarios(); $scenarios = array_merge( $scenarios, [ self::SCENARIO_FEEDBACK => [ 'name', 'phone', ], self::SCENARIO_CALLBACK => [ 'phone' ], ] ); return $scenarios; } /** * @inheritdoc */ public function behaviors() { return [ [ 'class' => TimestampBehavior::className(), ], [ 'class' => AttributeBehavior::className(), 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => 'ip', ], 'value' => function ($event) { return \Yii::$app->request->userIP; }, ], ]; } /** * @inheritdoc */ public function rules() { return [ [ [ 'status' ], 'integer', ], [ [ 'phone', 'name', ], 'required', ], [ [ 'phone' ], 'match', 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/', ], [ [ 'name', 'phone', ], 'string', 'max' => 255, ], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => Yii::t('app', 'id'), 'name' => Yii::t('app', 'name'), 'phone' => Yii::t('app', 'phone'), 'created_at' => Yii::t('app', 'created_at'), 'ip' => Yii::t('app', 'ip'), 'status' => Yii::t('app', 'status'), 'manager_id' => Yii::t('app', 'manager'), 'updated_at' => Yii::t('app', 'updated_at'), ]; } /** * Manager wich first ecited status field * * @return \yii\db\ActiveQuery */ public function getManager() { return $this->hasOne(User::className(), [ 'id' => 'manager_id' ]); } }