0, ], [ [ 'ratingValue', ], 'number', 'min' => 1, 'max' => 5, ], [ [ 'customer_id', 'text', 'username', 'email', 'ip', 'entity', 'info', ], 'safe', ], ]; } /** * @inheritdoc */ public function attributeLabels() { return array_merge( parent::attributeLabels(), [ 'ratingValue' => \Yii::t('artbox-comment', 'Рейтинг'), 'childrenCount' => \Yii::t('artbox-comment', 'Количество ответов'), ] ); } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CommentModel::find() ->joinWith( [ 'rating', 'customer', ] ); // add conditions that should always apply here $dataProvider = new ActiveDataProvider( [ 'query' => $query, 'sort' => [ 'attributes' => [ 'ratingValue' => [ 'asc' => [ 'artbox_comment_rating.value' => SORT_ASC ], 'desc' => [ 'artbox_comment_rating.value' => SORT_DESC ], ], 'id', 'text', 'customer_id', 'status', 'entity', 'entity_id', 'created_at', ], 'defaultOrder' => [ 'created_at' => SORT_DESC, ], ], ] ); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere( [ 'id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at, 'artbox_comment.status' => $this->status, 'parent_id' => $this->parent_id, 'related_id' => $this->related_id, 'entity_id' => $this->entity_id, ] ); $query->andFilterWhere( [ 'like', 'text', $this->text, ] ) ->andFilterWhere( [ 'like', 'username', $this->username, ] ) ->andFilterWhere( [ 'like', 'email', $this->email, ] ) ->andFilterWhere( [ 'like', 'ip', $this->ip, ] ) ->andFilterWhere( [ 'like', 'entity', $this->entity, ] ) ->andFilterWhere( [ 'like', 'info', $this->info, ] ) ->andFilterWhere( [ 'artbox_comment_rating.value' => $this->ratingValue, ] ); if (!empty($this->customer_id)) { $query->andWhere( [ 'or', [ 'artbox_comment.customer_id' => (int) $this->customer_id ], [ 'like', 'user.username', $this->customer_id, ], [ 'like', 'artbox_comment.username', $this->customer_id, ], [ 'like', 'artbox_comment.email', $this->customer_id, ], ] ); } return $dataProvider; } }