/**
  * 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;
 }
 /**
  * Creates a new Composition model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($matchId = null, $teamId = null)
 {
     $model = new Composition();
     if (!isset($matchId) || !isset($teamId)) {
         throw new \yii\web\BadRequestHttpException('Unidentified matchId and teamId');
     }
     $match = Match::findOne($matchId);
     $team = Team::findOne($teamId);
     if (!isset($match) || !isset($team)) {
         throw new \yii\web\BadRequestHttpException('Unidentified match and team models');
     }
     $model->command_id = $teamId;
     $model->match_id = $matchId;
     $model->is_basis = 1;
     $contractTeams = Team::getContractTeams();
     if (in_array($teamId, $contractTeams)) {
         $model->contract_type = Composition::CONTRACT_TYPE;
         $contractModel = new Contract();
         $contractModel->season_id = $match->season_id;
         $contractModel->is_active = 1;
     } else {
         $model->contract_type = Composition::MEMBERSHIP_TYPE;
         $contractModel = new Membership();
     }
     $contractModel->command_id = $teamId;
     if ($model->load(Yii::$app->request->post()) && $contractModel->load(Yii::$app->request->post()) && $contractModel->validate()) {
         if ($contractModel->save(false)) {
             $model->contract_id = $contractModel->id;
             $model->number = $contractModel->number;
             $model->save();
         }
         if (Yii::$app->request->isAjax) {
             $out = ['success' => 'true'];
             return Json::encode($out);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('create', ['model' => $model, 'contractModel' => $contractModel]);
         }
         return $this->render('create', ['model' => $model, 'contractModel' => $contractModel]);
     }
 }
 /**
  * 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;
 }
 /**
  * Finds the Membership model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Membership the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Membership::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMemberships()
 {
     return $this->hasMany(Membership::className(), ['command_id' => 'id']);
 }
Exemple #6
0
 public function getMemberships()
 {
     return $this->hasMany(Membership::className(), ['merchant_brand_fk' => '_id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContract()
 {
     if ($this->getContractType() == self::CONTRACT_TYPE) {
         return $this->hasOne(Contract::className(), ['id' => 'contract_id']);
     } elseif ($this->getContractType() == self::MEMBERSHIP_TYPE) {
         return $this->hasOne(Membership::className(), ['id' => 'contract_id']);
     } else {
         return null;
     }
 }
 /**
  * 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'));
     }
 }
Exemple #9
0
 /**
  * Signs user up.
  *
  * @return mixed
  */
 public function actionSignup()
 {
     $model = new Membership();
     $user = new User();
     if ($model->load(Yii::$app->request->post())) {
         $postReq = Yii::$app->request->post();
         $user->username = $postReq['User']['username'];
         $user->email = $postReq['User']['email'];
         $user->new_password = $postReq['User']['new_password'];
         $user->setPassword();
         $user->save();
         $model->membership_login_id = $user->id;
         if ($model->save()) {
             if (Yii::$app->getUser()->login($user)) {
                 return $this->goHome();
             }
         }
     }
     return $this->render('signup', ['model' => $model, 'user' => $user]);
 }