public function getOuts($tournament_id) { return HighOut::model()->findAllByAttributes(array('player_id' => $this->id, 'tournament_id' => $tournament_id)); }
public function actionmatchresults($id) { $model = $this->loadModel($id); $tournament_id = $model->challonge_id; if (isset($_POST['winner_id']) && isset($_POST['match_id'])) { $c = new ChallongeAPI(Yii::app()->params['challonge_api']); $match_id = $_POST['match_id']; $csv = $_POST['team_number'] == 1 ? "1-0" : "0-1"; $params = array("match[scores_csv]" => $csv, "match[winner_id]" => $_POST['winner_id']); $match = $c->updateMatch($tournament_id, $match_id, $params); if (count($c->errors)) { foreach ($c->errors as $error) { Yii::app()->user->setFlash('error', "Challonge ERROR: " . $error); } } else { $model->updateMatchesFromChallonge(); } $outs = $_POST['Data']['outs']; $high_darts = $_POST['Data']['high_dart']; // echo "<pre>"; // print_r($_POST); // print_r($outs); // echo "</pre>"; foreach ($outs as $game) { foreach ($game as $player_id => $out) { if ($out > 0) { $highout = new HighOut(); $highout->tournament_id = $id; $highout->player_id = $player_id; $highout->high_out = $out; $highout->save(); } } } foreach ($high_darts as $player_id => $high_dart) { if ($high_dart > 0) { $highdart = new HighDart(); $highdart->tournament_id = $id; $highdart->player_id = $player_id; $highdart->high_dart = $high_dart; $highdart->save(); } } } $this->redirect(array('matches', 'id' => $model->id)); }