/** * If user is just waiting, delete the wait * If user is in match already, this will end the current match, * and the opponent will win with official result 10:0 * @return multitype:string */ public function endMatch() { $team = Session::get('team'); if (empty($team)) { return array('error' => 'You are not logged in!'); } // check if user is in some match $match = MatchModel::getActiveMatchForTeam($team->id); if (!empty($match)) { $match = $match[0]; // run this as transaction DB::transaction(function () use($match, $team) { // finish this match as 10:0 (or 0:10) MatchModel::finishMatchOfficially($match->id, $team->id != $match->home_id); // update the teams goals counters, so our team concedes 10 goals MatchModel::updateTeamGoals($match->home_id, $match->away_id, $team->id == $match->away_id ? 10 : 0, $team->id == $match->home_id ? 10 : 0); }); } else { // user is not in match, delete him from the waiting TableModel::removeTeamFromWaiting($team->id); } return array('status' => 'ok'); }