public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); // next match $matchinfo = YouthMatchesDataService::getYouthMatchinfoById($this->_websoccer, $this->_db, $this->_i18n, $parameters["matchid"]); // check if home or guest team (or else it is an invalid match) if ($matchinfo["home_team_id"] == $teamId) { $teamPrefix = "home"; } elseif ($matchinfo["guest_team_id"] == $teamId) { $teamPrefix = "guest"; } else { // ID has been entered manually, hence message not important throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } // check if expired if ($matchinfo["matchdate"] < $this->_websoccer->getNowAsTimestamp() || $matchinfo["simulated"]) { throw new Exception($this->_i18n->getMessage("youthformation_err_matchexpired")); } // get team players and check whether provided IDs are valid players (ceck for duplicate players only, for now) $this->validatePlayer($parameters["player1"]); $this->validatePlayer($parameters["player2"]); $this->validatePlayer($parameters["player3"]); $this->validatePlayer($parameters["player4"]); $this->validatePlayer($parameters["player5"]); $this->validatePlayer($parameters["player6"]); $this->validatePlayer($parameters["player7"]); $this->validatePlayer($parameters["player8"]); $this->validatePlayer($parameters["player9"]); $this->validatePlayer($parameters["player10"]); $this->validatePlayer($parameters["player11"]); $this->validatePlayer($parameters["bench1"]); $this->validatePlayer($parameters["bench2"]); $this->validatePlayer($parameters["bench3"]); $this->validatePlayer($parameters["bench4"]); $this->validatePlayer($parameters["bench5"]); // 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); $validSubstitutions[] = $subNo; } } // save formation $this->saveFormation($teamId, $parameters, $validSubstitutions, $matchinfo, $teamPrefix); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("saved_message_title"), "")); return null; }
public function getTemplateParameters() { $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); // next match $matchinfo = YouthMatchesDataService::getYouthMatchinfoById($this->_websoccer, $this->_db, $this->_i18n, $this->_websoccer->getRequestParameter("matchid")); // check if home or guest team (or else it is an invalid match) if ($matchinfo["home_team_id"] == $clubId) { $teamPrefix = "home"; } elseif ($matchinfo["guest_team_id"] == $clubId) { $teamPrefix = "guest"; } else { // ID has been entered manually, hence message not important throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } // check if expired if ($matchinfo["matchdate"] <= $this->_websoccer->getNowAsTimestamp() || $matchinfo["simulated"]) { throw new Exception($this->_i18n->getMessage("youthformation_err_matchexpired")); } // get team players $players = null; if ($clubId > 0) { $players = YouthPlayersDataService::getYouthPlayersOfTeamByPosition($this->_websoccer, $this->_db, $clubId, "DESC"); } // get previously saved formation and tactic $formation = $this->_getFormation($teamPrefix, $matchinfo); // override by request parameters 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] = ""; } } } $setup = $this->getFormationSetup($formation); 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("matchinfo" => $matchinfo, "players" => $players, "formation" => $formation, "setup" => $setup, "youthFormation" => TRUE); }