public function getTemplateParameters() { $teamId = $this->_websoccer->getRequestParameter("teamid"); if ($teamId > 0) { $transfers = TransfermarketDataService::getCompletedTransfersOfTeam($this->_websoccer, $this->_db, $teamId); } return array("completedtransfers" => $transfers); }
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); }
public static function computeUserInactivity(WebSoccer $websoccer, DbConnection $db, $userId) { $inactivity = self::getUserInactivity($websoccer, $db, $userId); $now = $websoccer->getNowAsTimestamp(); $checkBoundary = $now - 24 * 3600; $updatecolumns = array(); $user = UsersDataService::getUserById($websoccer, $db, $userId); // compute login-activity if ($inactivity["login_check"] < $checkBoundary) { $inactiveDays = round(($now - $user["lastonline"]) / (24 * 3600)); $updatecolumns["login"] = min(100, round($inactiveDays * INACTIVITY_PER_DAY_LOGIN)); $updatecolumns["login_check"] = $now; // update tactics activity $formationTable = $websoccer->getConfig("db_prefix") . "_aufstellung AS F"; $formationTable .= " INNER JOIN " . $websoccer->getConfig("db_prefix") . "_verein AS T ON T.id = F.verein_id"; $result = $db->querySelect("F.datum AS date", $formationTable, "T.user_id = %d", $userId); $formation = $result->fetch_array(); $result->free(); if ($formation) { $inactiveDays = round(($now - $formation["date"]) / (24 * 3600)); $updatecolumns["aufstellung"] = min(100, round($inactiveDays * INACTIVITY_PER_DAY_TACTICS)); } } // compute transfers-activity (check user's bids) if ($inactivity["transfer_check"] < $checkBoundary) { $bid = TransfermarketDataService::getLatestBidOfUser($websoccer, $db, $userId); $transferBenchmark = $user["registration_date"]; if ($bid) { $transferBenchmark = $bid["date"]; } $inactiveDays = round(($now - $transferBenchmark) / (24 * 3600)); $updatecolumns["transfer"] = min(100, round($inactiveDays * INACTIVITY_PER_DAY_TRANSFERS)); $updatecolumns["transfer_check"] = $now; } // update if (count($updatecolumns)) { $fromTable = $websoccer->getConfig("db_prefix") . "_user_inactivity"; $db->queryUpdate($updatecolumns, $fromTable, "id = %d", $inactivity["id"]); } }
/** * (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 function getTemplateParameters() { $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); $transfers = TransfermarketDataService::getLastCompletedTransfers($this->_websoccer, $this->_db, $teamId); return array("completedtransfers" => $transfers); }
/** * Provides players who are currently available on the transfer market. * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param string $positionFilter position ID as in DB table. * @param int $startIndex fetch start index. * @param int $entries_per_page number of items to fetch. * @return array list of found players or empty array. */ public static function getPlayersOnTransferList(WebSoccer $websoccer, DbConnection $db, $startIndex, $entries_per_page, $positionFilter = null) { $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.vertrag_gehalt'] = 'contract_salary'; $columns['P.vertrag_torpraemie'] = 'contract_goalbonus'; $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['P.transfermarkt'] = 'transfermarket'; $columns['P.marktwert'] = 'marketvalue'; $columns['P.transfer_start'] = 'transfer_start'; $columns['P.transfer_ende'] = 'transfer_deadline'; $columns['P.transfer_mindestgebot'] = 'min_bid'; $columns['C.id'] = 'team_id'; $columns['C.name'] = 'team_name'; $fromTable = $websoccer->getConfig('db_prefix') . '_spieler AS P'; $fromTable .= ' LEFT JOIN ' . $websoccer->getConfig('db_prefix') . '_verein AS C ON C.id = P.verein_id'; $whereCondition = 'P.status = 1 AND P.transfermarkt = 1 AND P.transfer_ende > %d'; $parameters[] = $websoccer->getNowAsTimestamp(); if ($positionFilter != null) { $whereCondition .= ' AND P.position = \'%s\''; $parameters[] = $positionFilter; } $whereCondition .= ' ORDER BY P.transfer_ende ASC, P.nachname ASC, P.vorname ASC'; $limit = $startIndex . ',' . $entries_per_page; $result = $db->querySelect($columns, $fromTable, $whereCondition, $parameters, $limit); $players = array(); while ($player = $result->fetch_array()) { $player['position'] = self::_convertPosition($player['position']); $player['highestbid'] = TransfermarketDataService::getHighestBidForPlayer($websoccer, $db, $player['id'], $player['transfer_start'], $player['transfer_deadline']); $players[] = $player; } $result->free(); return $players; }
/** * @see AbstractJob::execute() */ function execute() { TransfermarketDataService::movePlayersWithoutTeamToTransfermarket($this->_websoccer, $this->_db); }
public function getTemplateParameters() { $highestBid = TransfermarketDataService::getHighestBidForPlayer($this->_websoccer, $this->_db, $this->_player["player_id"], $this->_player["transfer_start"], $this->_player["transfer_end"]); return array("player" => $this->_player, "highestbid" => $highestBid); }
/** * (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; }
/** * @see AbstractJob::execute() */ function execute() { TransfermarketDataService::executeOpenTransfers($this->_websoccer, $this->_db); }
public function getTemplateParameters() { $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db); $bids = TransfermarketDataService::getCurrentBidsOfTeam($this->_websoccer, $this->_db, $teamId); return array("bids" => $bids); }
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; }
/** * 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"]); }