/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); // check if feature is enabled $exchangeRate = (int) $this->_websoccer->getConfig("premium_exchangerate_gamecurrency"); if ($exchangeRate <= 0) { throw new Exception("featue is disabled!"); } // check if user has a club. $clubId = $user->getClubId($this->_websoccer, $this->_db); if (!$clubId) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } // check if balance is enough $amount = $parameters["amount"]; $balance = $user->premiumBalance; if ($balance < $amount) { throw new Exception($this->_i18n->getMessage("premium-exchange_err_balancenotenough")); } // validation only: redirect to confirmation page if ($parameters["validateonly"]) { return "premium-exchange-confirm"; } // credit amount on team account BankAccountDataService::creditAmount($this->_websoccer, $this->_db, $clubId, $amount * $exchangeRate, "premium-exchange_team_subject", $user->username); // debit premium amount PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $amount, "exchange-premium"); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("premium-exchange_success"), "")); return "premiumaccount"; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if ($teamId < 1) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } if (TrainingDataService::countRemainingTrainingUnits($this->_websoccer, $this->_db, $teamId)) { throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_existing_units")); } // trainer info $trainer = TrainingDataService::getTrainerById($this->_websoccer, $this->_db, $parameters["id"]); if (!isset($trainer["id"])) { throw new Exception("invalid ID"); } // can team afford it? $numberOfUnits = (int) $parameters["units"]; $totalCosts = $numberOfUnits * $trainer["salary"]; $teamInfo = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); if ($teamInfo["team_budget"] <= $totalCosts) { throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_too_expensive")); } // try to debit premium fee if ($trainer['premiumfee']) { PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $trainer['premiumfee'], "choose-trainer"); } // debit money BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "training_trainer_salary_subject", $trainer["name"]); // create new units $columns["team_id"] = $teamId; $columns["trainer_id"] = $trainer["id"]; $fromTable = $this->_websoccer->getConfig("db_prefix") . "_training_unit"; for ($unitNo = 1; $unitNo <= $numberOfUnits; $unitNo++) { $this->_db->queryInsert($columns, $fromTable); } // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("saved_message_title"), "")); // redirect to training overview return "training"; }
/** * (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"; }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $buildingId = $parameters['id']; $user = $this->_websoccer->getUser(); $teamId = $user->getClubId($this->_websoccer, $this->_db); if (!$teamId) { throw new Exception($this->_i18n->getMessage("feature_requires_team")); } $dbPrefix = $this->_websoccer->getConfig('db_prefix'); $result = $this->_db->querySelect('*', $dbPrefix . '_stadiumbuilding', 'id = %d', $buildingId); $building = $result->fetch_array(); $result->free(); if (!$building) { // no i18n required since this should actually not happen if used properly. throw new Exception('illegal building.'); } // check budget $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId); if ($team['team_budget'] <= $building['costs']) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_too_expensive')); } // check if already exists in team $result = $this->_db->querySelect('*', $dbPrefix . '_buildings_of_team', 'team_id = %d AND building_id = %d', array($teamId, $buildingId)); $buildingExists = $result->fetch_array(); $result->free(); if ($buildingExists) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_already_exists')); } // check required building if ($building['required_building_id']) { $result = $this->_db->querySelect('*', $dbPrefix . '_buildings_of_team', 'team_id = %d AND building_id = %d', array($teamId, $building['required_building_id'])); $requiredBuildingExists = $result->fetch_array(); $result->free(); if (!$requiredBuildingExists) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_requires_building')); } } // check premium costs if ($building['premiumfee'] > $user->premiumBalance) { throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_premium_balance')); } // withdraw costs BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $building['costs'], 'building_construction_fee_subject', $building['name']); // place order $constructionDeadline = $this->_websoccer->getNowAsTimestamp() + $building['construction_time_days'] * 24 * 3600; $this->_db->queryInsert(array('building_id' => $buildingId, 'team_id' => $teamId, 'construction_deadline' => $constructionDeadline), $dbPrefix . '_buildings_of_team'); // withdraw premium fee if ($building['premiumfee']) { PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $building['premiumfee'], "order-building"); } // credit fan popularity change if ($building['effect_fanpopularity'] != 0) { $result = $this->_db->querySelect('fanbeliebtheit', $dbPrefix . '_user', 'id = %d', $user->id, 1); $userinfo = $result->fetch_array(); $result->free(); $popularity = min(100, max(1, $building['effect_fanpopularity'] + $userinfo['fanbeliebtheit'])); $this->_db->queryUpdate(array('fanbeliebtheit' => $popularity), $dbPrefix . '_user', 'id = %d', $user->id); } // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadiumenvironment_build_success"), "")); return null; }
private static function _handlePremiumAction(WebSoccer $website, DbConnection $db, I18n $i18n, $actionId, $creditsRequired, $validatedParams, $controllerName) { // check if user has enough credit if ($creditsRequired > $website->getUser()->premiumBalance) { $targetPage = $website->getConfig('premium_infopage'); // redirect to external info page if (filter_var($targetPage, FILTER_VALIDATE_URL)) { header('location: ' . $targetPage); exit; // render info page } else { $website->addContextParameter('premium_balance_required', $creditsRequired); return $targetPage; } } // debit amount and execute action if ($website->getRequestParameter('premiumconfirmed')) { PremiumDataService::debitAmount($website, $db, $website->getUser()->id, $creditsRequired, $actionId); return self::_executeAction($website, $db, $i18n, $actionId, $controllerName, $validatedParams); } // redirect to confirmation page $website->addContextParameter('premium_balance_required', $creditsRequired); $website->addContextParameter('actionparameters', $validatedParams); $website->addContextParameter('actionid', $actionId); $website->addContextParameter('srcpage', $website->getPageId()); return 'premium-confirm-action'; }