public function teams_selected() { $teams = Team::model()->findAllByAttributes(array('tournament_id' => $this->id)); $players = PlayerTournament::model()->findAllByAttributes(array('tournament_id' => $this->id)); return count($teams) == count($players) && count($teams) > 0; }
public function actionRedrawTeams() { if (Yii::app()->request->isPostRequest) { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } $message = 'fail'; if (isset($_GET['data'])) { $tournament_id = $_GET['data']['tournament_id']; $tournament = Tournament::model()->findByPk($tournament_id); $teams = $tournament->teams; $ids = array(); foreach ($teams as $player) { $ids[] = $player->challonge_participant_id; } if (count($ids)) { $c = new ChallongeAPI(Yii::app()->params['challonge_api']); foreach (array_unique($ids) as $challonge_id) { if ($challonge_id) { $c->deleteParticipant($tournament->challonge_id, $challonge_id); } } } $deleted = Team::model()->deleteAllByAttributes(array('tournament_id' => $tournament_id)); $updated = PlayerTournament::model()->updateAll(array('chip_pulled' => null), 'tournament_id = ' . $tournament_id); if ($deleted > 0 && $updated > 0) { $message = 'success'; } } echo CJSON::encode(array('status' => $message)); }