/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("youth_enabled")) { return NULL; } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // check if it is own player $player = YouthPlayersDataService::getYouthPlayerById($this->_websoccer, $this->_db, $this->_i18n, $parameters["id"]); if ($clubId != $player["team_id"]) { throw new Exception($this->_i18n->getMessage("youthteam_err_notownplayer")); } // check if old enough if ($player["age"] < $this->_websoccer->getConfig("youth_min_age_professional")) { throw new Exception($this->_i18n->getMessage("youthteam_makeprofessional_err_tooyoung", $this->_websoccer->getConfig("youth_min_age_professional"))); } // validate main position (must be in compliance with general position) if ($player["position"] == "Torwart") { $validPositions = array("T"); } elseif ($player["position"] == "Abwehr") { $validPositions = array("LV", "IV", "RV"); } elseif ($player["position"] == "Mittelfeld") { $validPositions = array("LM", "RM", "DM", "OM", "ZM"); } else { $validPositions = array("LS", "RS", "MS"); } if (!in_array($parameters["mainposition"], $validPositions)) { throw new Exception($this->_i18n->getMessage("youthteam_makeprofessional_err_invalidmainposition")); } // check if team can afford salary $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if ($team["team_budget"] <= TeamsDataService::getTotalPlayersSalariesOfTeam($this->_websoccer, $this->_db, $clubId)) { throw new Exception($this->_i18n->getMessage("youthteam_makeprofessional_err_budgettooless")); } $this->createPlayer($player, $parameters["mainposition"]); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("youthteam_makeprofessional_success"), "")); return "myteam"; }