public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("youth_enabled") || !$this->_websoccer->getConfig("youth_matchrequests_enabled")) { return NULL; } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // check if user has a club if ($clubId < 1) { throw new Exception($this->_i18n->getMessage("error_action_required_team")); } // check if date is valid (might be manipulated) $tooLateBoundary = $this->_websoccer->getNowAsTimestamp() + 3600 * 24 * (1 + $this->_websoccer->getConfig("youth_matchrequest_max_futuredays")); $validTimes = explode(",", $this->_websoccer->getConfig("youth_matchrequest_allowedtimes")); // check valid times (remove white spaces) $timeIsValid = FALSE; $matchTime = date("H:i", $parameters["matchdate"]); foreach ($validTimes as $validTime) { if ($matchTime == trim($validTime)) { $timeIsValid = TRUE; break; } } if (!$timeIsValid || $parameters["matchdate"] > $tooLateBoundary) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_create_err_invaliddate")); } // check maximum number of open requests $fromTable = $this->_websoccer->getConfig("db_prefix") . "_youthmatch_request"; $result = $this->_db->querySelect("COUNT(*) AS hits", $fromTable, "team_id = %d", $clubId); $requests = $result->fetch_array(); $result->free(); $maxNoOfRequests = (int) $this->_websoccer->getConfig("youth_matchrequest_max_open_requests"); if ($requests && $requests["hits"] >= $maxNoOfRequests) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_create_err_too_many_open_requests", $maxNoOfRequests)); } // check if reward can be paid if ($parameters["reward"]) { $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if ($team["team_budget"] <= $parameters["reward"]) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_create_err_budgetnotenough")); } } // check if enough youth players if (YouthPlayersDataService::countYouthPlayersOfTeam($this->_websoccer, $this->_db, $clubId) < 11) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_create_err_notenoughplayers")); } // check maximum number of matches per day constraint $maxMatchesPerDay = $this->_websoccer->getConfig("youth_match_maxperday"); if (YouthMatchesDataService::countMatchesOfTeamOnSameDay($this->_websoccer, $this->_db, $clubId, $parameters["matchdate"]) >= $maxMatchesPerDay) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_err_maxperday_violated", $maxMatchesPerDay)); } // create request $columns = array("team_id" => $clubId, "matchdate" => $parameters["matchdate"], "reward" => $parameters["reward"]); $this->_db->queryInsert($columns, $fromTable); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("youthteam_matchrequest_create_success"), "")); return "youth-matchrequests"; }
public function getTemplateParameters() { YouthPlayersDataService::deleteInvalidOpenMatchRequests($this->_websoccer, $this->_db); $count = YouthPlayersDataService::countMatchRequests($this->_websoccer, $this->_db); $eps = $this->_websoccer->getConfig("entries_per_page"); $paginator = new Paginator($count, $eps, $this->_websoccer); $requests = YouthPlayersDataService::getMatchRequests($this->_websoccer, $this->_db, $paginator->getFirstIndex(), $eps); return array("requests" => $requests, "paginator" => $paginator); }
public function getTemplateParameters() { $teamId = $this->_websoccer->getRequestParameter("teamid"); $players = array(); if ($teamId > 0) { $players = YouthPlayersDataService::getYouthPlayersOfTeam($this->_websoccer, $this->_db, $teamId); } return array("players" => $players); }
public function getTemplateParameters() { $playerId = (int) $this->_websoccer->getRequestParameter("id"); if ($playerId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $player = YouthPlayersDataService::getYouthPlayerById($this->_websoccer, $this->_db, $this->_i18n, $playerId); return array("player" => $player); }
public function getTemplateParameters() { $positionFilter = $this->_websoccer->getRequestParameter("position"); $count = YouthPlayersDataService::countTransferableYouthPlayers($this->_websoccer, $this->_db, $positionFilter); $eps = $this->_websoccer->getConfig("entries_per_page"); $paginator = new Paginator($count, $eps, $this->_websoccer); if ($positionFilter != null) { $paginator->addParameter("position", $positionFilter); } $players = YouthPlayersDataService::getTransferableYouthPlayers($this->_websoccer, $this->_db, $positionFilter, $paginator->getFirstIndex(), $eps); return array("players" => $players, "paginator" => $paginator); }
public function getTemplateParameters() { $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); $players = array(); if ($teamId > 0) { $players = YouthPlayersDataService::getYouthPlayersOfTeam($this->_websoccer, $this->_db, $teamId); $noOfPlayers = count($players); for ($playerIndex = 0; $playerIndex < $noOfPlayers; $playerIndex++) { $players[$playerIndex]["nation_flagfile"] = PlayersDataService::getFlagFilename($players[$playerIndex]["nation"]); } } return array("players" => $players); }
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); }
public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("youth_enabled") && $this->_websoccer->getConfig("youth_scouting_enabled")) { return NULL; } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // check if user has a club if ($clubId < 1) { throw new Exception($this->_i18n->getMessage("error_action_required_team")); } // check if break is violated $lastExecutionTimestamp = YouthPlayersDataService::getLastScoutingExecutionTime($this->_websoccer, $this->_db, $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db)); $nextPossibleExecutionTimestamp = $lastExecutionTimestamp + $this->_websoccer->getConfig("youth_scouting_break_hours") * 3600; $now = $this->_websoccer->getNowAsTimestamp(); if ($now < $nextPossibleExecutionTimestamp) { throw new Exception($this->_i18n->getMessage("youthteam_scouting_err_breakviolation", $this->_websoccer->getFormattedDatetime($nextPossibleExecutionTimestamp))); } // check if valid country (if name files exists) $namesFolder = NAMES_DIRECTORY . "/" . $parameters["country"]; if (!file_exists($namesFolder . "/firstnames.txt") || !file_exists($namesFolder . "/lastnames.txt")) { throw new Exception($this->_i18n->getMessage("youthteam_scouting_err_invalidcountry")); } // check if valid scout $scout = YouthPlayersDataService::getScoutById($this->_websoccer, $this->_db, $this->_i18n, $parameters["scoutid"]); // check if team can afford it. $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if ($team["team_budget"] <= $scout["fee"]) { throw new Exception($this->_i18n->getMessage("youthteam_scouting_err_notenoughbudget")); } // deduct fee BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $clubId, $scout["fee"], "youthteam_scouting_fee_subject", $scout["name"]); // has scout found someone? $found = TRUE; $succesProbability = (int) $this->_websoccer->getConfig("youth_scouting_success_probability"); if ($this->_websoccer->getConfig("youth_scouting_success_probability") < 100) { $found = SimulationHelper::selectItemFromProbabilities(array(TRUE => $succesProbability, FALSE => 100 - $succesProbability)); } // he found someone, so create youth player if ($found) { $this->createYouthPlayer($clubId, $scout, $parameters["country"]); // create failure message } else { $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, $this->_i18n->getMessage("youthteam_scouting_failure"), "")); } // update last execution time $this->_db->queryUpdate(array("scouting_last_execution" => $now), $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $clubId); return $found ? "youth-team" : "youth-scouting"; }
public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("youth_enabled") || !$this->_websoccer->getConfig("youth_matchrequests_enabled")) { return NULL; } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // get request info $fromTable = $this->_websoccer->getConfig("db_prefix") . "_youthmatch_request"; $result = $this->_db->querySelect("*", $fromTable, "id = %d", $parameters["id"]); $request = $result->fetch_array(); $result->free(); if (!$request) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_cancel_err_notfound")); } // check if own request if ($clubId == $request["team_id"]) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_accept_err_ownrequest")); } // check if team has enough youth players if (YouthPlayersDataService::countYouthPlayersOfTeam($this->_websoccer, $this->_db, $clubId) < 11) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_create_err_notenoughplayers")); } // check maximum number of matches on same day $maxMatchesPerDay = $this->_websoccer->getConfig("youth_match_maxperday"); if (YouthMatchesDataService::countMatchesOfTeamOnSameDay($this->_websoccer, $this->_db, $clubId, $request["matchdate"]) >= $maxMatchesPerDay) { throw new Exception($this->_i18n->getMessage("youthteam_matchrequest_err_maxperday_violated", $maxMatchesPerDay)); } $homeTeam = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $request["team_id"]); $guestTeam = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); // deduct/credit transfer reward if ($request["reward"]) { BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $request["team_id"], $request["reward"], "youthteam_matchrequest_reward_subject", $guestTeam["team_name"]); BankAccountDataService::creditAmount($this->_websoccer, $this->_db, $clubId, $request["reward"], "youthteam_matchrequest_reward_subject", $homeTeam["team_name"]); } // create match $this->_db->queryInsert(array("matchdate" => $request["matchdate"], "home_team_id" => $request["team_id"], "guest_team_id" => $clubId), $this->_websoccer->getConfig("db_prefix") . "_youthmatch"); // delete match request $this->_db->queryDelete($fromTable, "id = %d", $parameters["id"]); // send notification to user NotificationsDataService::createNotification($this->_websoccer, $this->_db, $homeTeam["user_id"], "youthteam_matchrequest_accept_notification", array("team" => $guestTeam["team_name"], "date" => $this->_websoccer->getFormattedDatetime($request["matchdate"])), "youthmatch_accept", "youth-matches", null, $request["team_id"]); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("youthteam_matchrequest_accept_success"), $this->_i18n->getMessage("youthteam_matchrequest_accept_success_details"))); return "youth-matches"; }
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")); } $this->_db->queryDelete($this->_websoccer->getConfig("db_prefix") . "_youthplayer", "id = %d", $parameters["id"]); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("youthteam_fire_success"), "")); return "youth-team"; }
public function getTemplateParameters() { $lastExecutionTimestamp = YouthPlayersDataService::getLastScoutingExecutionTime($this->_websoccer, $this->_db, $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db)); $nextPossibleExecutionTimestamp = $lastExecutionTimestamp + $this->_websoccer->getConfig("youth_scouting_break_hours") * 3600; $now = $this->_websoccer->getNowAsTimestamp(); $scouts = array(); $countries = array(); $scoutingPossible = $nextPossibleExecutionTimestamp <= $now; if ($scoutingPossible) { $scoutId = (int) $this->_websoccer->getRequestParameter("scoutid"); if ($scoutId > 0) { $countries = YouthPlayersDataService::getPossibleScoutingCountries(); } else { $scouts = YouthPlayersDataService::getScouts($this->_websoccer, $this->_db); } } return array("lastExecutionTimestamp" => $lastExecutionTimestamp, "nextPossibleExecutionTimestamp" => $nextPossibleExecutionTimestamp, "scoutingPossible" => $scoutingPossible, "scouts" => $scouts, "countries" => $countries); }
/** * pay salary ans triger player updates. * * @param SimulationMatch $match * @param SimulationTeam $team */ private function _updateTeam(SimulationMatch $match, SimulationTeam $team) { // debit players salary $salary = YouthPlayersDataService::computeSalarySumOfYouthPlayersOfTeam($this->_websoccer, $this->_db, $team->id); if ($salary) { BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $team->id, $salary, 'youthteam_salarypayment_subject', 'match_salarypayment_sender'); } // update players who played if (is_array($team->positionsAndPlayers)) { foreach ($team->positionsAndPlayers as $position => $players) { foreach ($players as $player) { $this->_updatePlayer($match, $player, TRUE); } } } if (is_array($team->removedPlayers)) { foreach ($team->removedPlayers as $player) { $this->_updatePlayer($match, $player, FALSE); } } }
/** * (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"; }
/** * (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); if ($clubId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } // check if it is already 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_buy_err_ownplayer")); } // player must not be tranfered from one of user's other teams $result = $this->_db->querySelect("user_id", $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $player["team_id"]); $playerteam = $result->fetch_array(); $result->free_result(); if ($playerteam["user_id"] == $user->id) { throw new Exception($this->_i18n->getMessage("youthteam_buy_err_ownplayer_otherteam")); } // check if enough budget $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if ($team["team_budget"] <= $player["transfer_fee"]) { throw new Exception($this->_i18n->getMessage("youthteam_buy_err_notenoughbudget")); } // credit / debit amount $prevTeam = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $player["team_id"]); BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $clubId, $player["transfer_fee"], "youthteam_transferfee_subject", $prevTeam["team_name"]); BankAccountDataService::creditAmount($this->_websoccer, $this->_db, $player["team_id"], $player["transfer_fee"], "youthteam_transferfee_subject", $team["team_name"]); // update player $this->_db->queryUpdate(array("team_id" => $clubId, "transfer_fee" => 0), $this->_websoccer->getConfig("db_prefix") . "_youthplayer", "id = %d", $parameters["id"]); // create notification NotificationsDataService::createNotification($this->_websoccer, $this->_db, $prevTeam["user_id"], "youthteam_transfer_notification", array("player" => $player["firstname"] . " " . $player["lastname"], "newteam" => $team["team_name"]), "youth_transfer", "team", "id=" . $clubId); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("youthteam_buy_success"), "")); return "youth-team"; }
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 player is already on market if ($player["transfer_fee"]) { throw new Exception($this->_i18n->getMessage("youthteam_sell_err_alreadyonmarket")); } $this->updatePlayer($parameters["id"], $parameters["transfer_fee"]); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("youthteam_sell_success"), "")); return "youth-team"; }
/** * Creates a new formation for specified team. * Will simply take the first 11 players and place them in a 4-4-2 formation. * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param SimulationMatch $match match model. * @param SimulationTeam $team team model. */ private static function _createRandomFormation(WebSoccer $websoccer, DbConnection $db, SimulationMatch $match, SimulationTeam $team) { // better delete possible previous formation with too few players $db->queryDelete($websoccer->getConfig('db_prefix') . '_youthmatch_player', 'match_id = %d AND team_id = %d', array($match->id, $team->id)); // define the exact default formation $formationPositions = array('T', 'LV', 'IV', 'IV', 'RV', 'LM', 'ZM', 'ZM', 'RM', 'LS', 'RS'); $positionMapping = SimulationHelper::getPositionsMapping(); // set players $players = YouthPlayersDataService::getYouthPlayersOfTeam($websoccer, $db, $team->id); $positionIndex = 0; foreach ($players as $playerinfo) { $mainPosition = $formationPositions[$positionIndex]; $position = $positionMapping[$mainPosition]; $player = new SimulationPlayer($playerinfo['id'], $team, $position, $mainPosition, 3.0, DEFAULT_PLAYER_AGE, $playerinfo['strength'], $playerinfo['strength'], YOUTH_STRENGTH_STAMINA, YOUTH_STRENGTH_FRESHNESS, YOUTH_STRENGTH_SATISFACTION); $player->name = $playerinfo['firstname'] . ' ' . $playerinfo['lastname']; // strength adaption required? if ($player->position != $playerinfo['position']) { $player->strength = round($playerinfo['strength'] * (1 - $websoccer->getConfig('sim_strength_reduction_wrongposition') / 100)); } try { // create record $columns = array('match_id' => $match->id, 'team_id' => $team->id, 'player_id' => $player->id, 'playernumber' => $positionIndex + 1, 'position' => $player->position, 'position_main' => $player->mainPosition, 'name' => $player->name); $db->queryInsert($columns, $websoccer->getConfig('db_prefix') . '_youthmatch_player'); $team->positionsAndPlayers[$player->position][] = $player; } catch (Exception $e) { // could not be stored. Can happen when the youth player moved from the opponent to this team. // then we get a PK violation. We just don't add this player then. } $positionIndex++; if ($positionIndex == 11) { break; } } }