public function action() { $team = new Team(); $team->initById($this->parameters->teamId); $teamInJSON = JSONPrepare::team($team); $teamInJSON["footballers"] = JSONPrepare::footballers(FootballerSatellite::initForTeam($team)); $teamInJSON["sponsors"] = JSONPrepare::sponsors(SponsorSatellite::initForTeam($team)); $this->result['team'] = $teamInJSON; }
private function install($teamParam) { $team = json_decode($teamParam); /*if(empty($team)){ return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Информация о команде получена неполностью, повторите попытку", ErrorPoint::TYPE_USER, $teamParam); }*/ track_stats(); // Отслеживаем производительность $actionResult = $this->teamProfile->initById(UserParameters::getUserId()); if ($actionResult instanceof ErrorPoint) { return $actionResult; } if ($actionResult === true) { return; } SQL::getInstance()->autocommit(false); $addOnStudyPoints = 0; $this->teamProfile->setTeamName(isset($team->teamName) ? $team->teamName : "Футболлер"); $this->teamProfile->setTeamLogoId(isset($team->teamLogoId) ? $team->teamLogoId : "42326"); $this->teamProfile->setUserPhoto($this->parameters->userPhoto); $this->teamProfile->setUserName($this->parameters->userName); $this->teamProfile->setUserYear(isset($this->parameters->userYear) ? intval($this->parameters->userYear) : 0); $this->teamProfile->setUserCountry(isset($this->parameters->userCountry) ? intval($this->parameters->userCountry) : 0); $this->teamProfile->setParameterForward(0); $this->teamProfile->setParameterHalf(0); $this->teamProfile->setParameterSafe(0); $this->teamProfile->setInGroup(0); $installResult = $this->teamProfile->install(); track_stats(); // Отслеживаем производительность if ($installResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } if ($addOnStudyPoints > GlobalParameters::MAX_TEAM) { SQL::getInstance()->rollback(); return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Друзей в команду набрано больше чем допустимо", ErrorPoint::TYPE_USER); } $needRandomFootballers = GlobalParameters::MAX_TEAM - $addOnStudyPoints; track_stats(); // Отслеживаем производительность if ($needRandomFootballers) { $prototypes = FootballerSatellite::getRandomPrototypes($needRandomFootballers); if ($prototypes instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $prototypes; } foreach ($prototypes as $footballerPrototype) { $footballer = new Footballer(); $actionResult = $footballer->add($footballerPrototype, $needRandomFootballers--); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } $this->teamProfile->addFootballerToStore($footballer); } } track_stats(); // Отслеживаем производительность $this->teamProfile->updateTeamParameters(); $addOnStudyPoints += 5; // Дадим ещё немного очков, для заманухи $this->teamProfile->setStudyPoints($addOnStudyPoints); $installResult = $this->teamProfile->save(); track_stats(); // Отслеживаем производительность if ($installResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } else { SQL::getInstance()->commit(); } /* $getResult = $this->teamProfile->initById(UserParameters::getUserId()); if($getResult instanceof ErrorPoint){ SQL::getInstance()->rollback(); return $actionResult; } */ track_stats(); // Отслеживаем производительность $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED); $api->setStatus(UserParameters::getUserId(), sprintf(VK_APPLICATION_STATUS, $this->teamProfile->getTeamName())); track_stats(); // Отслеживаем производительность return $installResult; }
public function action() { $friendId = intval($this->parameters->friendId); if (empty($friendId)) { $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Получен не правильный номер друга", ErrorPoint::TYPE_USER); return $actionResult; } track_stats(); // Отслеживаем производительность $alreadyExists = $this->teamProfile->getFootballerById($friendId); if ($alreadyExists) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже играет за вас", ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность $actionResult = FootballerSatellite::getFootballerOwner($friendId); if ($actionResult instanceof ErrorPoint) { return $actionResult; } if ($actionResult !== false) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже числиться в другом футбольном клубе", ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность SQL::getInstance()->autocommit(false); $friendFootballer = new Footballer(); $actionResult = $friendFootballer->addFriend($friendId, NULL, $this->teamProfile->getActiveCount()); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность $addonPoints = 0; if (TeamSatellite::isFreshFriend($friendId)) { // Даються очьку обучения как среднее по всех футболистов if (count($this->teamProfile->getFootballers()) != 0) { $addonPoints = floor($this->teamProfile->getFootballerSumLevel() / count($this->teamProfile->getFootballers())); $this->teamProfile->setStudyPoints($this->teamProfile->getStudyPoints() + $addonPoints); $actionResult = $this->teamProfile->save(); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } } } track_stats(); // Отслеживаем производительность $actionResult = Team::markTeamAsSelected($friendId); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersFriendsCount', $this->teamProfile->getAllFootballersFriendsCount() + 1); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); } else { SQL::getInstance()->commit(); $this->result['footballer'] = $friendFootballer; $this->result['addonStadyPoints'] = $addonPoints; $this->result['totalStadyPoints'] = $this->teamProfile->getStudyPoints(); } track_stats(); // Отслеживаем производительность return $actionResult; }
public function getCoach() { if (empty($this->coach)) { $shopItemInDB = FootballerSatellite::getFromStoreById($this->getTrainerId(), TYPE_FOOTBALLER_TEAMLEAD_CODE); if ($shopItemInDB instanceof ErrorPoint) { return $shopItemInDB; } $this->coach = new TrainerPrototype($shopItemInDB); } return $this->coach; }
public function action() { $actionResult = NULL; track_stats(); // Отслеживаем производительность $shopItemInDB = FootballerSatellite::getFromStoreById($this->parameters->peopleId, $this->parameters->line); if ($shopItemInDB instanceof ErrorPoint) { return $shopItemInDB; } if (isset($this->parameters->line) && $this->parameters->line == TYPE_FOOTBALLER_TEAMLEAD_CODE) { $structure = new TrainerPrototype($shopItemInDB); } else { $structure = new FootballerPrototype(); $structure->init($shopItemInDB, $this->parameters); } track_stats(); // Отслеживаем производительность if ($this->parameters->isInGame && $structure->getRequiredLevel() > $this->teamProfile->getLevel()) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Для соверщения этой операции недостаточно уровня. У пользователя " . $this->teamProfile->getLevel() . " а надо " . $structure->getRequiredLevel(), ErrorPoint::TYPE_USER); } $tourBonus = 1; if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() > time()) { $tourBonus = $this->teamProfile->getTourBonus(); $tourBonus -= 1; $tourBonus = 1 - $tourBonus; } track_stats(); // Отслеживаем производительность if ($tourBonus == 0) { $tourBonus = 1; } if ($this->parameters->isInGame) { if ($structure->getPrice() * $tourBonus > $this->teamProfile->getMoney()) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER); } } else { if ($structure->getRealPrice() * $tourBonus > $this->teamProfile->getRealMoney()) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER); } } track_stats(); // Отслеживаем производительность SQL::getInstance()->autocommit(false); if ($structure instanceof TrainerPrototype) { $this->teamProfile->setTrainer($structure->getId()); track_stats(); // Отслеживаем производительность } else { if ($this->teamProfile->getFootballerById($structure->getId())) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Данный футболист уже в вашем клубе", ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность $footballerInstance = new Footballer(); $actionResult = $footballerInstance->add($structure, $this->teamProfile->getActiveCount()); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность if ($footballerInstance->getIsActive()) { switch ($footballerInstance->getType()) { case TYPE_FOOTBALLER_FORWARD_CODE: $this->teamProfile->setParameterForward($this->teamProfile->getParameterForward() + $footballerInstance->getLevel()); break; case TYPE_FOOTBALLER_SAFER_CODE: case TYPE_FOOTBALLER_GOALKEEPER_CODE: $this->teamProfile->setParameterSafe($this->teamProfile->getParameterSafe() + $footballerInstance->getLevel()); break; case TYPE_FOOTBALLER_HALFSAFER_CODE: $this->teamProfile->setParameterHalf($this->teamProfile->getParameterHalf() + $footballerInstance->getLevel()); break; } } $this->result['isActive'] = $footballerInstance->getIsActive(); $this->result['teamParameters'] = array("Forward" => $this->teamProfile->getParameterForward(), "Safe" => $this->teamProfile->getParameterSafe(), "Half" => $this->teamProfile->getParameterHalf()); $this->teamProfile->addFootballerToStore($footballerInstance); track_stats(); // Отслеживаем производительность } if ($this->parameters->isInGame) { $this->teamProfile->setMoney($this->teamProfile->getMoney() - $structure->getPrice() * $tourBonus); } else { $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() - $structure->getRealPrice() * $tourBonus); } $actionResult = $this->teamProfile->save(); track_stats(); // Отслеживаем производительность RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersCount', $this->teamProfile->getAllFootballersCount() + 1); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); } else { SQL::getInstance()->commit(); } track_stats(); // Отслеживаем производительность return $actionResult; }
public static function initForTeam(Team &$team, $isGetOnlyActive = false) { $teamId = $team->getSocialUserId(); $store = array(); track_stats(); // Отслеживаем производительность $footballersStore = RAM::getInstance()->getObjectsForTeam($teamId, RAM::RAM_TYPE_FOOTBALLER); track_stats(); // Отслеживаем производительность $activeFootballer = 0; // Utils::forDebug(count($footballersStore) . " == " . $team->getAllFootballersCount()); if (count($footballersStore) != $team->getAllFootballersCount() || $team->getAllFootballersCount() == 0) { //} || GlobalParameters::$IS_FAKE_ENTER || GlobalParameters::MODER_ID == $teamId){ $sql_template = "SELECT\n footballers.level,\n footballers.footballer_id,\n footballers.is_active,\n footballers.super,\n footballers.health_down,\n item_footballers.line as type FROM footballers\nLEFT JOIN item_footballers ON item_footballers.id = footballers.footballer_id\nWHERE footballers.owner_vk_id = %d " . ($isGetOnlyActive ? " AND footballers.is_active = 1 " : "") . " ORDER BY item_footballers.line DESC "; $sql_template = "SELECT\n footballers.level,\n footballers.footballer_id,\n footballers.is_active,\n footballers.super,\n footballers.health_down,\n item_footballers.line AS typer FROM footballers, item_footballers\nWHERE footballers.owner_vk_id = %d " . ($isGetOnlyActive ? " AND footballers.is_active = 1 " : "") . " AND item_footballers.id = footballers.footballer_id ORDER BY item_footballers.line ASC"; $sql = sprintf($sql_template, intval($teamId)); $SQLresult = SQL::getInstance()->query($sql); track_stats(); // Отслеживаем производительность if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } track_stats(); // Отслеживаем производительность $team->setAllFootballersCount($SQLresult->num_rows, true); $counter = 0; $footballersStore = array(); while ($footballer = $SQLresult->fetch_object()) { $footballerInstance = new Footballer(); $footballerInstance->initFromParameters($footballer, false, $teamId, $sql); $footballersStore[$footballerInstance->getId()] = $footballerInstance; if ($footballerInstance->getIsActive() == 1) { $activeFootballer++; } //RAM::getInstance()->setFootballer($footballerInstance, $teamId, $counter); $counter++; } track_stats(); // Отслеживаем производительность } else { track_stats(); // Отслеживаем производительность $footballersStore = array(); if ($isGetOnlyActive) { $footballersStoreTeam = $footballersStore; foreach ($footballersStoreTeam as $footballerInstance) { if ($footballerInstance->getIsActive() == 1) { $footballersStore[$footballerInstance->getId()] = $footballerInstance; } $footballerInstance->checkHealth(); } } else { $footballersStoreTeam = $footballersStore; foreach ($footballersStoreTeam as $footballerInstance) { if ($footballerInstance instanceof Footballer) { if ($footballerInstance instanceof Footballer && $footballerInstance->getIsActive() == 1) { $activeFootballer++; } $footballersStore[$footballerInstance->getId()] = $footballerInstance; $footballerInstance->checkHealth(); } } } track_stats(); // Отслеживаем производительность } track_stats(); // Отслеживаем производительность $footballersFriendStore = RAM::getInstance()->getObjectsForTeam($teamId, RAM::RAM_TYPE_FOOTBALLER_FRIEND); track_stats(); // Отслеживаем производительность if (count($footballersFriendStore) != $team->getAllFootballersFriendsCount() || $team->getAllFootballersFriendsCount() == 0) { $sql_template = "SELECT footballers_friends.*,\n teams.user_year,\n teams.user_country,\n teams.user_name,\n teams.user_photo,\n teams.in_team,\n owner_team.team_name\nFROM footballers_friends\nJOIN teams ON footballers_friends.vk_id = teams.vk_id\nLEFT JOIN teams AS owner_team ON owner_team.vk_id = footballers_friends.owner_vk_id\nWHERE owner_vk_id = '%s' " . ($isGetOnlyActive ? " AND is_active = 1 " : "") . " ORDER BY footballers_friends.type DESC"; $sql_template = "SELECT\n footballers_friends.vk_id,\n footballers_friends.level,\n footballers_friends.type as typer,\n footballers_friends.is_active,\n footballers_friends.super,\n footballers_friends.owner_vk_id,\n footballers_friends.health_down,\n teams.user_year,\n teams.user_country,\n teams.user_name,\n teams.user_photo,\n teams.in_team\nFROM footballers_friends\nJOIN teams ON footballers_friends.vk_id = teams.vk_id\nWHERE owner_vk_id = %d " . ($isGetOnlyActive ? " AND is_active = 1 " : "") . " ORDER BY footballers_friends.type DESC"; // ORDER BY footballers_friends.type DESC"; $sql = sprintf($sql_template, intval($teamId)); $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } $team->setAllFootballersFriendsCount($SQLresult->num_rows, true); track_stats(); // Отслеживаем производительность $footballersFriendStore = array(); $counter = 0; while ($footballer = $SQLresult->fetch_object()) { $footballerInstance = new Footballer(); $footballerInstance->initFromParameters($footballer, true, $teamId, $sql); $footballersFriendStore[$footballerInstance->getId()] = $footballerInstance; if ($footballerInstance->getIsActive() == 1) { $activeFootballer++; } //RAM::getInstance()->setFootballerFriend($footballerInstance, $teamId, $counter); $counter++; } track_stats(); // Отслеживаем производительность } else { track_stats(); // Отслеживаем производительность if ($isGetOnlyActive) { $footballersStoreTeam = $footballersFriendStore; $footballersFriendStore = array(); foreach ($footballersStoreTeam as $footballerInstance) { if ($footballerInstance->getIsActive() == 1) { $footballersFriendStore[] = $footballerInstance; } $footballerInstance->checkHealth(); } } else { foreach ($footballersFriendStore as $footballerInstance) { if ($footballerInstance->getIsActive() == 1) { $activeFootballer++; } $footballerInstance->checkHealth(); } } track_stats(); // Отслеживаем производительность } $store = array_merge($footballersStore, $footballersFriendStore); $returnStore = array(); foreach ($store as $footballerInstance) { if ($footballerInstance instanceof Footballer) { $returnStore[$footballerInstance->getId()] = $footballerInstance; } } track_stats(); // Отслеживаем производительность if ($activeFootballer > GlobalParameters::MAX_TEAM) { $actionResult = FootballerSatellite::bagoFixActiveFootballers($team, $returnStore); if ($actionResult instanceof ErrorPoint) { return $actionResult; } $returnStore = FootballerSatellite::initForTeam($team); // return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Количество активных игроков превышет допустимого значения. Разрешено ". // GlobalParameters::MAX_TEAM . " а у игрока " . $activeFootballer, ErrorPoint::TYPE_SYSTEM); } track_stats(); // Отслеживаем производительность return $returnStore; }
public function action() { track_stats(); // Отслеживаем производительность $actionResult = NULL; $sellId = intval($this->parameters->footballerId); $footballerInstance = $this->teamProfile->getFootballerById($sellId); if ($footballerInstance === false) { $errorMessage = "Анулирование контракта невозможно"; // Utils::forDebug($errorMessage . " sellId : $sellId - UserId : " . $this->teamProfile->getSocialUserId()); return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Анулирование контракта невозможно", ErrorPoint::TYPE_USER); } if ($footballerInstance->getIsActive()) { switch ($footballerInstance->getType()) { case TYPE_FOOTBALLER_FORWARD_CODE: $this->teamProfile->setParameterForward($this->teamProfile->getParameterForward() - $footballerInstance->getLevel()); break; case TYPE_FOOTBALLER_SAFER_CODE: case TYPE_FOOTBALLER_GOALKEEPER_CODE: $this->teamProfile->setParameterSafe($this->teamProfile->getParameterSafe() - $footballerInstance->getLevel()); break; case TYPE_FOOTBALLER_HALFSAFER_CODE: $this->teamProfile->setParameterHalf($this->teamProfile->getParameterHalf() - $footballerInstance->getLevel()); break; } } track_stats(); // Отслеживаем производительность $this->result['teamParameters'] = array("Forward" => $this->teamProfile->getParameterForward(), "Safe" => $this->teamProfile->getParameterSafe(), "Half" => $this->teamProfile->getParameterHalf()); track_stats(); // Отслеживаем производительность SQL::getInstance()->autocommit(false); track_stats(); // Отслеживаем производительность $deleteResult = $this->teamProfile->deleteFootballerFromStore($footballerInstance); if ($deleteResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $deleteResult; } track_stats(); // Отслеживаем производительность if ($footballerInstance->getIsFriend()) { $markAsFreeResult = TeamSatellite::markFriendAsFree($footballerInstance->getId(), $free = true); if ($markAsFreeResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $markAsFreeResult; } } track_stats(); // Отслеживаем производительность $footballerPrice = FootballerSatellite::detectPrice($footballerInstance, $this->teamProfile->getStudyPointCost()); $footballerPrice = $footballerInstance->getIsSuper() ? $footballerPrice * 3 : $footballerPrice; $footballerPrice *= 0.25; track_stats(); // Отслеживаем производительность $tourBonus = 1; if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() > time()) { $tourBonus = $this->teamProfile->getTourBonus(); $tourBonus -= 1; $tourBonus = 1 - $tourBonus; } if ($tourBonus == 0) { $tourBonus = 1; } track_stats(); // Отслеживаем производительность $footballerPrice = $footballerPrice * $tourBonus; $this->teamProfile->setMoney($this->teamProfile->getMoney() + $footballerPrice); $actionResult = $this->teamProfile->save(); track_stats(); // Отслеживаем производительность if ($footballerInstance->getIsFriend()) { RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersFriendsCount', $this->teamProfile->getAllFootballersFriendsCount() - 1); } else { RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersCount', $this->teamProfile->getAllFootballersCount() - 1); } track_stats(); // Отслеживаем производительность if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); } else { SQL::getInstance()->commit(); } track_stats(); // Отслеживаем производительность return $actionResult; }