_task)) { $this->addError('_task', 'X is not array!'); } } public function byId() { if ($this->id) { return UserCard::find() ->where(['id' => $this->id]) ->with(['skillValues']) ->with(['achievements']) ->asArray() ->one(); } return null; } public function byParams() { $model = UserCard::find(); if($this->skills){ $model->joinWith(['skillValues']); $this->skills = explode(',', $this->skills); $model->where(['card_skill.skill_id' => $this->skills]); $model->having('COUNT(DISTINCT skill_id) = ' . count($this->skills)); } else{ $model->joinWith('skillValues'); } if($this->achievements){ $model->joinWith(['achievements']); $this->achievements = explode(',', $this->achievements); $model->where(['achievement_user_card.achievement_id' => $this->achievements]); $model->having('COUNT(DISTINCT achievement_id) = ' . count($this->achievements)); } else{ $model->joinWith('achievements'); } $model->andFilterWhere(['position_id' => $this->position_id]); $model->andWhere(['status' => [4, 12]]); $model->andWhere(['deleted_at' => null]); $model->groupBy('card_skill.card_id'); return $model->limit($this->limit) ->offset($this->offset)->orderBy('updated_at DESC')->asArray()->all(); } }