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; }
/** * Creates badge assignment. * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param int $userId ID of user. * @param int $badgeId ID od badge. */ public static function awardBadge(WebSoccer $websoccer, DbConnection $db, $userId, $badgeId) { $badgeUserTable = $websoccer->getConfig('db_prefix') . '_badge_user'; // create assignment $db->queryInsert(array('user_id' => $userId, 'badge_id' => $badgeId, 'date_rewarded' => $websoccer->getNowAsTimestamp()), $badgeUserTable); // notify lucky user NotificationsDataService::createNotification($websoccer, $db, $userId, 'badge_notification', null, 'badge', 'user', 'id=' . $userId); }
/** * Deletes user's absence report and gives back his teams. * Deputy gets notification. * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param int $userId ID of user who returned. */ public static function confirmComeback(WebSoccer $websoccer, DbConnection $db, $userId) { $absence = self::getCurrentAbsenceOfUser($websoccer, $db, $userId); if (!$absence) { return; } // give back teams $db->queryUpdate(array('user_id' => $userId, 'user_id_actual' => NULL), $websoccer->getConfig('db_prefix') . '_verein', 'user_id_actual = %d', $userId); // delete absence(s) $db->queryDelete($websoccer->getConfig('db_prefix') . '_userabsence', 'user_id', $userId); // notify deputy if ($absence['deputy_id']) { $user = UsersDataService::getUserById($websoccer, $db, $userId); NotificationsDataService::createNotification($websoccer, $db, $absence['deputy_id'], 'absence_comeback_notification', array('user' => $user['nick']), 'absence', 'user'); } }
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"; }
/** * (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"; }
private function checkStadiumConstructions() { $constructions = StadiumsDataService::getDueConstructionOrders($this->_websoccer, $this->_db); $newDeadline = $this->_websoccer->getNowAsTimestamp() + $this->_websoccer->getConfig('stadium_construction_delay') * 24 * 3600; foreach ($constructions as $construction) { // is actually completed? $pStatus = array(); $pStatus['completed'] = $construction['builder_reliability']; $pStatus['notcompleted'] = 100 - $pStatus['completed']; $constructionResult = SimulationHelper::selectItemFromProbabilities($pStatus); // not completed: postpone deadline if ($constructionResult == 'notcompleted') { $this->_db->queryUpdate(array('deadline' => $newDeadline), $this->_websoccer->getConfig('db_prefix') . '_stadium_construction', 'id = %d', $construction['id']); // send notification if ($construction['user_id']) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $construction['user_id'], 'stadium_construction_notification_delay', null, 'stadium_construction', 'stadium'); } // completed } else { // update stadium $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $construction['team_id']); $columns = array(); $columns['p_steh'] = $stadium['places_stands'] + $construction['p_steh']; $columns['p_sitz'] = $stadium['places_seats'] + $construction['p_sitz']; $columns['p_haupt_steh'] = $stadium['places_stands_grand'] + $construction['p_haupt_steh']; $columns['p_haupt_sitz'] = $stadium['places_seats_grand'] + $construction['p_haupt_sitz']; $columns['p_vip'] = $stadium['places_vip'] + $construction['p_vip']; $this->_db->queryUpdate($columns, $this->_websoccer->getConfig('db_prefix') . '_stadion', 'id = %d', $stadium['stadium_id']); // delete order $this->_db->queryDelete($this->_websoccer->getConfig('db_prefix') . '_stadium_construction', 'id = %d', $construction['id']); // send notification if ($construction['user_id']) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $construction['user_id'], 'stadium_construction_notification_completed', null, 'stadium_construction', 'stadium'); } } } }
/** * (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; }
private function notifyAboutSoonEndingContracts($userId, $teamId) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $userId, 'notification_soon_ending_playercontracts', '', 'soon_ending_playercontracts', 'myteam', null, $teamId); unset($this->_teamsWithSoonEndingContracts[$teamId]); }
private static function _executeEvent(WebSoccer $websoccer, DbConnection $db, $userId, $clubId, $event) { $notificationType = 'randomevent'; $subject = $event['message']; // debit or credit money if ($event['effect'] == 'money') { $amount = $event['effect_money_amount']; $sender = $websoccer->getConfig('projectname'); if ($amount > 0) { BankAccountDataService::creditAmount($websoccer, $db, $clubId, $amount, $subject, $sender); } else { BankAccountDataService::debitAmount($websoccer, $db, $clubId, $amount * (0 - 1), $subject, $sender); } // notification NotificationsDataService::createNotification($websoccer, $db, $userId, $subject, null, $notificationType, 'finances', null, $clubId); // execute on random player } else { // select random player from team $result = $db->querySelect('id, vorname, nachname, kunstname, w_frische, w_kondition, w_zufriedenheit', $websoccer->getConfig('db_prefix') . '_spieler', 'verein_id = %d AND gesperrt = 0 AND verletzt = 0 AND status = \'1\' ORDER BY RAND()', $clubId, 1); $player = $result->fetch_array(); $result->free(); if (!$player) { return; } // execute (get update column) switch ($event['effect']) { case 'player_injured': $columns = array('verletzt' => $event['effect_blocked_matches']); break; case 'player_blocked': $columns = array('gesperrt' => $event['effect_blocked_matches']); break; case 'player_happiness': $columns = array('w_zufriedenheit' => max(1, min(100, $player['w_zufriedenheit'] + $event['effect_skillchange']))); break; case 'player_fitness': $columns = array('w_frische' => max(1, min(100, $player['w_frische'] + $event['effect_skillchange']))); break; case 'player_stamina': $columns = array('w_kondition' => max(1, min(100, $player['w_kondition'] + $event['effect_skillchange']))); break; } // update player if (!isset($columns)) { return; } $db->queryUpdate($columns, $websoccer->getConfig('db_prefix') . '_spieler', 'id = %d', $player['id']); // create notification $playerName = strlen($player['kunstname']) ? $player['kunstname'] : $player['vorname'] . ' ' . $player['nachname']; NotificationsDataService::createNotification($websoccer, $db, $userId, $subject, array('playername' => $playerName), $notificationType, 'player', 'id=' . $player['id'], $clubId); } }
/** * 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"]); }
private function transferPlayer(WebSoccer $websoccer, DbConnection $db, $player, $bid) { $playerName = strlen($player['pseudonym']) ? $player['pseudonym'] : $player['first_name'] . ' ' . $player['last_name']; // transfer without fee if ($player['team_id'] < 1) { // debit hand money if ($bid['hand_money'] > 0) { BankAccountDataService::debitAmount($websoccer, $db, $bid['team_id'], $bid['hand_money'], 'transfer_transaction_subject_handmoney', $playerName); } // debit / credit fee } else { BankAccountDataService::debitAmount($websoccer, $db, $bid['team_id'], $bid['amount'], 'transfer_transaction_subject_fee', $player['team_name']); BankAccountDataService::creditAmount($websoccer, $db, $player['team_id'], $bid['amount'], 'transfer_transaction_subject_fee', $bid['team_name']); } $fromTable = $websoccer->getConfig('db_prefix') . '_spieler'; // move and update player $columns['transfermarkt'] = 0; $columns['transfer_start'] = 0; $columns['transfer_ende'] = 0; $columns['verein_id'] = $bid['team_id']; $columns['vertrag_spiele'] = $bid['contract_matches']; $columns['vertrag_gehalt'] = $bid['contract_salary']; $columns['vertrag_torpraemie'] = $bid['contract_goalbonus']; $whereCondition = 'id = %d'; $db->queryUpdate($columns, $fromTable, $whereCondition, $player['player_id']); // create transfer log $logcolumns['spieler_id'] = $player['player_id']; $logcolumns['seller_user_id'] = $player['team_user_id']; $logcolumns['seller_club_id'] = $player['team_id']; $logcolumns['buyer_user_id'] = $bid['user_id']; $logcolumns['buyer_club_id'] = $bid['team_id']; $logcolumns['datum'] = $websoccer->getNowAsTimestamp(); $logcolumns['directtransfer_amount'] = $bid['amount']; $logTable = $websoccer->getConfig('db_prefix') . '_transfer'; $db->queryInsert($logcolumns, $logTable); // notify user NotificationsDataService::createNotification($websoccer, $db, $bid['user_id'], 'transfer_bid_notification_transfered', array('player' => $playerName), 'transfermarket', 'player', 'id=' . $player['player_id']); // delete old bids $db->queryDelete($websoccer->getConfig('db_prefix') . '_transfer_angebot', 'spieler_id = %d', $player['player_id']); // award badges self::awardUserForTrades($websoccer, $db, $bid['user_id']); if ($player['team_user_id']) { self::awardUserForTrades($websoccer, $db, $player['team_user_id']); } }
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"; }