/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UsersOffices::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $sort = $dataProvider->getSort(); $sort->attributes['officeName'] = ['asc' => ['office.name' => SORT_ASC], 'desc' => ['office.name' => SORT_DESC], 'label' => 'Office Name']; $dataProvider->setSort($sort); $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'); $query->joinWith(['office']); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'profile_id', $this->profile_id])->andFilterWhere(['like', 'profile_office_role', $this->profile_office_role]); $query->joinWith(['office' => function ($q) { $q->andFilterWhere(['like', 'office.name', $this->officeName]); }]); return $dataProvider; }
/** * @param $profile_id * @return array * Возвращает массив ID отделений, где пользователь является управляющим */ protected function getOffiсeIds($profile_id) { $modelsUsersOffices = UsersOffices::findAll(['profile_id' => $profile_id, 'profile_office_role' => 'manager']); return ArrayHelper::map($modelsUsersOffices, 'office_id', 'office_id'); }
/** * Finds the UsersOffices model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UsersOffices the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UsersOffices::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }