public function actionPlayers($id) { $trainingMatch = TrainingMatch::findOne($id); $request = Yii::$app->request; if ($request->isPost) { $post = $request->post(); // Сброс старых игроков foreach ($trainingMatch->greenPlayers as $player) { $trainingMatch->unlink('greenPlayers', $player); } foreach ($trainingMatch->purplePlayers as $player) { $trainingMatch->unlink('purplePlayers', $player); } // Добавление новых if (isset($post['green_players_ids'])) { $greenPlayers = Player::find()->where(['id' => $post['green_players_ids']])->all(); foreach ($greenPlayers as $player) { $trainingMatch->link('greenPlayers', $player); } } if (isset($post['purple_players_ids'])) { $purplePlayers = Player::find()->where(['id' => $post['purple_players_ids']])->all(); foreach ($purplePlayers as $player) { $trainingMatch->link('purplePlayers', $player); } } // Сохранение в БД $trainingMatch->save(); } return [$trainingMatch->greenPlayers, $trainingMatch->purplePlayers]; }
/** * Displays homepage. * * @return mixed */ public function actionIndex() { $matches = Match::find()->with('team', 'competition')->orderBy(['date_time' => SORT_DESC])->asArray()->all(); $trainingMatches = TrainingMatch::find()->with('greenPlayers', 'purplePlayers')->orderBy(['date_time' => SORT_DESC])->asArray()->all(); $trainingMatchStandings = TrainingMatchStandings::find()->one()->sorted(); $playersStatisticSummary = PlayerStatisticSummary::find()->with(['player' => function ($query) { $query->with('playerLastResultsAggregated'); }])->orderBy(['count_points' => SORT_DESC, 'count_games' => SORT_ASC])->limit(5)->asArray()->all(); $playersRatingLebedev = PlayerRatingLebedevSummary::find()->with(['player' => function ($query) { $query->with('playerLastResultsAggregated'); }])->orderBy(['rating_lebedev_avg' => SORT_DESC])->limit(5)->asArray()->all(); return $this->render('index', ['matches' => $matches, 'trainingMatches' => $trainingMatches, 'trainingMatchStandings' => $trainingMatchStandings, 'playersStatisticSummary' => $playersStatisticSummary, 'playersRatingLebedev' => $playersRatingLebedev]); }
public function getTrainingMatch() { return $this->hasOne(TrainingMatch::className(), ['training_match_id' => 'id']); }
public function actionRefuse($id) { $trainingMatch = TrainingMatch::find()->where(['id' => $id])->one(); if (!Yii::$app->user->isGuest) { $userId = Yii::$app->user->identity->id; $request = Yii::$app->request; if ($request->isPost) { $post = $request->post(); $player = Player::find()->where(['id' => $userId])->one(); $trainingMatch->unlink('purplePlayers', $player); $trainingMatch->unlink('greenPlayers', $player); $trainingMatch->link('refusedPlayers', $player); $trainingMatch->save(); } } return $this->goBack(); }