/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Membership::find(); $membershipTable = Membership::tableName(); $teamTable = Team::tableName(); $playerTable = Player::tableName(); $ampluaTable = Amplua::tableName(); $query->joinWith(['team' => function ($query) use($teamTable) { $query->from(['team' => $teamTable]); }]); $query->joinWith(['amplua' => function ($query) use($ampluaTable) { $query->from(['amplua' => $ampluaTable]); }]); $query->joinWith(['player' => function ($query) use($playerTable) { $query->from(['player' => $playerTable]); }]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]); // enable sorting for the related columns $addSortAttributes = ["team.name", "amplua.name", "player.name"]; foreach ($addSortAttributes as $addSortAttribute) { $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]]; } if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(["{$membershipTable}.id" => $this->id, 'command_id' => $this->command_id, 'player_id' => $this->player_id, 'number' => $this->number, 'amplua_id' => $this->amplua_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'team.name', $this->getAttribute('team.name')]); $query->andFilterWhere(['like', 'player.lastname', $this->getAttribute('player.name')]); $query->andFilterWhere(['like', 'amplua.name', $this->getAttribute('amplua.name')]); return $dataProvider; }
public function actionMbMemberships() { $getVars = Yii::$app->request->queryParams; $mbFk = $getVars["membership"]["\$id"]; $query = Membership::find()->where(['merchant_brand_fk' => new \MongoId($mbFk)]); $searchModel = new MembershipSearch(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function actionMbMemberships() { $currUser = Yii::$app->user->getIdentity(); $currMb = MerchantBrand::find()->where(['merchant_brand_id' => $currUser->username])->one(); $mbFk = $currMb->_id; $query = Membership::find()->where(['merchant_brand_fk' => new \MongoId($mbFk)]); $searchModel = new MembershipSearch(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Membership::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } $query->andFilterWhere(['like', '_id', $this->_id])->andFilterWhere(['like', 'membership_unique_id', $this->membership_unique_id])->andFilterWhere(['like', 'membership_login_id', $this->membership_login_id])->andFilterWhere(['like', 'membership_first_name', $this->membership_first_name])->andFilterWhere(['like', 'membership_last_name', $this->membership_last_name])->andFilterWhere(['like', 'membership_gender', $this->membership_gender])->andFilterWhere(['like', 'membership_date_of_birth', $this->membership_date_of_birth])->andFilterWhere(['like', 'membership_district', $this->membership_district])->andFilterWhere(['like', 'membership_address', $this->membership_address])->andFilterWhere(['like', 'membership_contact_telephone', $this->membership_contact_telephone])->andFilterWhere(['like', 'membership_email_address', $this->membership_email_address])->andFilterWhere(['like', 'membership_current_points', $this->membership_current_points])->andFilterWhere(['like', 'membership_current_reputation', $this->membership_current_reputation])->andFilterWhere(['like', 'membership_date_of_joining', $this->membership_date_of_joining])->andFilterWhere(['like', 'membership_status', $this->membership_status])->andFilterWhere(['like', 'merchant_brand_fk', $this->merchant_brand_fk])->andFilterWhere(['like', 'membership_profile_image', $this->membership_profile_image]); return $dataProvider; }
/** * Updates an existing Match model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $model->date = date('d.m.Y H:i', strtotime($model->date)); // compositionForm $compositionForm = new CompositionForm(); $compositionForm->match_id = $model->id; $compositionForm->initPlayers($model->command_home_id, $model->command_guest_id); $searchModel = new CompositionSearch(); // homeCompositionDataProvider $params = ['CompositionSearch' => ['match_id' => $model->id, 'command_id' => $model->command_home_id]]; $homeCompositionDataProvider = $searchModel->search($params); $homeCompositionDataProvider->setSort(['defaultOrder' => ['is_basis' => SORT_DESC, 'number' => SORT_ASC]]); // guestCompositionDataProvider $params = ['CompositionSearch' => ['match_id' => $model->id, 'command_id' => $model->command_guest_id]]; $guestCompositionDataProvider = $searchModel->search($params); $guestCompositionDataProvider->setSort(['defaultOrder' => ['is_basis' => SORT_DESC, 'number' => SORT_ASC]]); $contractTeams = Team::getContractTeams(); // homeComposition if (in_array($model->command_home_id, $contractTeams)) { $homeContractType = CompositionForm::CONTRACT_TYPE; $homeCompositionData = Contract::find()->where(['command_id' => $model->command_home_id, 'season_id' => $model->season_id, 'is_active' => 1])->orderBy(['number' => SORT_ASC])->all(); } else { $homeContractType = CompositionForm::MEMBERSHIP_TYPE; $homeCompositionData = Membership::find()->where(['command_id' => $model->command_home_id])->orderBy(['number' => SORT_ASC])->all(); } $homeComposition = []; foreach ($homeCompositionData as $key => $data) { $homeComposition[$key]['id'] = $data->id; $homeComposition[$key]['name'] = "#" . $data->number . " " . $data->player->lastname . " " . $data->player->firstname; } // guestComposition if (in_array($model->command_guest_id, $contractTeams)) { $guestContractType = CompositionForm::CONTRACT_TYPE; $guestCompositionData = Contract::find()->where(['command_id' => $model->command_guest_id, 'season_id' => $model->season_id, 'is_active' => 1])->orderBy(['number' => SORT_ASC])->all(); } else { $guestContractType = CompositionForm::MEMBERSHIP_TYPE; $guestCompositionData = Membership::find()->where(['command_id' => $model->command_guest_id])->orderBy(['number' => SORT_ASC])->all(); } $guestComposition = []; foreach ($guestCompositionData as $key => $data) { $guestComposition[$key]['id'] = $data->id; $guestComposition[$key]['name'] = "#" . $data->number . " " . $data->player->lastname . " " . $data->player->firstname; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->date = date('Y-m-d H:i', strtotime($model->date)); $model->save(false); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', compact('model', 'compositionForm', 'homeComposition', 'guestComposition', 'homeContractType', 'guestContractType', 'homeCompositionDataProvider', 'guestCompositionDataProvider')); } }