/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $matchId = (int) $this->_websoccer->getRequestParameter('id'); if ($matchId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $match = MatchesDataService::getMatchById($this->_websoccer, $this->_db, $matchId); if (!isset($match['match_id'])) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $allowTacticChanges = FALSE; $reportmessages = array(); if ($match['match_minutes'] > 0) { $reportmessages = MatchesDataService::getMatchReportMessages($this->_websoccer, $this->_db, $this->_i18n, $matchId); $userTeamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); $userNationalTeamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); if (!$match['match_simulated'] && $this->_websoccer->getConfig('sim_allow_livechanges') && ($match['match_home_id'] == $userTeamId || $match['match_guest_id'] == $userTeamId || $match['match_home_id'] == $userNationalTeamId || $match['match_guest_id'] == $userNationalTeamId)) { $allowTacticChanges = TRUE; } } // collect strikers $homeStrikerMessages = array(); $guestStrikerMessages = array(); foreach ($reportmessages as $reportMessage) { $type = $reportMessage['type']; if ($type == 'Tor' || $type == 'Tor_mit_vorlage' || $type == 'Elfmeter_erfolg' || $type == 'Freistoss_treffer') { if ($reportMessage['active_home']) { array_unshift($homeStrikerMessages, $reportMessage); } else { array_unshift($guestStrikerMessages, $reportMessage); } } } return array('match' => $match, 'reportmessages' => $reportmessages, 'allowTacticChanges' => $allowTacticChanges, 'homeStrikerMessages' => $homeStrikerMessages, 'guestStrikerMessages' => $guestStrikerMessages); }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); if ($this->_isNationalTeam) { $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); } else { $teamId = $user->getClubId($this->_websoccer, $this->_db); } // check and get next match // next x matches $nextMatches = MatchesDataService::getNextMatches($this->_websoccer, $this->_db, $teamId, $this->_websoccer->getConfig('formation_max_next_matches')); if (!count($nextMatches)) { throw new Exception($this->_i18n->getMessage('formation_err_nonextmatch')); } // currently selected match $matchId = $parameters['id']; foreach ($nextMatches as $nextMatch) { if ($nextMatch['match_id'] == $matchId) { $matchinfo = $nextMatch; break; } } if (!isset($matchinfo)) { throw new Exception('illegal match id'); } // get team players and check whether provided IDs are valid players (in team and not blocked) $players = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $teamId, $this->_isNationalTeam, $matchinfo['match_type'] == 'cup', $matchinfo['match_type'] != 'friendly'); $this->validatePlayer($parameters['player1'], $players); $this->validatePlayer($parameters['player2'], $players); $this->validatePlayer($parameters['player3'], $players); $this->validatePlayer($parameters['player4'], $players); $this->validatePlayer($parameters['player5'], $players); $this->validatePlayer($parameters['player6'], $players); $this->validatePlayer($parameters['player7'], $players); $this->validatePlayer($parameters['player8'], $players); $this->validatePlayer($parameters['player9'], $players); $this->validatePlayer($parameters['player10'], $players); $this->validatePlayer($parameters['player11'], $players); $this->validatePlayer($parameters['bench1'], $players, TRUE); $this->validatePlayer($parameters['bench2'], $players, TRUE); $this->validatePlayer($parameters['bench3'], $players, TRUE); $this->validatePlayer($parameters['bench4'], $players, TRUE); $this->validatePlayer($parameters['bench5'], $players, TRUE); // validate substitutions $validSubstitutions = array(); for ($subNo = 1; $subNo <= 3; $subNo++) { $playerIn = $parameters['sub' . $subNo . '_in']; $playerOut = $parameters['sub' . $subNo . '_out']; $playerMinute = $parameters['sub' . $subNo . '_minute']; if ($playerIn != null && $playerIn > 0 && $playerOut != null && $playerOut > 0 && $playerMinute != null && $playerMinute > 0) { $this->validateSubstitution($playerIn, $playerOut, $playerMinute, $players); $validSubstitutions[] = $subNo; } } // save formation $this->saveFormation($teamId, $matchinfo['match_id'], $parameters, $validSubstitutions); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage('saved_message_title'), '')); return null; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("nationalteams_enabled")) { return NULL; } // get team info $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("nationalteams_user_requires_team")); } $result = $this->_db->querySelect("name", $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $teamId); $team = $result->fetch_array(); $result->free(); // get player info $fromTable = $this->_websoccer->getConfig("db_prefix") . "_spieler"; $result = $this->_db->querySelect("nation", $fromTable, "id = %d", $parameters["id"]); $player = $result->fetch_array(); $result->free(); if (!$player) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } // check if from same nation. If not, user most probably tries to cheat, hence i18n not important. if ($player["nation"] != $team["name"]) { throw new Exception("Player is from different nation."); } // remove from team team $this->_db->queryDelete($this->_websoccer->getConfig("db_prefix") . "_nationalplayer", "player_id = %d AND team_id = %d", array($parameters["id"], $teamId)); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("nationalteams_removeplayer_success"), "")); return "nationalteam"; }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { // get team info $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("nationalteams_user_requires_team")); } $result = $this->_db->querySelect("name", $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $teamId); $team = $result->fetch_array(); $result->free(); // query players $firstName = $this->_websoccer->getRequestParameter("fname"); $lastName = $this->_websoccer->getRequestParameter("lname"); $position = $this->_websoccer->getRequestParameter("position"); $mainPosition = $this->_websoccer->getRequestParameter("position_main"); $playersCount = NationalteamsDataService::findPlayersCount($this->_websoccer, $this->_db, $team["name"], $teamId, $firstName, $lastName, $position, $mainPosition); // setup paginator $eps = $this->_websoccer->getConfig("entries_per_page"); $paginator = new Paginator($playersCount, $eps, $this->_websoccer); $paginator->addParameter("fname", $firstName); $paginator->addParameter("lname", $lastName); $paginator->addParameter("position", $position); $paginator->addParameter("position_main", $mainPosition); $paginator->addParameter("search", "true"); // get players records if ($playersCount > 0) { $players = NationalteamsDataService::findPlayers($this->_websoccer, $this->_db, $team["name"], $teamId, $firstName, $lastName, $position, $mainPosition, $paginator->getFirstIndex(), $eps); } else { $players = array(); } return array("team_name" => $team["name"], "playersCount" => $playersCount, "players" => $players, "paginator" => $paginator); }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { // get team info $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("nationalteams_user_requires_team")); } return array(); }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { // get team info $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("nationalteams_user_requires_team")); } $result = $this->_db->querySelect("name", $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $teamId); $team = $result->fetch_array(); $result->free(); return array("team_name" => $team["name"], "players" => NationalteamsDataService::getNationalPlayersOfTeamByPosition($this->_websoccer, $this->_db, $teamId)); }
public function getTemplateParameters() { if ($this->_websoccer->getRequestParameter("nationalteam")) { $clubId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); } else { $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); } $matchinfo = MatchesDataService::getNextMatch($this->_websoccer, $this->_db, $clubId); // get previous matches against this team if (count($matchinfo)) { $matchinfo["previous_matches"] = MatchesDataService::getPreviousMatches($matchinfo, $this->_websoccer, $this->_db); } return $matchinfo; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("nationalteams_enabled")) { return NULL; } // get team info $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("nationalteams_user_requires_team")); } $result = $this->_db->querySelect("name", $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $teamId); $team = $result->fetch_array(); $result->free(); // get player info $fromTable = $this->_websoccer->getConfig("db_prefix") . "_spieler"; $result = $this->_db->querySelect("nation", $fromTable, "id = %d", $parameters["id"]); $player = $result->fetch_array(); $result->free(); if (!$player) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } // check if from same nation. If not, user most probably tries to cheat, hence i18n not important. if ($player["nation"] != $team["name"]) { throw new Exception("Player is from different nation."); } // check if already in team $fromTable = $this->_websoccer->getConfig("db_prefix") . "_nationalplayer"; $result = $this->_db->querySelect("COUNT(*) AS hits", $fromTable, "player_id = %d", $parameters["id"]); $players = $result->fetch_array(); $result->free(); if ($players && $players["hits"]) { throw new Exception($this->_i18n->getMessage("nationalteams_addplayer_err_alreadyinteam")); } // check maximum number of players $result = $this->_db->querySelect("COUNT(*) AS hits", $fromTable, "team_id = %d", $teamId); $existingplayers = $result->fetch_array(); $result->free(); if ($existingplayers["hits"] >= 30) { throw new Exception($this->_i18n->getMessage("nationalteams_addplayer_err_toomanyplayer", 30)); } // add to team $this->_db->queryInsert(array("team_id" => $teamId, "player_id" => $parameters["id"]), $fromTable); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("nationalteams_addplayer_success"), "")); return "nationalteam"; }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { // get team info $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("nationalteams_user_requires_team")); } $matchesCount = NationalteamsDataService::countNextMatches($this->_websoccer, $this->_db, $teamId); // setup paginator $eps = 5; $paginator = new Paginator($matchesCount, $eps, $this->_websoccer); $paginator->addParameter("block", "national-next-matches"); $matches = array(); if ($matchesCount) { $matches = NationalteamsDataService::getNextMatches($this->_websoccer, $this->_db, $teamId, $paginator->getFirstIndex(), $eps); } return array("paginator" => $paginator, "matches" => $matches); }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { // get team players if ($this->_nationalteam) { $clubId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); } else { $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); } // next x matches $nextMatches = MatchesDataService::getNextMatches($this->_websoccer, $this->_db, $clubId, $this->_websoccer->getConfig('formation_max_next_matches')); if (!count($nextMatches)) { throw new Exception($this->_i18n->getMessage('next_match_block_no_nextmatch')); } // currently selected match $matchId = $this->_websoccer->getRequestParameter('id'); if (!$matchId) { $matchinfo = $nextMatches[0]; } else { foreach ($nextMatches as $nextMatch) { if ($nextMatch['match_id'] == $matchId) { $matchinfo = $nextMatch; break; } } } if (!isset($matchinfo)) { throw new Exception('illegal match id'); } $players = null; if ($clubId > 0) { if ($this->_nationalteam) { $players = NationalteamsDataService::getNationalPlayersOfTeamByPosition($this->_websoccer, $this->_db, $clubId); } else { $players = PlayersDataService::getPlayersOfTeamByPosition($this->_websoccer, $this->_db, $clubId, 'DESC', count($matchinfo) && $matchinfo['match_type'] == 'cup', isset($matchinfo['match_type']) && $matchinfo['match_type'] != 'friendly'); } } // load template if ($this->_websoccer->getRequestParameter('templateid')) { $formation = FormationDataService::getFormationByTemplateId($this->_websoccer, $this->_db, $clubId, $this->_websoccer->getRequestParameter('templateid')); } else { // get previously saved formation and tactic $formation = FormationDataService::getFormationByTeamId($this->_websoccer, $this->_db, $clubId, $matchinfo['match_id']); } for ($benchNo = 1; $benchNo <= 5; $benchNo++) { if ($this->_websoccer->getRequestParameter('bench' . $benchNo)) { $formation['bench' . $benchNo] = $this->_websoccer->getRequestParameter('bench' . $benchNo); } else { if (!isset($formation['bench' . $benchNo])) { $formation['bench' . $benchNo] = ''; } } } for ($subNo = 1; $subNo <= 3; $subNo++) { if ($this->_websoccer->getRequestParameter('sub' . $subNo . '_out')) { $formation['sub' . $subNo . '_out'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_out'); $formation['sub' . $subNo . '_in'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_in'); $formation['sub' . $subNo . '_minute'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_minute'); $formation['sub' . $subNo . '_condition'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_condition'); $formation['sub' . $subNo . '_position'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_position'); } else { if (!isset($formation['sub' . $subNo . '_out'])) { $formation['sub' . $subNo . '_out'] = ''; $formation['sub' . $subNo . '_in'] = ''; $formation['sub' . $subNo . '_minute'] = ''; $formation['sub' . $subNo . '_condition'] = ''; $formation['sub' . $subNo . '_position'] = ''; } } } $setup = $this->getFormationSetup($formation); // select players from team by criteria $criteria = $this->_websoccer->getRequestParameter('preselect'); if ($criteria !== NULL) { if ($criteria == 'strongest') { $sortColumn = 'w_staerke'; } elseif ($criteria == 'freshest') { $sortColumn = 'w_frische'; } else { $sortColumn = 'w_zufriedenheit'; } $proposedPlayers = FormationDataService::getFormationProposalForTeamId($this->_websoccer, $this->_db, $clubId, $setup['defense'], $setup['dm'], $setup['midfield'], $setup['om'], $setup['striker'], $setup['outsideforward'], $sortColumn, 'DESC', $this->_nationalteam, isset($matchinfo['match_type']) && $matchinfo['match_type'] == 'cup'); for ($playerNo = 1; $playerNo <= 11; $playerNo++) { $playerIndex = $playerNo - 1; if (isset($proposedPlayers[$playerIndex])) { $formation['player' . $playerNo] = $proposedPlayers[$playerIndex]['id']; $formation['player' . $playerNo . '_pos'] = $proposedPlayers[$playerIndex]['position']; } } // clear bench (prevents duplicate players) for ($benchNo = 1; $benchNo <= 5; $benchNo++) { $formation['bench' . $benchNo] = ''; } for ($subNo = 1; $subNo <= 3; $subNo++) { $formation['sub' . $subNo . '_out'] = ''; $formation['sub' . $subNo . '_in'] = ''; $formation['sub' . $subNo . '_minute'] = ''; $formation['sub' . $subNo . '_condition'] = ''; $formation['sub' . $subNo . '_position'] = ''; } } // free kick taker if ($this->_websoccer->getRequestParameter('freekickplayer')) { $formation['freekickplayer'] = $this->_websoccer->getRequestParameter('freekickplayer'); } else { if (!isset($formation['freekickplayer'])) { $formation['freekickplayer'] = ''; } } // tactical options if ($this->_websoccer->getRequestParameter('offensive')) { $formation['offensive'] = $this->_websoccer->getRequestParameter('offensive'); } else { if (!isset($formation['offensive'])) { $formation['offensive'] = 40; } } if ($this->_websoccer->getRequestParameter('longpasses')) { $formation['longpasses'] = $this->_websoccer->getRequestParameter('longpasses'); } if ($this->_websoccer->getRequestParameter('counterattacks')) { $formation['counterattacks'] = $this->_websoccer->getRequestParameter('counterattacks'); } for ($playerNo = 1; $playerNo <= 11; $playerNo++) { // set player from request if ($this->_websoccer->getRequestParameter('player' . $playerNo)) { $formation['player' . $playerNo] = $this->_websoccer->getRequestParameter('player' . $playerNo); $formation['player' . $playerNo . '_pos'] = $this->_websoccer->getRequestParameter('player' . $playerNo . '_pos'); // set to 0 if no previous formation is available } else { if (!isset($formation['player' . $playerNo])) { $formation['player' . $playerNo] = ''; $formation['player' . $playerNo . '_pos'] = ''; } } } return array('nextMatches' => $nextMatches, 'next_match' => $matchinfo, 'previous_matches' => MatchesDataService::getPreviousMatches($matchinfo, $this->_websoccer, $this->_db), 'players' => $players, 'formation' => $formation, 'setup' => $setup, 'captain_id' => TeamsDataService::getTeamCaptainIdOfTeam($this->_websoccer, $this->_db, $clubId)); }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $matches = NationalteamsDataService::getNextMatches($this->_websoccer, $this->_db, $this->_teamId, 0, 1); return array('match' => $matches[0]); }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $matchId = (int) $this->_websoccer->getRequestParameter('id'); if ($matchId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $match = MatchesDataService::getMatchSubstitutionsById($this->_websoccer, $this->_db, $matchId); if ($match['match_simulated']) { throw new Exception($this->_i18n->getMessage('match_details_match_completed')); } $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); if ($match['match_home_id'] !== $teamId && $match['match_guest_id'] !== $teamId) { $teamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); } if ($teamId !== $match['match_home_id'] && $match['match_guest_id'] !== $teamId) { throw new Exception('illegal match'); } $teamPrefix = $teamId == $match['match_home_id'] ? 'home' : 'guest'; $players = MatchesDataService::getMatchPlayerRecordsByField($this->_websoccer, $this->_db, $matchId, $teamId); $playersOnField = $players['field']; $playersOnBench = isset($players['bench']) ? $players['bench'] : array(); $formation = array(); if ($this->_websoccer->getRequestParameter('freekickplayer')) { $formation['freekickplayer'] = $this->_websoccer->getRequestParameter('freekickplayer'); } else { $formation['freekickplayer'] = $match['match_' . $teamPrefix . '_freekickplayer']; } if ($this->_websoccer->getRequestParameter('offensive')) { $formation['offensive'] = $this->_websoccer->getRequestParameter('offensive'); } else { $formation['offensive'] = $match['match_' . $teamPrefix . '_offensive']; } if ($this->_websoccer->getRequestParameter('longpasses')) { $formation['longpasses'] = $this->_websoccer->getRequestParameter('longpasses'); } else { $formation['longpasses'] = $match['match_' . $teamPrefix . '_longpasses']; } if ($this->_websoccer->getRequestParameter('counterattacks')) { $formation['counterattacks'] = $this->_websoccer->getRequestParameter('counterattacks'); } else { $formation['counterattacks'] = $match['match_' . $teamPrefix . '_counterattacks']; } // get existing formation $playerNo = 0; foreach ($playersOnField as $player) { $playerNo++; $formation['player' . $playerNo] = $player['id']; $formation['player' . $playerNo . '_pos'] = $player['match_position_main']; } // set setup $setup = array('defense' => 6, 'dm' => 3, 'midfield' => 4, 'om' => 3, 'striker' => 2, 'outsideforward' => 2); $setupMainMapping = array('LV' => 'defense', 'RV' => 'defense', 'IV' => 'defense', 'DM' => 'dm', 'LM' => 'midfield', 'ZM' => 'midfield', 'RM' => 'midfield', 'OM' => 'om', 'LS' => 'outsideforward', 'MS' => 'striker', 'RS' => 'outsideforward'); $setupPosMapping = array('Abwehr' => 'defense', 'Mittelfeld' => 'midfield', 'Sturm' => 'striker'); // override formation by user input and count setup for ($playerNo = 1; $playerNo <= 11; $playerNo++) { if ($this->_websoccer->getRequestParameter('player' . $playerNo) > 0) { $formation['player' . $playerNo] = $this->_websoccer->getRequestParameter('player' . $playerNo); $formation['player' . $playerNo . '_pos'] = $this->_websoccer->getRequestParameter('player' . $playerNo . '_pos'); } } // bench $benchNo = 0; foreach ($playersOnBench as $player) { $benchNo++; $formation['bench' . $benchNo] = $player['id']; } for ($benchNo = 1; $benchNo <= 5; $benchNo++) { if ($this->_websoccer->getRequestParameter('bench' . $benchNo)) { $formation['bench' . $benchNo] = $this->_websoccer->getRequestParameter('bench' . $benchNo); } else { if (!isset($formation['bench' . $benchNo])) { $formation['bench' . $benchNo] = ''; } } } // subs for ($subNo = 1; $subNo <= 3; $subNo++) { if ($this->_websoccer->getRequestParameter('sub' . $subNo . '_out')) { $formation['sub' . $subNo . '_out'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_out'); $formation['sub' . $subNo . '_in'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_in'); $formation['sub' . $subNo . '_minute'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_minute'); $formation['sub' . $subNo . '_condition'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_condition'); $formation['sub' . $subNo . '_position'] = $this->_websoccer->getRequestParameter('sub' . $subNo . '_position'); } else { if (isset($match[$teamPrefix . '_sub' . $subNo . '_out'])) { $formation['sub' . $subNo . '_out'] = $match[$teamPrefix . '_sub' . $subNo . '_out']; $formation['sub' . $subNo . '_in'] = $match[$teamPrefix . '_sub' . $subNo . '_in']; $formation['sub' . $subNo . '_minute'] = $match[$teamPrefix . '_sub' . $subNo . '_minute']; $formation['sub' . $subNo . '_condition'] = $match[$teamPrefix . '_sub' . $subNo . '_condition']; $formation['sub' . $subNo . '_position'] = $match[$teamPrefix . '_sub' . $subNo . '_position']; } else { $formation['sub' . $subNo . '_out'] = ''; $formation['sub' . $subNo . '_in'] = ''; $formation['sub' . $subNo . '_minute'] = ''; $formation['sub' . $subNo . '_condition'] = ''; $formation['sub' . $subNo . '_position'] = ''; } } } return array('setup' => $setup, 'players' => $players, 'formation' => $formation, 'minute' => $match['match_minutes']); }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); $nationalTeamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db); $matchId = $parameters['id']; // check and get match data $matchinfo = MatchesDataService::getMatchSubstitutionsById($this->_websoccer, $this->_db, $matchId); if (!isset($matchinfo['match_id'])) { throw new Exception($this->_i18n->getMessage('formation_err_nonextmatch')); } // check whether user is one of the team managers if ($matchinfo['match_home_id'] != $teamId && $matchinfo['match_guest_id'] != $teamId && $matchinfo['match_home_id'] != $nationalTeamId && $matchinfo['match_guest_id'] != $nationalTeamId) { throw new Exception('nice try'); } // is already completed? if ($matchinfo['match_simulated']) { throw new Exception($this->_i18n->getMessage('match_details_match_completed')); } // update match fields $columns = array(); $teamPrefix = $matchinfo['match_home_id'] == $teamId || $matchinfo['match_home_id'] == $nationalTeamId ? 'home' : 'guest'; $teamPrefixDb = $matchinfo['match_home_id'] == $teamId || $matchinfo['match_home_id'] == $nationalTeamId ? 'home' : 'gast'; // consider already executed subs $occupiedSubPos = array(); $existingFutureSubs = array(); for ($subNo = 1; $subNo <= 3; $subNo++) { $existingMinute = (int) $matchinfo[$teamPrefix . '_sub' . $subNo . '_minute']; if ($existingMinute > 0 && $existingMinute <= $matchinfo['match_minutes']) { $occupiedSubPos[$subNo] = TRUE; } elseif ($existingMinute > 0) { $existingFutureSubs[$matchinfo[$teamPrefix . '_sub' . $subNo . '_out']] = array('minute' => $matchinfo[$teamPrefix . '_sub' . $subNo . '_minute'], 'in' => $matchinfo[$teamPrefix . '_sub' . $subNo . '_in'], 'condition' => $matchinfo[$teamPrefix . '_sub' . $subNo . '_condition'], 'position' => $matchinfo[$teamPrefix . '_sub' . $subNo . '_position'], 'slot' => $subNo); } } // save subs if (count($occupiedSubPos) < 3) { // a substitution must be announced at least number of minutes of interval, otherwise no chance of execution $nextPossibleMinute = $matchinfo['match_minutes'] + $this->_websoccer->getConfig('sim_interval') + 1; for ($subNo = 1; $subNo <= 3; $subNo++) { $newOut = (int) $parameters['sub' . $subNo . '_out']; $newIn = (int) $parameters['sub' . $subNo . '_in']; $newMinute = (int) $parameters['sub' . $subNo . '_minute']; $newCondition = $parameters['sub' . $subNo . '_condition']; $newPosition = $parameters['sub' . $subNo . '_position']; $slot = FALSE; $saveSub = TRUE; // replace existing sub if (isset($existingFutureSubs[$newOut]) && $newIn == $existingFutureSubs[$newOut]['in'] && $newCondition == $existingFutureSubs[$newOut]['condition'] && $newMinute == $existingFutureSubs[$newOut]['minute'] && $newPosition == $existingFutureSubs[$newOut]['position']) { $saveSub = FALSE; } // get first free slot for ($slotNo = 1; $slotNo <= 3; $slotNo++) { if (!isset($occupiedSubPos[$slotNo])) { $slot = $slotNo; break; } } if ($slot && $newOut && $newIn && $newMinute) { if ($saveSub && $newMinute < $nextPossibleMinute) { $newMinute = $nextPossibleMinute; $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, '', $this->_i18n->getMessage('match_details_changes_too_late_altered', $subNo))); } $columns[$teamPrefixDb . '_w' . $slot . '_raus'] = $newOut; $columns[$teamPrefixDb . '_w' . $slot . '_rein'] = $newIn; $columns[$teamPrefixDb . '_w' . $slot . '_minute'] = $newMinute; $columns[$teamPrefixDb . '_w' . $slot . '_condition'] = $newCondition; $columns[$teamPrefixDb . '_w' . $slot . '_position'] = $newPosition; $occupiedSubPos[$slot] = TRUE; } } } // update tactics $prevOffensive = $matchinfo['match_' . $teamPrefix . '_offensive']; $prevLongpasses = $matchinfo['match_' . $teamPrefix . '_longpasses']; $prevCounterattacks = $matchinfo['match_' . $teamPrefix . '_counterattacks']; if (!$prevLongpasses) { $prevLongpasses = '0'; } if (!$prevCounterattacks) { $prevCounterattacks = '0'; } if ($prevOffensive !== $parameters['offensive'] || $prevLongpasses !== $parameters['longpasses'] || $prevCounterattacks !== $parameters['counterattacks']) { $alreadyChanged = $matchinfo['match_' . $teamPrefix . '_offensive_changed']; if ($alreadyChanged >= $this->_websoccer->getConfig('sim_allow_offensivechanges')) { throw new Exception($this->_i18n->getMessage('match_details_changes_too_often', $this->_websoccer->getConfig('sim_allow_offensivechanges'))); } $columns[$teamPrefixDb . '_offensive'] = $parameters['offensive']; $columns[$teamPrefixDb . '_longpasses'] = $parameters['longpasses']; $columns[$teamPrefixDb . '_counterattacks'] = $parameters['counterattacks']; $columns[$teamPrefixDb . '_offensive_changed'] = $alreadyChanged + 1; $this->_createMatchReportMessage($user, $matchId, $matchinfo['match_minutes'], $teamPrefix == 'home'); } // free kick taker $prevFreekickPlayer = $matchinfo['match_' . $teamPrefix . '_freekickplayer']; if ($parameters['freekickplayer'] && $parameters['freekickplayer'] != $prevFreekickPlayer) { $columns[$teamPrefixDb . '_freekickplayer'] = $parameters['freekickplayer']; } // execute update if (count($columns)) { $fromTable = $this->_websoccer->getConfig('db_prefix') . '_spiel'; $whereCondition = 'id = %d'; $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $matchId); } $this->_updatePlayerPosition($parameters, $matchId, $teamId); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage('saved_message_title'), '')); return "match"; }