/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("enable_player_resignation")) { return; } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // check if it is own player $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $parameters["id"]); if ($clubId != $player["team_id"]) { throw new Exception("nice try"); } // check violation of minimum team size $teamSize = $this->getTeamSize($clubId); if ($teamSize <= $this->_websoccer->getConfig("transfermarket_min_teamsize")) { throw new Exception($this->_i18n->getMessage("sell_player_teamsize_too_small", $teamSize)); } // check and withdraw compensation if ($this->_websoccer->getConfig("player_resignation_compensation_matches") > 0) { $compensation = $this->_websoccer->getConfig("player_resignation_compensation_matches") * $player["player_contract_salary"]; $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if ($team["team_budget"] <= $compensation) { throw new Exception($this->_i18n->getMessage("fireplayer_tooexpensive")); } BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $clubId, $compensation, "fireplayer_compensation_subject", $player["player_firstname"] . " " . $player["player_lastname"]); } $this->updatePlayer($player["player_id"]); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("fireplayer_success"), "")); return null; }
public function executeAction($parameters) { $now = $this->_websoccer->getNowAsTimestamp(); $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); // check if duration is in range $min = $this->_websoccer->getConfig("trainingcamp_min_days"); $max = $this->_websoccer->getConfig("trainingcamp_max_days"); if ($parameters["days"] < $min || $parameters["days"] > $max) { throw new Exception(sprintf($this->_i18n->getMessage("trainingcamp_booking_err_invaliddays"), $min, $max)); } // check if date is in future $startDateObj = DateTime::createFromFormat($this->_websoccer->getConfig("date_format") . " H:i", $parameters["start_date"] . " 00:00"); $startDateTimestamp = $startDateObj->getTimestamp(); $endDateTimestamp = $startDateTimestamp + 3600 * 24 * $parameters["days"]; if ($startDateTimestamp <= $now) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_dateinpast")); } // check if too far in future $maxDate = $now + $this->_websoccer->getConfig("trainingcamp_booking_max_days_in_future") * 3600 * 24; if ($startDateTimestamp > $maxDate) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_datetoofar", $this->_websoccer->getConfig("trainingcamp_booking_max_days_in_future"))); } // get camp details $camp = TrainingcampsDataService::getCampById($this->_websoccer, $this->_db, $parameters["id"]); if (!$camp) { throw new Exception("Illegal ID"); } // check if user still has an open training camp $existingBookings = TrainingcampsDataService::getCampBookingsByTeam($this->_websoccer, $this->_db, $teamId); if (count($existingBookings)) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_existingbookings")); } // check if team can afford it. $playersOfTeam = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $teamId); $totalCosts = $camp["costs"] * $parameters["days"] * count($playersOfTeam); if ($totalCosts >= $team["team_budget"]) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_tooexpensive")); } // check if there are matches within the time frame $matches = MatchesDataService::getMatchesByTeamAndTimeframe($this->_websoccer, $this->_db, $teamId, $startDateTimestamp, $endDateTimestamp); if (count($matches)) { throw new Exception($this->_i18n->getMessage("trainingcamp_booking_err_matcheswithintimeframe")); } // debit amount BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "trainingcamp_booking_costs_subject", $camp["name"]); // create camp booking $columns["verein_id"] = $teamId; $columns["lager_id"] = $camp["id"]; $columns["datum_start"] = $startDateTimestamp; $columns["datum_ende"] = $endDateTimestamp; $this->_db->queryInsert($columns, $this->_websoccer->getConfig("db_prefix") . "_trainingslager_belegung"); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("trainingcamp_booking_success"), "")); return "trainingcamp"; }
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 executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("lending_enabled")) { return NULL; } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // check if user has team if ($clubId == null) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } // check if it is already own player $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $parameters["id"]); if ($clubId == $player["team_id"]) { throw new Exception($this->_i18n->getMessage("lending_hire_err_ownplayer")); } // check if player is borrowed by any user if ($player["lending_owner_id"] > 0) { throw new Exception($this->_i18n->getMessage("lending_hire_err_borrowed_player")); } // check if player is offered for lending if ($player["lending_fee"] == 0) { throw new Exception($this->_i18n->getMessage("lending_hire_err_notoffered")); } // check if player is on transfermarket if ($player["player_transfermarket"] > 0) { throw new Exception($this->_i18n->getMessage("lending_err_on_transfermarket")); } // check min and max duration if ($parameters["matches"] < $this->_websoccer->getConfig("lending_matches_min") || $parameters["matches"] > $this->_websoccer->getConfig("lending_matches_max")) { throw new Exception(sprintf($this->_i18n->getMessage("lending_hire_err_illegalduration"), $this->_websoccer->getConfig("lending_matches_min"), $this->_websoccer->getConfig("lending_matches_max"))); } // check player's contract length if ($parameters["matches"] >= $player["player_contract_matches"]) { throw new Exception($this->_i18n->getMessage("lending_hire_err_contractendingtoosoon", $player["player_contract_matches"])); } // check if team can pay fee and salary $fee = $parameters["matches"] * $player["lending_fee"]; // team should have the money for at least 5 matches to pay him $minBudget = $fee + 5 * $player["player_contract_salary"]; $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if ($team["team_budget"] < $minBudget) { throw new Exception($this->_i18n->getMessage("lending_hire_err_budget_too_low")); } // deduct and credit fee BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $clubId, $fee, "lending_fee_subject", $player["team_name"]); BankAccountDataService::creditAmount($this->_websoccer, $this->_db, $player["team_id"], $fee, "lending_fee_subject", $team["team_name"]); $this->updatePlayer($player["player_id"], $player["team_id"], $clubId, $parameters["matches"]); // create notification for owner $playerName = strlen($player["player_pseudonym"]) ? $player["player_pseudonym"] : $player["player_firstname"] . " " . $player["player_lastname"]; if ($player["team_user_id"]) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $player["team_user_id"], "lending_notification_lent", array("player" => $playerName, "matches" => $parameters["matches"], "newteam" => $team["team_name"]), "lending_lent", "player", "id=" . $player["player_id"]); } // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("lending_hire_success"), "")); return "myteam"; }
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 static function getSponsorOffers(WebSoccer $websoccer, DbConnection $db, $teamId) { $team = TeamsDataService::getTeamSummaryById($websoccer, $db, $teamId); $teamRank = TeamsDataService::getTableRankOfTeam($websoccer, $db, $teamId); $columns["S.id"] = "sponsor_id"; $columns["S.name"] = "name"; $columns["S.b_spiel"] = "amount_match"; $columns["S.b_heimzuschlag"] = "amount_home_bonus"; $columns["S.b_sieg"] = "amount_win"; $columns["S.b_meisterschaft"] = "amount_championship"; $fromTable = $websoccer->getConfig("db_prefix") . "_sponsor AS S"; $whereCondition = "S.liga_id = %d AND (S.min_platz = 0 OR S.min_platz >= %d)" . " AND (S.max_teams <= 0 OR S.max_teams > (SELECT COUNT(*) FROM " . $websoccer->getConfig("db_prefix") . "_verein AS T WHERE T.sponsor_id = S.id AND T.sponsor_spiele > 0))" . " ORDER BY S.b_spiel DESC"; $parameters = array($team["team_league_id"], $teamRank); return $db->queryCachedSelect($columns, $fromTable, $whereCondition, $parameters, 20); }
public function getTemplateParameters() { $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); $count = BankAccountDataService::countAccountStatementsOfTeam($this->_websoccer, $this->_db, $teamId); $eps = $this->_websoccer->getConfig("entries_per_page"); $paginator = new Paginator($count, $eps, $this->_websoccer); if ($count > 0) { $statements = BankAccountDataService::getAccountStatementsOfTeam($this->_websoccer, $this->_db, $teamId, $paginator->getFirstIndex(), $eps); } else { $statements = array(); } return array("budget" => $team["team_budget"], "statements" => $statements, "paginator" => $paginator); }
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("transferoffers_enabled")) { return; } $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); // get offer information $result = $this->_db->querySelect("*", $this->_websoccer->getConfig("db_prefix") . "_transfer_offer", "id = %d AND rejected_date = 0 AND admin_approval_pending = '0'", $parameters["id"]); $offer = $result->fetch_array(); $result->free(); $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $offer["player_id"]); // check if player is already on transfer market if ($player["player_transfermarket"]) { throw new Exception($this->_i18n->getMessage("transferoffer_err_unsellable")); } // check exchange players if ($offer["offer_player1"] || $offer["offer_player2"]) { $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if ($offer["offer_player1"]) { $this->checkExchangePlayer($offer["offer_player1"], $offer["sender_user_id"], $team["team_budget"]); } if ($offer["offer_player2"]) { $this->checkExchangePlayer($offer["offer_player2"], $offer["sender_user_id"], $team["team_budget"]); } } // check if team is above minimum number of players. $teamSize = TeamsDataService::getTeamSize($this->_websoccer, $this->_db, $clubId); if ($teamSize < $this->_websoccer->getConfig("transfermarket_min_teamsize")) { throw new Exception($this->_i18n->getMessage("sell_player_teamsize_too_small", $teamSize)); } // mark offer as pending if ($this->_websoccer->getConfig("transferoffers_adminapproval_required")) { $this->_db->queryUpdate(array("admin_approval_pending" => "1"), $this->_websoccer->getConfig("db_prefix") . "_transfer_offer", "id = %d", $parameters["id"]); $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("transferoffer_accepted_title"), $this->_i18n->getMessage("transferoffer_accepted_message_approvalpending"))); // execute transfer } else { DirectTransfersDataService::executeTransferFromOffer($this->_websoccer, $this->_db, $parameters["id"]); // show success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("transferoffer_accepted_title"), $this->_i18n->getMessage("transferoffer_accepted_message"))); } return null; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig('rename_club_enabled')) { throw new Exceltion("feature is disabled"); } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); if (!$team) { return null; } // rename club $short = strtoupper($parameters['kurz']); $this->_db->queryUpdate(array('name' => $parameters['name'], 'kurz' => $short), $this->_websoccer->getConfig('db_prefix') . '_verein', 'id = %d', $clubId); // rename stadium $this->_db->queryUpdate(array('S.name' => $parameters['stadium']), $this->_websoccer->getConfig('db_prefix') . '_verein AS C INNER JOIN ' . $this->_websoccer->getConfig('db_prefix') . '_stadion AS S ON S.id = C.stadion_id', 'C.id = %d', $clubId); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("rename-club_success"), "")); return 'league'; }
/** * (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"; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } if (TrainingDataService::countRemainingTrainingUnits($this->_websoccer, $this->_db, $teamId)) { throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_existing_units")); } // trainer info $trainer = TrainingDataService::getTrainerById($this->_websoccer, $this->_db, $parameters["id"]); if (!isset($trainer["id"])) { throw new Exception("invalid ID"); } // can team afford it? $numberOfUnits = (int) $parameters["units"]; $totalCosts = $numberOfUnits * $trainer["salary"]; $teamInfo = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); if ($teamInfo["team_budget"] <= $totalCosts) { throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_too_expensive")); } // try to debit premium fee if ($trainer['premiumfee']) { PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $trainer['premiumfee'], "choose-trainer"); } // debit money BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "training_trainer_salary_subject", $trainer["name"]); // create new units $columns["team_id"] = $teamId; $columns["trainer_id"] = $trainer["id"]; $fromTable = $this->_websoccer->getConfig("db_prefix") . "_training_unit"; for ($unitNo = 1; $unitNo <= $numberOfUnits; $unitNo++) { $this->_db->queryInsert($columns, $fromTable); } // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("saved_message_title"), "")); // redirect to training overview return "training"; }
/** * Executes a transfer according to direct transfer offer. Deletes all offers for this player on success. * * @param WebSoccer $websoccer application context. * @param DbConnection $db DB connection. * @param unknown $offerId id of direct transfer offer. */ public static function executeTransferFromOffer(WebSoccer $websoccer, DbConnection $db, $offerId) { // offer data $result = $db->querySelect("*", $websoccer->getConfig("db_prefix") . "_transfer_offer", "id = %d", $offerId); $offer = $result->fetch_array(); $result->free(); if (!$offer) { return; } $currentTeam = TeamsDataService::getTeamSummaryById($websoccer, $db, $offer["receiver_club_id"]); $targetTeam = TeamsDataService::getTeamSummaryById($websoccer, $db, $offer["sender_club_id"]); // move player (and create transfer log) self::_transferPlayer($websoccer, $db, $offer["player_id"], $offer["sender_club_id"], $offer["sender_user_id"], $currentTeam["user_id"], $offer["receiver_club_id"], $offer["offer_amount"], $offer["offer_player1"], $offer["offer_player2"]); // credit amount BankAccountDataService::creditAmount($websoccer, $db, $offer["receiver_club_id"], $offer["offer_amount"], "directtransfer_subject", $targetTeam["team_name"]); // debit amount BankAccountDataService::debitAmount($websoccer, $db, $offer["sender_club_id"], $offer["offer_amount"], "directtransfer_subject", $currentTeam["team_name"]); // move exchange players if ($offer["offer_player1"]) { self::_transferPlayer($websoccer, $db, $offer["offer_player1"], $offer["receiver_club_id"], $currentTeam["user_id"], $targetTeam["user_id"], $offer["sender_club_id"], 0, $offer["player_id"]); } if ($offer["offer_player2"]) { self::_transferPlayer($websoccer, $db, $offer["offer_player2"], $offer["receiver_club_id"], $currentTeam["user_id"], $targetTeam["user_id"], $offer["sender_club_id"], 0, $offer["player_id"]); } // delete offer and other offers for this player $db->queryDelete($websoccer->getConfig("db_prefix") . "_transfer_offer", "player_id = %d", $offer["player_id"]); // get player name for notification $player = PlayersDataService::getPlayerById($websoccer, $db, $offer["player_id"]); if ($player["player_pseudonym"]) { $playerName = $player["player_pseudonym"]; } else { $playerName = $player["player_firstname"] . " " . $player["player_lastname"]; } // notify and award users NotificationsDataService::createNotification($websoccer, $db, $currentTeam["user_id"], "transferoffer_notification_executed", array("playername" => $playerName), NOTIFICATION_TYPE, "player", "id=" . $offer["player_id"], $currentTeam["team_id"]); NotificationsDataService::createNotification($websoccer, $db, $offer["sender_user_id"], "transferoffer_notification_executed", array("playername" => $playerName), NOTIFICATION_TYPE, "player", "id=" . $offer["player_id"], $targetTeam['team_id']); TransfermarketDataService::awardUserForTrades($websoccer, $db, $currentTeam["user_id"]); TransfermarketDataService::awardUserForTrades($websoccer, $db, $offer["sender_user_id"]); }
public function getTemplateParameters() { $fromTable = $this->_websoccer->getConfig("db_prefix") . "_user"; $user = $this->_websoccer->getUser(); // select general information $columns = "fanbeliebtheit AS user_popularity, highscore AS user_highscore"; $whereCondition = "id = %d"; $result = $this->_db->querySelect($columns, $fromTable, $whereCondition, $user->id, 1); $userinfo = $result->fetch_array(); $result->free(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // get team info $team = null; if ($clubId > 0) { $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); } // unread messages $unseenMessages = MessagesDataService::countUnseenInboxMessages($this->_websoccer, $this->_db); // unseen notifications $unseenNotifications = NotificationsDataService::countUnseenNotifications($this->_websoccer, $this->_db, $user->id, $clubId); return array("profile" => $userinfo, "userteam" => $team, "unseenMessages" => $unseenMessages, "unseenNotifications" => $unseenNotifications); }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { return null; } // validate type parameter $type = $parameters["type"]; if (!in_array($type, array("pitch", "videowall", "seatsquality", "vipquality"))) { throw new Exception("illegal parameter: type"); } $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $teamId); if (!$stadium) { return null; } $existingLevel = $stadium["level_" . $type]; // upgradable? if ($existingLevel >= 5) { throw new Exception($this->_i18n->getMessage("stadium_upgrade_err_not_upgradable")); } // can user afford it? $costs = StadiumsDataService::computeUpgradeCosts($this->_websoccer, $type, $stadium); $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); if ($team["team_budget"] <= $costs) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_too_expensive")); } // debit money BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $costs, "stadium_upgrade_transaction_subject", $stadium["name"]); // update stadium $maintenanceDue = (int) $this->_websoccer->getConfig("stadium_maintenanceinterval_" . $type); $this->_db->queryUpdate(array("level_" . $type => $existingLevel + 1, "maintenance_" . $type => $maintenanceDue), $this->_websoccer->getConfig("db_prefix") . "_stadion", "id = %d", $stadium["stadium_id"]); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadium_upgrade_success"), $this->_i18n->getMessage("stadium_upgrade_success_details"))); return "stadium"; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $buildingId = $parameters['id']; $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $dbPrefix = $this->_websoccer->getConfig('db_prefix'); $result = $this->_db->querySelect('*', $dbPrefix . '_stadiumbuilding', 'id = %d', $buildingId); $building = $result->fetch_array(); $result->free(); if (!$building) { // no i18n required since this should actually not happen if used properly. throw new Exception('illegal building.'); } // check budget $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); if ($team['team_budget'] <= $building['costs']) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_too_expensive')); } // check if already exists in team $result = $this->_db->querySelect('*', $dbPrefix . '_buildings_of_team', 'team_id = %d AND building_id = %d', array($teamId, $buildingId)); $buildingExists = $result->fetch_array(); $result->free(); if ($buildingExists) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_already_exists')); } // check required building if ($building['required_building_id']) { $result = $this->_db->querySelect('*', $dbPrefix . '_buildings_of_team', 'team_id = %d AND building_id = %d', array($teamId, $building['required_building_id'])); $requiredBuildingExists = $result->fetch_array(); $result->free(); if (!$requiredBuildingExists) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_requires_building')); } } // check premium costs if ($building['premiumfee'] > $user->premiumBalance) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_premium_balance')); } // withdraw costs BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $building['costs'], 'building_construction_fee_subject', $building['name']); // place order $constructionDeadline = $this->_websoccer->getNowAsTimestamp() + $building['construction_time_days'] * 24 * 3600; $this->_db->queryInsert(array('building_id' => $buildingId, 'team_id' => $teamId, 'construction_deadline' => $constructionDeadline), $dbPrefix . '_buildings_of_team'); // withdraw premium fee if ($building['premiumfee']) { PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $building['premiumfee'], "order-building"); } // credit fan popularity change if ($building['effect_fanpopularity'] != 0) { $result = $this->_db->querySelect('fanbeliebtheit', $dbPrefix . '_user', 'id = %d', $user->id, 1); $userinfo = $result->fetch_array(); $result->free(); $popularity = min(100, max(1, $building['effect_fanpopularity'] + $userinfo['fanbeliebtheit'])); $this->_db->queryUpdate(array('fanbeliebtheit' => $popularity), $dbPrefix . '_user', 'id = %d', $user->id); } // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadiumenvironment_build_success"), "")); return null; }
public static function movePlayersWithoutTeamToTransfermarket(WebSoccer $websoccer, DbConnection $db) { $columns['unsellable'] = 0; $columns['lending_fee'] = 0; $columns['lending_owner_id'] = 0; $columns['lending_matches'] = 0; $fromTable = $websoccer->getConfig('db_prefix') . '_spieler'; // select players: // 1) any player who has no contract any more and are not on the market yet // 2) any player who has no contract any more, but still on the team list // 3) any player who had been added to the list before his contract ended. $whereCondition = 'status = 1 AND (transfermarkt != \'1\' AND (verein_id = 0 OR verein_id IS NULL) OR transfermarkt != \'1\' AND verein_id > 0 AND vertrag_spiele < 1 OR transfermarkt = \'1\' AND verein_id > 0 AND vertrag_spiele < 1)'; // update each player, since we might also update user's inactivity $result = $db->querySelect('id, verein_id', $fromTable, $whereCondition); while ($player = $result->fetch_array()) { $team = TeamsDataService::getTeamSummaryById($websoccer, $db, $player['verein_id']); if ($team == NULL || $team['user_id']) { if ($team['user_id']) { UserInactivityDataService::increaseContractExtensionField($websoccer, $db, $team['user_id']); } $columns['transfermarkt'] = '1'; $columns['transfer_start'] = $websoccer->getNowAsTimestamp(); $columns['transfer_ende'] = $columns['transfer_start'] + 24 * 3600 * $websoccer->getConfig('transfermarket_duration_days'); $columns['transfer_mindestgebot'] = 0; $columns['verein_id'] = ''; // do not move player out of team if team has no manager // (prevents shrinking of teams) } else { $columns['transfermarkt'] = '0'; $columns['transfer_start'] = '0'; $columns['transfer_ende'] = '0'; $columns['vertrag_spiele'] = '5'; $columns['verein_id'] = $player['verein_id']; } $db->queryUpdate($columns, $fromTable, 'id = %d', $player['id']); } $result->free(); }
/** * Debits specified amount from team's account (TAKING money). * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param int $teamId ID of team * @param int $amount Positive amount to debit. If 0, no statement will be created. * @param string $subject message key or untranslated message to display to user. * @param string $sender Name of sender. * @throws Exception if amount is negative or team could not be found. */ public static function debitAmount(WebSoccer $websoccer, DbConnection $db, $teamId, $amount, $subject, $sender) { if ($amount == 0) { return; } $team = TeamsDataService::getTeamSummaryById($websoccer, $db, $teamId); if (!isset($team["team_id"])) { throw new Exception("team not found: " . $teamId); } if ($amount < 0) { throw new Exception("amount illegal: " . $amount); } $amount = 0 - $amount; self::createTransaction($websoccer, $db, $team, $teamId, $amount, $subject, $sender); }
public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("transferoffers_enabled")) { return; } $clubId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); // check if user has team if ($clubId == null) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $this->_websoccer->getRequestParameter("id")); // check if player team has a manager if (!$player["team_user_id"]) { throw new Exception($this->_i18n->getMessage("transferoffer_err_nomanager")); } // check if player is already in one of user's teams if ($player["team_user_id"] == $this->_websoccer->getUser()->id) { throw new Exception($this->_i18n->getMessage("transferoffer_err_ownplayer")); } // check if player is unsellable or already on transfer market if ($player["player_unsellable"] || $player["player_transfermarket"]) { throw new Exception($this->_i18n->getMessage("transferoffer_err_unsellable")); } // check if there are open transfer offered by the user for manager of player $this->checkIfThereAreAlreadyOpenOffersFromUser($player["team_id"]); // check if user is allowed to send an alternative offer after previous offer had been rejected $this->checkIfUserIsAllowedToSendAlternativeOffers($player["player_id"]); // check player is allowed to transfer (Wechselsperre) $this->checkPlayersTransferStop($player["player_id"]); // check exchange player if ($parameters["exchangeplayer1"]) { $this->checkExchangePlayer($parameters["exchangeplayer1"]); } if ($parameters["exchangeplayer2"]) { $this->checkExchangePlayer($parameters["exchangeplayer2"]); } // check if team is above minimum number of players. if ($parameters["exchangeplayer1"] || $parameters["exchangeplayer2"]) { $teamSize = TeamsDataService::getTeamSize($this->_websoccer, $this->_db, $clubId); $numberOfSizeReduction = $parameters["exchangeplayer2"] ? 1 : 0; if ($teamSize < $this->_websoccer->getConfig("transfermarket_min_teamsize") - $numberOfSizeReduction) { throw new Exception($this->_i18n->getMessage("sell_player_teamsize_too_small", $teamSize)); } } // check maximum number of transactions between same user within last 30 days $noOfTransactions = TransfermarketDataService::getTransactionsBetweenUsers($this->_websoccer, $this->_db, $player["team_user_id"], $this->_websoccer->getUser()->id); $maxTransactions = $this->_websoccer->getConfig("transfermarket_max_transactions_between_users"); if ($noOfTransactions >= $maxTransactions) { throw new Exception($this->_i18n->getMessage("transfer_bid_too_many_transactions_with_user", $noOfTransactions)); } // check if budget is enough to pay this amount and sum of other open offers $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); $totalOffers = $this->getSumOfAllOpenOffers() + $parameters["amount"]; if ($team["team_budget"] < $totalOffers) { throw new Exception($this->_i18n->getMessage("transferoffer_err_totaloffers_too_high")); } // check if club can pay this salary TeamsDataService::validateWhetherTeamHasEnoughBudgetForSalaryBid($this->_websoccer, $this->_db, $this->_i18n, $clubId, $player["player_contract_salary"]); // submit offer DirectTransfersDataService::createTransferOffer($this->_websoccer, $this->_db, $player["player_id"], $this->_websoccer->getUser()->id, $clubId, $player["team_user_id"], $player["team_id"], $parameters["amount"], $parameters["comment"], $parameters["exchangeplayer1"], $parameters["exchangeplayer2"]); // show success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("transferoffer_submitted_title"), $this->_i18n->getMessage("transferoffer_submitted_message"))); return null; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { return null; } // any number entered? if (!$parameters["side_standing"] && !$parameters["side_seats"] && !$parameters["grand_standing"] && !$parameters["grand_seats"] && !$parameters["vip"]) { return null; } $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $teamId); if (!$stadium) { return null; } // max limit exceeded? $seatsSide = $stadium["places_stands"] + $stadium["places_seats"] + $parameters["side_standing"] + $parameters["side_seats"]; if ($seatsSide > $this->_websoccer->getConfig("stadium_max_side")) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_side", $this->_websoccer->getConfig("stadium_max_side"))); } $seatsGrand = $stadium["places_stands_grand"] + $stadium["places_seats_grand"] + $parameters["grand_standing"] + $parameters["grand_seats"]; if ($seatsGrand > $this->_websoccer->getConfig("stadium_max_grand")) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_grand", $this->_websoccer->getConfig("stadium_max_grand"))); } $seatsVip = $stadium["places_vip"] + $parameters["vip"]; if ($seatsVip > $this->_websoccer->getConfig("stadium_max_vip")) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_vip", $this->_websoccer->getConfig("stadium_max_vip"))); } // is construction already on-going? if (StadiumsDataService::getCurrentConstructionOrderOfTeam($this->_websoccer, $this->_db, $teamId) != NULL) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_constructionongoing")); } if (isset($parameters["validate-only"]) && $parameters["validate-only"]) { return "stadium-extend-confirm"; } // builder got selected? Illegal builder ID can only happen due to a bug or user input manipulation. $builderId = $this->_websoccer->getRequestParameter("offerid"); $offers = StadiumsDataService::getBuilderOffersForExtension($this->_websoccer, $this->_db, $teamId, (int) $this->_websoccer->getRequestParameter("side_standing"), (int) $this->_websoccer->getRequestParameter("side_seats"), (int) $this->_websoccer->getRequestParameter("grand_standing"), (int) $this->_websoccer->getRequestParameter("grand_seats"), (int) $this->_websoccer->getRequestParameter("vip")); if ($builderId == NULL || !isset($offers[$builderId])) { throw new Exception("Illegal offer ID."); } // can user afford it? $offer = $offers[$builderId]; $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); $totalCosts = $offer["totalCosts"]; if ($team["team_budget"] <= $totalCosts) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_too_expensive")); } // try to debit premium fee if ($offer["builder_premiumfee"]) { PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $offer["builder_premiumfee"], "extend-stadium"); } // debit money BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "stadium_extend_transaction_subject", $offer["builder_name"]); // create construction order $this->_db->queryInsert(array("team_id" => $teamId, "builder_id" => $builderId, "started" => $this->_websoccer->getNowAsTimestamp(), "deadline" => $offer["deadline"], "p_steh" => $parameters["side_standing"] ? $parameters["side_standing"] : 0, "p_sitz" => $parameters["side_seats"] ? $parameters["side_seats"] : 0, "p_haupt_steh" => $parameters["grand_standing"] ? $parameters["grand_standing"] : 0, "p_haupt_sitz" => $parameters["grand_seats"] ? $parameters["grand_seats"] : 0, "p_vip" => $parameters["vip"] ? $parameters["vip"] : 0), $this->_websoccer->getConfig("db_prefix") . "_stadium_construction"); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadium_extend_success"), "")); // create action log manually here, ceause of this great "validate-only" idea... ActionLogDataService::createOrUpdateActionLog($this->_websoccer, $this->_db, $user->id, "extend-stadium"); $seats = $parameters["side_standing"] + $parameters["side_seats"] + $parameters["grand_standing"] + $parameters["grand_seats"] + $parameters["vip"]; BadgesDataService::awardBadgeIfApplicable($this->_websoccer, $this->_db, $user->id, 'stadium_construction_by_x', $seats); return "stadium"; }
private function handleBorrowedPlayer(&$columns, $playerinfo) { $columns['lending_matches'] = max(0, $playerinfo['lending_matches'] - 1); // move back to original team if ($columns['lending_matches'] == 0) { $columns['lending_fee'] = 0; $columns['lending_owner_id'] = 0; $columns['verein_id'] = $playerinfo['lending_owner_id']; // get manager IDs in order to send notification $borrower = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $playerinfo['verein_id']); $lender = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $playerinfo['lending_owner_id']); // create notifications $messageKey = 'lending_notification_return'; $messageType = 'lending_return'; $playerName = $playerinfo['kunstname'] ? $playerinfo['kunstname'] : $playerinfo['vorname'] . ' ' . $playerinfo['nachname']; $messageData = array('player' => $playerName, 'borrower' => $borrower['team_name'], 'lender' => $lender['team_name']); if ($borrower['user_id']) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $borrower['user_id'], $messageKey, $messageData, $messageType, 'player', 'id=' . $playerinfo['id']); } if ($lender['user_id']) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $lender['user_id'], $messageKey, $messageData, $messageType, 'player', 'id=' . $playerinfo['id']); } } }
if ($admin['r_demo']) { $err[] = $i18n->getMessage('validationerror_no_changes_as_demo'); } if (isset($err)) { include 'validationerror.inc.php'; } else { // strengths for player generation $strengths['strength'] = $_POST['entity_player_w_staerke']; $strengths['technique'] = $_POST['entity_player_w_technik']; $strengths['stamina'] = $_POST['entity_player_w_kondition']; $strengths['freshness'] = $_POST['entity_player_w_frische']; $strengths['satisfaction'] = $_POST['entity_player_w_zufriedenheit']; $teamIds = explode(',', $_POST['teamids']); foreach ($teamIds as $teamId) { // get team info $team = TeamsDataService::getTeamSummaryById($website, $db, $teamId); // update team $teamcolumns = array('user_id' => '', 'captain_id' => '', 'finanz_budget' => !empty($_POST['minbudget']) ? max($_POST['minbudget'], $team['team_budget']) : $team['team_budget']); $db->queryUpdate($teamcolumns, $website->getConfig('db_prefix') . '_verein', 'id = %d', $teamId); // disable user if (isset($_POST['disableusers']) && $_POST['disableusers']) { $db->queryUpdate(array('status' => '0'), $website->getConfig('db_prefix') . '_user', 'id = %d', $team['user_id']); } // send message to user if (!empty($_POST['message_subject']) && !empty($_POST['message_content'])) { $db->queryInsert(array('empfaenger_id' => $team['user_id'], 'absender_name' => $website->getConfig('projectname'), 'absender_id' => '', 'datum' => $website->getNowAsTimestamp(), 'betreff' => trim($_POST['message_subject']), 'nachricht' => trim($_POST['message_content'])), $website->getConfig('db_prefix') . '_briefe'); } // count and update players $positionsCount = array(); $positionsCount['T'] = 0; $positionsCount['LV'] = 0;
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig('transfermarket_enabled')) { return; } $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); $playerId = $parameters['id']; // check if user has a club if ($clubId < 1) { throw new Exception($this->_i18n->getMessage('error_action_required_team')); } // check if it is not own player $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $playerId); if ($user->id == $player['team_user_id']) { throw new Exception($this->_i18n->getMessage('transfer_bid_on_own_player')); } // check if player is still on transfer list if (!$player['player_transfermarket']) { throw new Exception($this->_i18n->getMessage('transfer_bid_player_not_on_list')); } // check that auction is not over $now = $this->_websoccer->getNowAsTimestamp(); if ($now > $player['transfer_end']) { throw new Exception($this->_i18n->getMessage('transfer_bid_auction_ended')); } // player must accept the new salary $minSalary = $player['player_contract_salary'] * 1.1; if ($parameters['contract_salary'] < $minSalary) { throw new Exception($this->_i18n->getMessage('transfer_bid_salary_too_less')); } // check goal bonus $minGoalBonus = $player['player_contract_goalbonus'] * 1.1; if ($parameters['contract_goal_bonus'] < $minGoalBonus) { throw new Exception($this->_i18n->getMessage('transfer_bid_goalbonus_too_less')); } // check if user has been already traded too often with the other user if ($player['team_id'] > 0) { $noOfTransactions = TransfermarketDataService::getTransactionsBetweenUsers($this->_websoccer, $this->_db, $player['team_user_id'], $user->id); $maxTransactions = $this->_websoccer->getConfig('transfermarket_max_transactions_between_users'); if ($noOfTransactions >= $maxTransactions) { throw new Exception($this->_i18n->getMessage('transfer_bid_too_many_transactions_with_user', $noOfTransactions)); } } // get existing highest bid $highestBid = TransfermarketDataService::getHighestBidForPlayer($this->_websoccer, $this->_db, $parameters['id'], $player['transfer_start'], $player['transfer_end']); // with transfer-fee: check if own bid amount is higher than existing bid if ($player['team_id'] > 0) { $minBid = $player['transfer_min_bid'] - 1; if (isset($highestBid['amount'])) { $minBid = $highestBid['amount']; } if ($parameters['amount'] <= $minBid) { throw new Exception($this->_i18n->getMessage('transfer_bid_amount_must_be_higher', $minBid)); } // without transfer fee: compare contract conditions } else { if (isset($highestBid['contract_matches'])) { // we compare the total income of the whole offered contract duraction $ownBidValue = $parameters['handmoney'] + $parameters['contract_matches'] * $parameters['contract_salary']; $opponentSalary = $highestBid['hand_money'] + $highestBid['contract_matches'] * $highestBid['contract_salary']; // consider goal bonus only for midfield and striker, assuming player scores 10 goals if ($player['player_position'] == 'midfield' || $player['player_position'] == 'striker') { $ownBidValue += 10 * $parameters['contract_goal_bonus']; $opponentSalary += 10 * $highestBid['contract_goalbonus']; } if ($ownBidValue <= $opponentSalary) { throw new Exception($this->_i18n->getMessage('transfer_bid_contract_conditions_too_low')); } } } // check if budget is enough (hand money/fee + assume that the team consists of 20 players with same salary, then it should survive for 2 matches) TeamsDataService::validateWhetherTeamHasEnoughBudgetForSalaryBid($this->_websoccer, $this->_db, $this->_i18n, $clubId, $parameters['contract_salary']); // check if budget is enough for all current highest bids of user. $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $clubId); $result = $this->_db->querySelect('SUM(abloese) + SUM(handgeld) AS bidsamount', $this->_websoccer->getConfig('db_prefix') . '_transfer_angebot', 'user_id = %d AND ishighest = \'1\'', $user->id); $bids = $result->fetch_array(); $result->free(); if (isset($bids['bidsamount']) && $parameters['handmoney'] + $parameters['amount'] + $bids['bidsamount'] >= $team['team_budget']) { throw new Exception($this->_i18n->getMessage('transfer_bid_budget_for_all_bids_too_less')); } // save bid $this->saveBid($playerId, $user->id, $clubId, $parameters); // mark previous highest bid as outbidden if (isset($highestBid['bid_id'])) { $this->_db->queryUpdate(array('ishighest' => '0'), $this->_websoccer->getConfig('db_prefix') . '_transfer_angebot', 'id = %d', $highestBid['bid_id']); } // notify outbidden user if (isset($highestBid['user_id']) && $highestBid['user_id']) { $playerName = strlen($player['player_pseudonym']) ? $player['player_pseudonym'] : $player['player_firstname'] . ' ' . $player['player_lastname']; NotificationsDataService::createNotification($this->_websoccer, $this->_db, $highestBid['user_id'], 'transfer_bid_notification_outbidden', array('player' => $playerName), 'transfermarket', 'transfer-bid', 'id=' . $playerId); } // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage('transfer_bid_success'), '')); return null; }