/** * Finds games with empty points but with not empty score * @return int */ public function actionGetNull() { $tournaments = Tournaments::getAutoprocessTournaments(); $games = []; foreach ($tournaments as $one) { $teamTournament = TeamTournaments::find()->where(['id_tournament' => $one->id_tournament])->all(); //getting Participant IDs for the tournament $teamIDs = ArrayHelper::getColumn($teamTournament, 'id'); $games = ArrayHelper::merge($games, Games::find()->where(['or', ['in', 'id_team_home', $teamIDs], ['in', 'id_team_guest', $teamIDs]])->andWhere(['and', ['or', ['not', ['score_home' => null]], ['not', ['score_guest' => null]]], ['or', ['points_home' => null], ['points_guest' => null]]])->all()); } if (!empty($games)) { $this->getErrorMessage($games); } else { Yii::info('No games with score but with no points', 'console'); } return 0; }
/** * @param $attribute * @param $params */ public function ifGameExists($attribute, $params) { if (Games::find()->where(['id_team_home' => $this->id_team_home])->andWhere(['id_team_guest' => $this->id_team_guest])->andWhere(['tour' => $this->tour])->one() || Games::find()->where(['id_team_home' => $this->id_team_home])->andWhere(['id_team_guest' => $this->id_team_guest])->andWhere(['date_time_game' => $this->date_time_game])->one()) { $this->addError('id_team_home', "Игра {$this->competitors} в этом туре уже существует"); } }
protected function addNewGames() { foreach ($this->gamesFromWeb as $gameWeb) { $newGame = new Games(); foreach ($gameWeb as $k => $attribute) { $newGame->{$k} = $attribute; } if (!Games::find()->where(['tour' => $newGame->tour])->andWhere(['id_team_home' => $newGame->id_team_home])->andWhere(['id_team_guest' => $newGame->id_team_guest])->exists()) { $newGame->save(false); } } }