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 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; }
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"; }
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; }