/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { return null; } // any number entered? if (!$parameters["side_standing"] && !$parameters["side_seats"] && !$parameters["grand_standing"] && !$parameters["grand_seats"] && !$parameters["vip"]) { return null; } $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $teamId); if (!$stadium) { return null; } // max limit exceeded? $seatsSide = $stadium["places_stands"] + $stadium["places_seats"] + $parameters["side_standing"] + $parameters["side_seats"]; if ($seatsSide > $this->_websoccer->getConfig("stadium_max_side")) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_side", $this->_websoccer->getConfig("stadium_max_side"))); } $seatsGrand = $stadium["places_stands_grand"] + $stadium["places_seats_grand"] + $parameters["grand_standing"] + $parameters["grand_seats"]; if ($seatsGrand > $this->_websoccer->getConfig("stadium_max_grand")) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_grand", $this->_websoccer->getConfig("stadium_max_grand"))); } $seatsVip = $stadium["places_vip"] + $parameters["vip"]; if ($seatsVip > $this->_websoccer->getConfig("stadium_max_vip")) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_vip", $this->_websoccer->getConfig("stadium_max_vip"))); } // is construction already on-going? if (StadiumsDataService::getCurrentConstructionOrderOfTeam($this->_websoccer, $this->_db, $teamId) != NULL) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_constructionongoing")); } if (isset($parameters["validate-only"]) && $parameters["validate-only"]) { return "stadium-extend-confirm"; } // builder got selected? Illegal builder ID can only happen due to a bug or user input manipulation. $builderId = $this->_websoccer->getRequestParameter("offerid"); $offers = StadiumsDataService::getBuilderOffersForExtension($this->_websoccer, $this->_db, $teamId, (int) $this->_websoccer->getRequestParameter("side_standing"), (int) $this->_websoccer->getRequestParameter("side_seats"), (int) $this->_websoccer->getRequestParameter("grand_standing"), (int) $this->_websoccer->getRequestParameter("grand_seats"), (int) $this->_websoccer->getRequestParameter("vip")); if ($builderId == NULL || !isset($offers[$builderId])) { throw new Exception("Illegal offer ID."); } // can user afford it? $offer = $offers[$builderId]; $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); $totalCosts = $offer["totalCosts"]; if ($team["team_budget"] <= $totalCosts) { throw new Exception($this->_i18n->getMessage("stadium_extend_err_too_expensive")); } // try to debit premium fee if ($offer["builder_premiumfee"]) { PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $offer["builder_premiumfee"], "extend-stadium"); } // debit money BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "stadium_extend_transaction_subject", $offer["builder_name"]); // create construction order $this->_db->queryInsert(array("team_id" => $teamId, "builder_id" => $builderId, "started" => $this->_websoccer->getNowAsTimestamp(), "deadline" => $offer["deadline"], "p_steh" => $parameters["side_standing"] ? $parameters["side_standing"] : 0, "p_sitz" => $parameters["side_seats"] ? $parameters["side_seats"] : 0, "p_haupt_steh" => $parameters["grand_standing"] ? $parameters["grand_standing"] : 0, "p_haupt_sitz" => $parameters["grand_seats"] ? $parameters["grand_seats"] : 0, "p_vip" => $parameters["vip"] ? $parameters["vip"] : 0), $this->_websoccer->getConfig("db_prefix") . "_stadium_construction"); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadium_extend_success"), "")); // create action log manually here, ceause of this great "validate-only" idea... ActionLogDataService::createOrUpdateActionLog($this->_websoccer, $this->_db, $user->id, "extend-stadium"); $seats = $parameters["side_standing"] + $parameters["side_seats"] + $parameters["grand_standing"] + $parameters["grand_seats"] + $parameters["vip"]; BadgesDataService::awardBadgeIfApplicable($this->_websoccer, $this->_db, $user->id, 'stadium_construction_by_x', $seats); return "stadium"; }
} if ($isOffline) { $parameters['offline_message'] = nl2br($website->getConfig('offline_text')); echo $website->getTemplateEngine($i18n)->loadTemplate('views/offline')->render($parameters); // show page } else { // check once per session if a new badge for user is applicable if (!isset($_SESSION['badgechecked']) && $website->getUser()->getRole() == ROLE_USER && $website->getUser()->getClubId($website, $db)) { $userId = $website->getUser()->id; $result = $db->querySelect('datum_anmeldung', $website->getConfig('db_prefix') . '_user', 'id = %d', $userId); $userinfo = $result->fetch_array(); $result->free(); // consider only users who have a registration date (in particular manually created users might not have). if ($userinfo['datum_anmeldung']) { $numberOfRegisteredDays = round(($website->getNowAsTimestamp() - $userinfo['datum_anmeldung']) / (3600 * 24)); BadgesDataService::awardBadgeIfApplicable($website, $db, $userId, 'membership_since_x_days', $numberOfRegisteredDays); } $_SESSION['badgechecked'] = 1; } // get page ID and parse it by router $pageId = $website->getRequestParameter(PARAM_PAGE); $pageId = PageIdRouter::getTargetPageId($website, $i18n, $pageId); $website->setPageId($pageId); $validationMessages = null; // handle action $actionId = $website->getRequestParameter(PARAM_ACTION); if ($actionId !== NULL) { try { $targetId = ActionHandler::handleAction($website, $db, $i18n, $actionId); if ($targetId != null) { $pageId = $targetId;
/** * Pays configured cup round awards (such as per round or winner/second of final round) * and creates actual matches for next cup round, if available. * * @param WebSoccer $websoccer application context. * @param DbConnection $db DB Connection- * @param int $winnerTeamId ID of winner team. * @param int $loserTeamId ID of loser team. * @param string $cupName matche's cup name. * @param string $cupRound matche's cup round name. */ public static function createNextRoundMatchAndPayAwards(WebSoccer $websoccer, DbConnection $db, $winnerTeamId, $loserTeamId, $cupName, $cupRound) { // rounds and cup info $columns['C.id'] = 'cup_id'; $columns['C.winner_award'] = 'cup_winner_award'; $columns['C.second_award'] = 'cup_second_award'; $columns['C.perround_award'] = 'cup_perround_award'; $columns['R.id'] = 'round_id'; $columns['R.finalround'] = 'is_finalround'; $fromTable = $websoccer->getConfig('db_prefix') . '_cup_round AS R'; $fromTable .= ' INNER JOIN ' . $websoccer->getConfig('db_prefix') . '_cup AS C ON C.id = R.cup_id'; $result = $db->querySelect($columns, $fromTable, 'C.name = \'%s\' AND R.name = \'%s\'', array($cupName, $cupRound), 1); $round = $result->fetch_array(); $result->free(); // do nothing if no round is configured if (!$round) { return; } // credit per round award if ($round['cup_perround_award']) { BankAccountDataService::creditAmount($websoccer, $db, $winnerTeamId, $round['cup_perround_award'], 'cup_cuproundaward_perround_subject', $cupName); BankAccountDataService::creditAmount($websoccer, $db, $loserTeamId, $round['cup_perround_award'], 'cup_cuproundaward_perround_subject', $cupName); } $result = $db->querySelect('user_id', $websoccer->getConfig('db_prefix') . '_verein', 'id = %d', $winnerTeamId); $winnerclub = $result->fetch_array(); $result->free(); $result = $db->querySelect('user_id', $websoccer->getConfig('db_prefix') . '_verein', 'id = %d', $loserTeamId); $loserclub = $result->fetch_array(); $result->free(); // create achievement log $now = $websoccer->getNowAsTimestamp(); if ($winnerclub['user_id']) { $db->queryInsert(array('user_id' => $winnerclub['user_id'], 'team_id' => $winnerTeamId, 'cup_round_id' => $round['round_id'], 'date_recorded' => $now), $websoccer->getConfig('db_prefix') . '_achievement'); } if ($loserclub['user_id']) { $db->queryInsert(array('user_id' => $loserclub['user_id'], 'team_id' => $loserTeamId, 'cup_round_id' => $round['round_id'], 'date_recorded' => $now), $websoccer->getConfig('db_prefix') . '_achievement'); } // was final round? if ($round['is_finalround']) { // credit awards if ($round['cup_winner_award']) { BankAccountDataService::creditAmount($websoccer, $db, $winnerTeamId, $round['cup_winner_award'], 'cup_cuproundaward_winner_subject', $cupName); } if ($round['cup_second_award']) { BankAccountDataService::creditAmount($websoccer, $db, $loserTeamId, $round['cup_second_award'], 'cup_cuproundaward_second_subject', $cupName); } // update 'winner flag' of cup $db->queryUpdate(array('winner_id' => $winnerTeamId), $websoccer->getConfig('db_prefix') . '_cup', 'id = %d', $round['cup_id']); // award badge if ($winnerclub['user_id']) { BadgesDataService::awardBadgeIfApplicable($websoccer, $db, $winnerclub['user_id'], 'cupwinner'); } // create matches for next round } else { $columns = 'id,firstround_date,secondround_date,name'; $fromTable = $websoccer->getConfig('db_prefix') . '_cup_round'; // get next round for winner $result = $db->querySelect($columns, $fromTable, 'from_winners_round_id = %d', $round['round_id'], 1); $winnerRound = $result->fetch_array(); $result->free(); if (isset($winnerRound['id'])) { self::createMatchForTeamAndRound($websoccer, $db, $winnerTeamId, $winnerRound['id'], $winnerRound['firstround_date'], $winnerRound['secondround_date'], $cupName, $winnerRound['name']); } // get next round for loser $result = $db->querySelect($columns, $fromTable, 'from_loosers_round_id = %d', $round['round_id'], 1); $loserRound = $result->fetch_array(); $result->free(); if (isset($loserRound['id'])) { self::createMatchForTeamAndRound($websoccer, $db, $loserTeamId, $loserRound['id'], $loserRound['firstround_date'], $loserRound['secondround_date'], $cupName, $loserRound['name']); } } }
private function updateUsers(SimulationMatch $match) { $highscoreWin = $this->_websoccer->getConfig('highscore_win'); $highscoreLoss = $this->_websoccer->getConfig('highscore_loss'); $highscoreDraw = $this->_websoccer->getConfig('highscore_draw'); $columns = 'U.id AS u_id, U.highscore AS highscore, U.fanbeliebtheit AS popularity'; $fromTable = $this->_websoccer->getConfig('db_prefix') . '_verein AS T'; $fromTable .= ' INNER JOIN ' . $this->_websoccer->getConfig('db_prefix') . '_user AS U ON U.id = T.user_id'; $whereCondition = 'T.id = %d'; $result = $this->_db->querySelect($columns, $fromTable, $whereCondition, $match->homeTeam->id); $homeUser = $result->fetch_array(); $result->free(); $updateTable = $this->_websoccer->getConfig('db_prefix') . '_user'; $updateCondition = 'id = %d'; // make popularity dependent on strength $homeStrength = $match->homeTeam->computeTotalStrength($this->_websoccer, $match); $guestStrength = $match->guestTeam->computeTotalStrength($this->_websoccer, $match); // the strength difference between home and guest team in per cent. Positive value means, home team is stronger. if ($homeStrength) { $homeGuestStrengthDiff = round(($homeStrength - $guestStrength) / $homeStrength * 100); } else { $homeGuestStrengthDiff = 0; } // update user of home team if (!empty($homeUser['u_id']) && !$match->homeTeam->noFormationSet) { if ($match->homeTeam->getGoals() > $match->guestTeam->getGoals()) { $homeColumns['highscore'] = max(0, $homeUser['highscore'] + $highscoreWin); // fans only get excited if team was not much stronger $popFactor = 1.1; if ($homeGuestStrengthDiff >= 20) { $popFactor = 1.05; } $homeColumns['fanbeliebtheit'] = min(100, round($homeUser['popularity'] * $popFactor)); // badge applicable? $goalsDiff = $match->homeTeam->getGoals() - $match->guestTeam->getGoals(); BadgesDataService::awardBadgeIfApplicable($this->_websoccer, $this->_db, $homeUser['u_id'], 'win_with_x_goals_difference', $goalsDiff); } else { if ($match->homeTeam->getGoals() == $match->guestTeam->getGoals()) { $homeColumns['highscore'] = max(0, $homeUser['highscore'] + $highscoreDraw); // fans react on strength difference. $popFactor = 1.0; if ($homeGuestStrengthDiff >= 20) { // if much stronger, they dislike it $popFactor = 0.95; } else { if ($homeGuestStrengthDiff <= -20) { // if much weaker, they like it! it is an achievement $popFactor = 1.05; } } $homeColumns['fanbeliebtheit'] = min(100, round($homeUser['popularity'] * $popFactor)); } else { $homeColumns['highscore'] = max(0, $homeUser['highscore'] + $highscoreLoss); // fans react on strength difference. $popFactor = 0.95; if ($homeGuestStrengthDiff >= 20) { // if much stronger, they dislike it even more $popFactor = 0.9; } else { if ($homeGuestStrengthDiff <= -20) { // if much weaker, it is ok for them $popFactor = 1.0; } } $homeColumns['fanbeliebtheit'] = max(1, round($homeUser['popularity'] * $popFactor)); } } if (!$match->homeTeam->isManagedByInterimManager) { $this->_db->queryUpdate($homeColumns, $updateTable, $updateCondition, $homeUser['u_id']); } // send notification about soon ending contracts if (isset($this->_teamsWithSoonEndingContracts[$match->homeTeam->id])) { $this->notifyAboutSoonEndingContracts($homeUser['u_id'], $match->homeTeam->id); } } $result = $this->_db->querySelect($columns, $fromTable, $whereCondition, $match->guestTeam->id); $guestUser = $result->fetch_array(); $result->free(); if (!empty($guestUser['u_id']) && !$match->guestTeam->noFormationSet) { if ($match->guestTeam->getGoals() > $match->homeTeam->getGoals()) { // fans only get excited if team was not much stronger $popFactor = 1.1; if ($homeGuestStrengthDiff <= -20) { $popFactor = 1.05; } $guestColumns['highscore'] = max(0, $guestUser['highscore'] + $highscoreWin); $guestColumns['fanbeliebtheit'] = min(100, round($guestUser['popularity'] * $popFactor)); // badge applicable? $goalsDiff = $match->guestTeam->getGoals() - $match->homeTeam->getGoals(); BadgesDataService::awardBadgeIfApplicable($this->_websoccer, $this->_db, $guestUser['u_id'], 'win_with_x_goals_difference', $goalsDiff); } else { if ($match->guestTeam->getGoals() == $match->homeTeam->getGoals()) { // fans react on strength difference. $popFactor = 1.0; if ($homeGuestStrengthDiff <= -20) { // if much stronger, they dislike it $popFactor = 0.95; } else { if ($homeGuestStrengthDiff >= 20) { // if much weaker, they like it! it is an achievement $popFactor = 1.05; } } $guestColumns['highscore'] = max(0, $guestUser['highscore'] + $highscoreDraw); $guestColumns['fanbeliebtheit'] = min(100, round($guestUser['popularity'] * $popFactor)); } else { $guestColumns['highscore'] = max(0, $guestUser['highscore'] + $highscoreLoss); // fans react on strength difference. $popFactor = 0.95; if ($homeGuestStrengthDiff <= -20) { // if much stronger, they dislike it even more $popFactor = 0.9; } else { if ($homeGuestStrengthDiff >= 20) { // if much weaker, it is ok for them $popFactor = 1.0; } } $guestColumns['fanbeliebtheit'] = max(1, round($guestUser['popularity'] * $popFactor)); } } if (!$match->guestTeam->isManagedByInterimManager) { $this->_db->queryUpdate($guestColumns, $updateTable, $updateCondition, $guestUser['u_id']); } // send notification about soon ending contracts if (isset($this->_teamsWithSoonEndingContracts[$match->guestTeam->id])) { $this->notifyAboutSoonEndingContracts($guestUser['u_id'], $match->guestTeam->id); } } }
public static function awardUserForTrades(WebSoccer $websoccer, DbConnection $db, $userId) { // count transactions of users $result = $db->querySelect('COUNT(*) AS hits', $websoccer->getConfig('db_prefix') . '_transfer', 'buyer_user_id = %d OR seller_user_id = %d', array($userId, $userId)); $transactions = $result->fetch_array(); $result->free(); if (!$transactions || !$transactions['hits']) { return; } BadgesDataService::awardBadgeIfApplicable($websoccer, $db, $userId, 'x_trades', $transactions['hits']); }