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 receiver_club_id = %d", array($parameters["id"], $clubId)); $offer = $result->fetch_array(); $result->free(); if (!$offer) { throw new Exception($this->_i18n->getMessage("transferoffers_offer_cancellation_notfound")); } $this->_db->queryUpdate(array("rejected_date" => $this->_websoccer->getNowAsTimestamp(), "rejected_message" => $parameters["comment"], "rejected_allow_alternative" => $parameters["allow_alternative"] ? 1 : 0), $this->_websoccer->getConfig("db_prefix") . "_transfer_offer", "id = %d", $offer["id"]); // get player name for notification $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $offer["player_id"]); if ($player["player_pseudonym"]) { $playerName = $player["player_pseudonym"]; } else { $playerName = $player["player_firstname"] . " " . $player["player_lastname"]; } // create notification NotificationsDataService::createNotification($this->_websoccer, $this->_db, $offer["sender_user_id"], "transferoffer_notification_rejected", array("playername" => $playerName, "receivername" => $this->_websoccer->getUser()->username), "transferoffer", "transferoffers#sent"); // show success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("transferoffers_offer_reject_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"; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); $team = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $clubId); // 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"); } $this->_db->queryUpdate(array("captain_id" => $parameters["id"]), $this->_websoccer->getConfig("db_prefix") . "_verein", "id = %d", $clubId); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("myteam_player_select_as_captain_success"), "")); // check if captain has been changed and show disappointment if ($team["captain_id"] && $team["captain_id"] != $parameters["id"]) { $oldPlayer = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $team["captain_id"]); // maybe player has moved to new team, then just ignore it if ($oldPlayer["team_id"] == $clubId) { $newSatisfaction = round($oldPlayer["player_strength_satisfaction"] * 0.6); $this->_db->queryUpdate(array("w_zufriedenheit" => $newSatisfaction), $this->_websoccer->getConfig("db_prefix") . "_spieler", "id = %d", $oldPlayer["player_id"]); $playername = strlen($oldPlayer["player_pseudonym"]) ? $oldPlayer["player_pseudonym"] : $oldPlayer["player_firstname"] . " " . $oldPlayer["player_lastname"]; $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, $this->_i18n->getMessage("myteam_player_select_as_captain_warning_old_captain", $playername), "")); } } return null; }
/** * (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; }
/** * (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; }
public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("transfermarket_enabled")) { return NULL; } $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 if player is already on market if ($player["player_transfermarket"]) { throw new Exception($this->_i18n->getMessage("sell_player_already_on_list")); } // check if player is borrowed or lendable. User should not come to this point, so message is not important. if ($player["lending_fee"] > 0) { throw new Exception($this->_i18n->getMessage("lending_err_alreadyoffered")); } // check violation of minimum team size $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)); } $minBidBoundary = round($player["player_marketvalue"] / 2); if ($parameters["min_bid"] < $minBidBoundary) { throw new Exception($this->_i18n->getMessage("sell_player_min_bid_too_low")); } $this->updatePlayer($player["player_id"], $parameters["min_bid"]); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("sell_player_success"), "")); return "transfermarket"; }
public function getTemplateParameters() { $players = array(); if ($this->_websoccer->getRequestParameter("loadformdata")) { $players = PlayersDataService::getPlayersOfTeamByPosition($this->_websoccer, $this->_db, $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db)); } return array("players" => $players, "player" => $this->_player); }
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 renderView() { $playerId = (int) $this->_websoccer->getRequestParameter("id"); if ($playerId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $this->_player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $playerId); return $this->_player["transfer_end"] > $this->_websoccer->getNowAsTimestamp(); }
public function executeAction($parameters) { $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"); } // if player is not happy at club, he does not want to extend at all $satisfaction = $player["player_strength_satisfaction"]; if ($satisfaction < MINIMUM_SATISFACTION_FOR_EXTENSION) { throw new Exception($this->_i18n->getMessage("extend-contract_player_is_unhappy")); } // check if player is already on market if ($player["player_transfermarket"]) { throw new Exception($this->_i18n->getMessage("sell_player_already_on_list")); } // no salary decrease if ($parameters["salary"] < $player["player_contract_salary"]) { throw new Exception($this->_i18n->getMessage("extend-contract_lower_than_current_salary")); } $averageSalary = $this->getAverageSalary($player["player_strength"]); // if salary is already higher than average, then just expect 10% more if ($player["player_contract_salary"] > $averageSalary) { $salaryFactor = 1.1; } else { // make minimum salary dependent on happiness $salaryFactor = (200 - $satisfaction) / 100; } $salaryFactor = max(1.1, $salaryFactor); $minSalary = round($player["player_contract_salary"] * $salaryFactor); // the salary should be at least 90% of the average, except if this would douple the salary if ($averageSalary < $parameters["salary"] * 2) { $minSalaryOfAverage = round(0.9 * $averageSalary); $minSalary = max($minSalary, $minSalaryOfAverage); } if ($parameters["salary"] < $minSalary) { // decrease satisfaction $this->decreaseSatisfaction($player["player_id"], $player["player_strength_satisfaction"]); throw new Exception($this->_i18n->getMessage("extend-contract_salary_too_low")); } // check if club can pay this salary TeamsDataService::validateWhetherTeamHasEnoughBudgetForSalaryBid($this->_websoccer, $this->_db, $this->_i18n, $clubId, $parameters["salary"]); // check goal bonus $minGoalBonus = $player["player_contract_goalbonus"] * 1.3; if ($parameters["goal_bonus"] < $minGoalBonus) { throw new Exception($this->_i18n->getMessage("extend-contract_goalbonus_too_low")); } $this->updatePlayer($player["player_id"], $player["player_strength_satisfaction"], $parameters["salary"], $parameters["goal_bonus"], $parameters["matches"]); // reset inactivity UserInactivityDataService::resetContractExtensionField($this->_websoccer, $this->_db, $user->id); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("extend-contract_success"), "")); return null; }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); $captain_id = TeamsDataService::getTeamCaptainIdOfTeam($this->_websoccer, $this->_db, $teamId); $players = array(); if ($teamId > 0) { $players = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $teamId); } return array("players" => $players, "captain_id" => $captain_id); }
public function getTemplateParameters() { $playerId = (int) $this->_websoccer->getRequestParameter("id"); if ($playerId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $playerId); if (!isset($player["player_id"])) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } return array("player" => $player); }
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() { $playerId = (int) $this->_websoccer->getRequestParameter("id"); if ($playerId < 1) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $playerId); if (!isset($player["player_id"])) { throw new Exception($this->_i18n->getMessage(MSG_KEY_ERROR_PAGENOTFOUND)); } $grades = $this->_getGrades($playerId); $transfers = TransfermarketDataService::getCompletedTransfersOfPlayer($this->_websoccer, $this->_db, $playerId); return array("player" => $player, "grades" => $grades, "completedtransfers" => $transfers); }
private function checkExchangePlayer($playerId, $userId, $teamBudget) { $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $playerId); $playerName = strlen($player["player_pseudonym"]) ? $player["player_pseudonym"] : $player["player_firstname"] . " " . $player["player_lastname"]; // Check if player is moved to tranfermarket if ($player["player_transfermarket"]) { throw new Exception($this->_i18n->getMessage("transferoffer_accept_err_exchangeplayer_on_transfermarket", $playerName)); } // Check if player is still playing for the user (might have changed) if ($player["team_user_id"] != $userId) { throw new Exception($this->_i18n->getMessage("transferoffer_accept_err_exchangeplayer_notinteam", $playerName)); } // check if user can afford player $minBudget = 40 * $player["player_contract_salary"]; if ($teamBudget < $minBudget) { throw new Exception($this->_i18n->getMessage("transferoffer_accept_err_exchangeplayer_salarytoohigh", $playerName)); } }
public function executeAction($parameters) { $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"); } $columns["unsellable"] = 1; $fromTable = $this->_websoccer->getConfig("db_prefix") . "_spieler"; $whereCondition = "id = %d"; $parameters = $parameters["id"]; $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $parameters); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("myteam_unsellable_player_success"), "")); return null; }
public function getTemplateParameters() { $playersCount = PlayersDataService::findPlayersCount($this->_websoccer, $this->_db, $this->_firstName, $this->_lastName, $this->_club, $this->_position, $this->_strength, $this->_lendableOnly); // setup paginator $eps = $this->_websoccer->getConfig("entries_per_page"); $paginator = new Paginator($playersCount, $eps, $this->_websoccer); $paginator->addParameter("block", "playerssearch-results"); $paginator->addParameter("fname", $this->_firstName); $paginator->addParameter("lname", $this->_lastName); $paginator->addParameter("club", $this->_club); $paginator->addParameter("position", $this->_position); $paginator->addParameter("strength", $this->_strength); $paginator->addParameter("lendable", $this->_lendableOnly); // get players records if ($playersCount > 0) { $players = PlayersDataService::findPlayers($this->_websoccer, $this->_db, $this->_firstName, $this->_lastName, $this->_club, $this->_position, $this->_strength, $this->_lendableOnly, $paginator->getFirstIndex(), $eps); } else { $players = array(); } return array("playersCount" => $playersCount, "players" => $players, "paginator" => $paginator); }
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 it is own player $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $parameters["id"]); if ($clubId != $player["team_id"]) { throw new Exception($this->_i18n->getMessage("lending_err_notownplayer")); } // check if player is borrowed by user if ($player["lending_owner_id"] > 0) { throw new Exception($this->_i18n->getMessage("lending_err_borrowed_player")); } // check if player is already offered for lending if ($player["lending_fee"] > 0) { throw new Exception($this->_i18n->getMessage("lending_err_alreadyoffered")); } // check if player is on transfermarket if ($player["player_transfermarket"] > 0) { throw new Exception($this->_i18n->getMessage("lending_err_on_transfermarket")); } // check violation of minimum team size $teamSize = TeamsDataService::getTeamSize($this->_websoccer, $this->_db, $clubId); if ($teamSize <= $this->_websoccer->getConfig("transfermarket_min_teamsize")) { throw new Exception($this->_i18n->getMessage("lending_err_teamsize_too_small", $teamSize)); } // remaining contract is too short $minBidBoundary = round($player["player_marketvalue"] / 2); if ($player["player_contract_matches"] <= $this->_websoccer->getConfig("lending_matches_min")) { throw new Exception($this->_i18n->getMessage("lending_err_contract_too_short")); } $this->updatePlayer($player["player_id"], $parameters["fee"]); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("lend_player_success"), "")); return "myteam"; }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); $columns = array("P.id" => "id", "vorname" => "firstname", "nachname" => "lastname", "kunstname" => "pseudonym", "position" => "position", "position_main" => "position_main", "position_second" => "position_second", "nation" => "player_nationality", "lending_matches" => "lending_matches", "lending_fee" => "lending_fee", "C.id" => "team_id", "C.name" => "team_name"); if ($this->_websoccer->getConfig('players_aging') == 'birthday') { $ageColumn = 'TIMESTAMPDIFF(YEAR,geburtstag,CURDATE())'; } else { $ageColumn = 'age'; } $columns[$ageColumn] = 'age'; $dbPrefix = $this->_websoccer->getConfig("db_prefix"); $fromTable = $dbPrefix . "_spieler P INNER JOIN " . $dbPrefix . "_verein C ON C.id = P.verein_id"; $whereCondition = "P.status = 1 AND lending_owner_id = %d"; $whereCondition .= " ORDER BY lending_matches ASC, position ASC, position_main ASC, nachname ASC, vorname ASC"; $result = $this->_db->querySelect($columns, $fromTable, $whereCondition, $teamId, 50); $players = array(); while ($player = $result->fetch_array()) { $player["position"] = PlayersDataService::_convertPosition($player["position"]); $players[] = $player; } $result->free(); return array('lentplayers' => $players); }
public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // check if it is own player. Might be already lent in the meanwhile. Or someone tries to cheat. $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $parameters["id"]); if ($clubId != $player["team_id"]) { throw new Exception($this->_i18n->getMessage("lending_err_notownplayer")); } // check if he is already lent. // Then the player is lent to the user itself and he tries to cheat, hence message is not that important. if ($player["lending_owner_id"] > 0) { throw new Exception($this->_i18n->getMessage("lending_err_borrowed_player")); } $columns = array("lending_fee" => 0); $fromTable = $this->_websoccer->getConfig("db_prefix") . "_spieler"; $whereCondition = "id = %d"; $parameters = $parameters["id"]; $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $parameters); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("lending_lendable_unmark_success"), "")); return null; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { // check if feature is enabled if (!$this->_websoccer->getConfig("transfermarket_enabled")) { return NULL; } $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 if there is already a bid $highestBid = TransfermarketDataService::getHighestBidForPlayer($this->_websoccer, $this->_db, $parameters["id"], $player["transfer_start"], $player["transfer_end"]); if ($highestBid) { throw new Exception($this->_i18n->getMessage("transfermarket_remove_err_bidexists")); } $this->_db->queryUpdate(array('transfermarkt' => '0', 'transfer_start' => 0, 'transfer_ende' => 0), $this->_websoccer->getConfig('db_prefix') . '_spieler', 'id = %d', $parameters['id']); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("transfermarket_remove_success"), "")); return "myteam"; }
public static function executeCamp(WebSoccer $websoccer, DbConnection $db, $teamId, $bookingInfo) { $players = PlayersDataService::getPlayersOfTeamById($websoccer, $db, $teamId); if (count($players)) { $playerTable = $websoccer->getConfig("db_prefix") . "_spieler"; $updateCondition = "id = %d"; $duration = round(($bookingInfo["date_end"] - $bookingInfo["date_start"]) / (24 * 3600)); // update players foreach ($players as $player) { if ($player["matches_injured"] > 0) { continue; } $columns = array(); $columns["w_staerke"] = min(100, max(1, $bookingInfo["effect_strength"] * $duration + $player["strength"])); $columns["w_technik"] = min(100, max(1, $bookingInfo["effect_strength_technique"] * $duration + $player["strength_technic"])); $columns["w_kondition"] = min(100, max(1, $bookingInfo["effect_strength_stamina"] * $duration + $player["strength_stamina"])); $columns["w_frische"] = min(100, max(1, $bookingInfo["effect_strength_freshness"] * $duration + $player["strength_freshness"])); $columns["w_zufriedenheit"] = min(100, max(1, $bookingInfo["effect_strength_satisfaction"] * $duration + $player["strength_satisfaction"])); $db->queryUpdate($columns, $playerTable, $updateCondition, $player["id"]); } } // delete booking $db->queryDelete($websoccer->getConfig("db_prefix") . "_trainingslager_belegung", "id = %d", $bookingInfo["id"]); }
public function getTemplateParameters() { $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $positionInput = $this->_websoccer->getRequestParameter("position"); $positionFilter = null; if ($positionInput == "goaly") { $positionFilter = "Torwart"; } else { if ($positionInput == "defense") { $positionFilter = "Abwehr"; } else { if ($positionInput == "midfield") { $positionFilter = "Mittelfeld"; } else { if ($positionInput == "striker") { $positionFilter = "Sturm"; } } } } $count = PlayersDataService::countPlayersOnTransferList($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", $positionInput); } if ($count > 0) { $players = PlayersDataService::getPlayersOnTransferList($this->_websoccer, $this->_db, $paginator->getFirstIndex(), $eps, $positionFilter); } else { $players = array(); } return array("transferplayers" => $players, "playerscount" => $count, "paginator" => $paginator); }
/** * Provides youth players who are transferable. * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param string|NULL $positionFilter DB value of position to filter for. * @param int $startIndex fetch start index. * @param int $entries_per_page Number of items to fetch. * @return array Array of players or empty array if no youth players found. */ public static function getTransferableYouthPlayers(WebSoccer $websoccer, DbConnection $db, $positionFilter = NULL, $startIndex, $entries_per_page) { $columns = array("P.id" => "player_id", "P.firstname" => "firstname", "P.lastname" => "lastname", "P.position" => "position", "P.nation" => "nation", "P.transfer_fee" => "transfer_fee", "P.age" => "age", "P.strength" => "strength", "P.st_matches" => "st_matches", "P.st_goals" => "st_goals", "P.st_assists" => "st_assists", "P.st_cards_yellow" => "st_cards_yellow", "P.st_cards_yellow_red" => "st_cards_yellow_red", "P.st_cards_red" => "st_cards_red", "P.team_id" => "team_id", "C.name" => "team_name", "C.bild" => "team_picture", "C.user_id" => "user_id", "U.nick" => "user_nick", "U.email" => "user_email", "U.picture" => "user_picture"); $fromTable = $websoccer->getConfig("db_prefix") . "_youthplayer AS P"; $fromTable .= " INNER JOIN " . $websoccer->getConfig("db_prefix") . "_verein AS C ON C.id = P.team_id"; $fromTable .= " LEFT JOIN " . $websoccer->getConfig("db_prefix") . "_user AS U ON U.id = C.user_id"; $parameters = ""; $whereCondition = "P.transfer_fee > 0"; if ($positionFilter != NULL) { $whereCondition .= " AND P.position = '%s'"; $parameters = $positionFilter; } $whereCondition .= " ORDER BY P.strength DESC"; $players = array(); $limit = $startIndex . "," . $entries_per_page; $result = $db->querySelect($columns, $fromTable, $whereCondition, $parameters, $limit); while ($player = $result->fetch_array()) { $player["user_picture"] = UsersDataService::getUserProfilePicture($websoccer, $player["user_picture"], $player["user_email"], 20); $player["nation_flagfile"] = PlayersDataService::getFlagFilename($player["nation"]); $players[] = $player; } $result->free(); return $players; }
public static function getMatchPlayerRecordsByField(WebSoccer $websoccer, DbConnection $db, $matchId, $teamId) { $fromTable = $websoccer->getConfig('db_prefix') . '_spiel_berechnung AS M'; $fromTable .= ' INNER JOIN ' . $websoccer->getConfig('db_prefix') . '_spieler AS P ON P.id = M.spieler_id'; $columns = array('P.id' => 'id', 'P.vorname' => 'firstname', 'P.nachname' => 'lastname', 'P.kunstname' => 'pseudonym', 'P.verletzt' => 'matches_injured', 'P.position' => 'position', 'P.position_main' => 'position_main', 'P.position_second' => 'position_second', 'P.w_staerke' => 'strength', 'P.w_technik' => 'strength_technique', 'P.w_kondition' => 'strength_stamina', 'P.w_frische' => 'strength_freshness', 'P.w_zufriedenheit' => 'strength_satisfaction', 'P.nation' => 'player_nationality', 'P.picture' => 'picture', 'P.sa_tore' => 'st_goals', 'P.sa_spiele' => 'st_matches', 'P.sa_karten_gelb' => 'st_cards_yellow', 'P.sa_karten_gelb_rot' => 'st_cards_yellow_red', 'P.sa_karten_rot' => 'st_cards_red', 'M.id' => 'match_record_id', 'M.position' => 'match_position', 'M.position_main' => 'match_position_main', 'M.feld' => 'field', 'M.note' => 'grade'); if ($websoccer->getConfig('players_aging') == 'birthday') { $ageColumn = 'TIMESTAMPDIFF(YEAR,P.geburtstag,CURDATE())'; } else { $ageColumn = 'P.age'; } $columns[$ageColumn] = 'age'; $whereCondition = 'M.spiel_id = %d AND M.team_id = %d AND M.feld != \'Ausgewechselt\' ORDER BY field(M.position_main, \'T\', \'LV\', \'IV\', \'RV\', \'DM\', \'LM\', \'ZM\', \'RM\', \'OM\', \'LS\', \'MS\', \'RS\'), M.id ASC'; $parameters = array($matchId, $teamId); $result = $db->querySelect($columns, $fromTable, $whereCondition, $parameters); $players = array(); while ($player = $result->fetch_array()) { $field = $player['field'] === '1' ? 'field' : 'bench'; $player['position'] = PlayersDataService::_convertPosition($player['position']); $players[$field][] = $player; } $result->free(); return $players; }
/** * Players search for national teams. * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param string $nationality Nationality as in DB. * @param int $teamId ID of team. * @param string $firstName first name. * @param string $lastName surname or pseudonym. * @param string $position position as in DB (Torwart|ABwehr|Mittelfeld|Sturm) * @param string $mainPosition main position as in DB (T, LV, IV, ...) * @param int $startIndex fetch start index. * @param int $entries_per_page number of entries per pae. * @return array list of found players. */ public static function findPlayers(WebSoccer $websoccer, DbConnection $db, $nationality, $teamId, $firstName, $lastName, $position, $mainPosition, $startIndex, $entries_per_page) { $columns["P.id"] = "id"; $columns["P.vorname"] = "firstname"; $columns["P.nachname"] = "lastname"; $columns["P.kunstname"] = "pseudonym"; $columns["P.position"] = "position"; $columns["P.position_main"] = "position_main"; $columns["P.position_second"] = "position_second"; $columns["P.w_staerke"] = "strength"; $columns["P.w_technik"] = "strength_technique"; $columns["P.w_kondition"] = "strength_stamina"; $columns["P.w_frische"] = "strength_freshness"; $columns["P.w_zufriedenheit"] = "strength_satisfaction"; $columns["C.id"] = "team_id"; $columns["C.name"] = "team_name"; $limit = $startIndex . "," . $entries_per_page; $result = self::executeFindQuery($websoccer, $db, $columns, $limit, $nationality, $teamId, $firstName, $lastName, $position, $mainPosition); $players = array(); while ($player = $result->fetch_array()) { $player["position"] = PlayersDataService::_convertPosition($player["position"]); $players[] = $player; } $result->free(); return $players; }
/** * (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)); }
private function trainPlayers($teamId, $trainer, $unit) { // compute effect on every player $players = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $teamId); // freshness decrease for stamina and technique training $freshnessDecrease = round(1 + $unit["intensity"] / 100 * 5); $fromTable = $this->_websoccer->getConfig("db_prefix") . "_spieler"; $whereCondition = "id = %d"; $trainingEffects = array(); foreach ($players as $player) { // injured player only refreshes and looses stamina $effectFreshness = 0; $effectStamina = 0; $effectTechnique = 0; $effectSatisfaction = 0; if ($player["matches_injured"]) { $effectFreshness = 1; $effectStamina = -1; } else { // regeneration training if ($unit["focus"] == "FR") { $effectFreshness = 5; $effectStamina = -2; $effectSatisfaction = 1; // motivation training } else { if ($unit["focus"] == "MOT") { $effectFreshness = 1; $effectStamina = -1; $effectSatisfaction = 5; // stamina training } else { if ($unit["focus"] == "STA") { $effectSatisfaction = -1; // freshness depends on intensity $effectFreshness = -$freshnessDecrease; // success depends on trainer skills and intensity $staminaIncrease = 1; if ($unit["intensity"] > 50) { $successFactor = $unit["intensity"] * $trainer["p_stamina"] / 100; $pStamina[5] = $successFactor; $pStamina[1] = 100 - $successFactor; $staminaIncrease += SimulationHelper::selectItemFromProbabilities($pStamina); } $effectStamina = $staminaIncrease; // technique } else { $effectFreshness = -$freshnessDecrease; if ($unit["intensity"] > 20) { $effectStamina = 1; } $techIncrease = 0; if ($unit["intensity"] > 75) { $successFactor = $unit["intensity"] * $trainer["p_technique"] / 100; $pTech[2] = $successFactor; $pTech[0] = 100 - $successFactor; $techIncrease += SimulationHelper::selectItemFromProbabilities($pTech); } $effectTechnique = $techIncrease; } } } } // call plugins $event = new PlayerTrainedEvent($this->_websoccer, $this->_db, $this->_i18n, $player["id"], $teamId, $trainer["id"], $effectFreshness, $effectTechnique, $effectStamina, $effectSatisfaction); PluginMediator::dispatchEvent($event); // update player $columns = array("w_frische" => min(100, max(1, $player["strength_freshness"] + $effectFreshness)), "w_technik" => min(100, max(1, $player["strength_technic"] + $effectTechnique)), "w_kondition" => min(100, max(1, $player["strength_stamina"] + $effectStamina)), "w_zufriedenheit" => min(100, max(1, $player["strength_satisfaction"] + $effectSatisfaction))); $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $player["id"]); // add effect $trainingEffects[$player["id"]] = array("name" => $player["pseudonym"] ? $player["pseudonym"] : $player["firstname"] . " " . $player["lastname"], "freshness" => $effectFreshness, "technique" => $effectTechnique, "stamina" => $effectStamina, "satisfaction" => $effectSatisfaction); } $this->_websoccer->addContextParameter("trainingEffects", $trainingEffects); }
/** * (non-PHPdoc) * @see IModel::getTemplateParameters() */ public function getTemplateParameters() { $isNationalTeam = $this->_websoccer->getRequestParameter("nationalteam") ? TRUE : FALSE; $players = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $this->_teamid, $isNationalTeam); return array("players" => $players); }
/** * (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; }