diff --git a/models/Feedback.php b/models/Feedback.php index 06d9193..541dc0e 100755 --- a/models/Feedback.php +++ b/models/Feedback.php @@ -2,6 +2,7 @@ namespace artweb\artbox\models; + use backend\models\User; use Yii; use yii\behaviors\AttributeBehavior; use yii\behaviors\TimestampBehavior; @@ -14,10 +15,20 @@ * @property string $name * @property string $phone * @property integer $created_at + * @property integer $updated_at * @property string $ip + * @property integer $status + * @property integer $manager_id + * @property User $manager */ class Feedback extends ActiveRecord { + const STATUSES = [ + 0 => 'Новый', + 1 => 'Обрабатывается', + 2 => 'Нет ответа', + 3 => 'Завершен', + ]; const SCENARIO_FEEDBACK = 'feedback'; const SCENARIO_CALLBACK = 'callback'; @@ -56,8 +67,7 @@ { return [ [ - 'class' => TimestampBehavior::className(), - 'updatedAtAttribute' => false, + 'class' => TimestampBehavior::className(), ], [ 'class' => AttributeBehavior::className(), @@ -78,6 +88,10 @@ { return [ [ + [ 'status' ], + 'integer', + ], + [ [ 'phone', 'name', @@ -111,6 +125,19 @@ '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' ]); + } } diff --git a/models/FeedbackSearch.php b/models/FeedbackSearch.php index 51cb6ce..0ea356d 100755 --- a/models/FeedbackSearch.php +++ b/models/FeedbackSearch.php @@ -46,13 +46,21 @@ */ public function search($params) { - $query = Feedback::find(); + $query = Feedback::find() + ->orderBy( + [ + 'created_at' => SORT_DESC, + ] + )->with('manager'); // add conditions that should always apply here $dataProvider = new ActiveDataProvider( [ 'query' => $query, + 'pagination' => [ + 'pageSize' => 50, + ], ] ); -- libgit2 0.21.4