コード例 #1
0
 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;
 }
コード例 #2
0
 public static function getFromStoreByIds($ids)
 {
     if (empty($ids)) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Переданы пустые ID для спонсоров", ErrorPoint::TYPE_SYSTEM);
     }
     $sponsorsStore = array();
     foreach ($ids as $IdVar => $Id) {
         $sponsor = RAM::getInstance()->getSponsorPrototypeById($Id);
         if (empty($sponsor)) {
             $sponsor = SponsorSatellite::getSponsorPrototype($Id);
             if ($sponsor instanceof ErrorPoint) {
                 return $sponsor;
             }
             RAM::getInstance()->setSponsorPrototype($sponsor);
         }
         $sponsorsStore[] = $sponsor;
     }
     return $sponsorsStore;
 }
コード例 #3
0
 public function action()
 {
     SQL::getInstance()->autocommit(false);
     $actionResult = SponsorSatellite::erase();
     /*
             $sponsorsStoreInRAM = RAM::getInstance()->getObjectsForTeam(UserParameters::getUserId(), RAM::RAM_TYPE_SPONSOR);
             foreach ($sponsorsStoreInRAM as $sponsorInstance){
                 RAM::getInstance()->deleteSponsor($sponsorInstance->getId(), UserParameters::getUserId());
             }
     */
     track_stats();
     // Отслеживаем производительность
     $energyRate = 1;
     $sponsorsStore = array();
     $actionResult = NULL;
     if (!is_object($this->parameters) && !is_array($this->parameters)) {
         $this->parameters = str_replace('\\\\"', '', $this->parameters);
         $this->parameters = str_replace(']\\"', ']', $this->parameters);
         $this->parameters = str_replace('\\"[', '[', $this->parameters);
         $this->parameters = json_decode($this->parameters);
     }
     track_stats();
     // Отслеживаем производительность
     if (!Utils::isEmpty($this->parameters) && !$actionResult instanceof ErrorPoint) {
         $sponsorDBResult = SponsorSatellite::getFromStoreByIds($this->parameters);
         $sponsorCount = count($sponsorDBResult);
         track_stats();
         // Отслеживаем производительность
         if ($sponsorDBResult instanceof ErrorPoint) {
             $actionResult = $sponsorDBResult;
         } elseif ($sponsorCount) {
             if ($sponsorCount > GlobalParameters::SPONSORS_LIMIT) {
                 $actionResult = new ErrorPoint(ErrorPoint::CODE_LOGIC, "Количество спонсоров превышет допустимый предел. Получено " . $sponsorCount . " спонсоров ", ErrorPoint::TYPE_SYSTEM);
             } else {
                 track_stats();
                 // Отслеживаем производительность
                 foreach ($sponsorDBResult as $sponsor) {
                     $sponsorInstance = new Sponsor();
                     $sponsorInstance->initFromParameters($sponsor);
                     if ($sponsorInstance->getRequiredLevel() > $this->teamProfile->getLevel()) {
                         $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Спонсор не доступен по уровню. Уровень спонсора: " . $sponsorInstance->getRequiredLevel() . ", а у вас " . intval($this->teamProfile->getLevel()), ErrorPoint::TYPE_USER);
                         break;
                     }
                     $actionResult = $sponsorInstance->save();
                     if ($actionResult instanceof ErrorPoint) {
                         break;
                     }
                     $energyRate *= $sponsorInstance->getEnergy();
                     $sponsorsStore[] = $sponsorInstance;
                 }
                 track_stats();
                 // Отслеживаем производительность
             }
         }
     }
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     if ($energyRate < 1) {
         $energyRate = 1;
     }
     track_stats();
     // Отслеживаем производительность
     $this->teamProfile->setSponsorRate($energyRate);
     $this->teamProfile->setMaxEnergy($energyRate * LevelsGrid::getInstance()->getBaseEnergy($this->teamProfile->getLevel()));
     $this->teamProfile->bindSponsors($sponsorsStore);
     $actionResult = $this->teamProfile->save();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
コード例 #4
0
ファイル: Team.php プロジェクト: rootree/vk-footboller-server
 public function initById($userId)
 {
     $this->socialUserId = intval($userId);
     if (!$this->socialUserId) {
         return new ErrorPoint(ErrorPoint::CODE_VK, "Не получен номер команды", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     $teamInstance = RAM::getInstance()->getTeamById($this->socialUserId);
     track_stats();
     // Отслеживаем производительность
     if (empty($teamInstance)) {
         //} || GlobalParameters::$IS_FAKE_ENTER || GlobalParameters::MODER_ID == $userId){
         $sql_template = "SELECT *, unix_timestamp(tour_bonus_time) as tour_bonus_time FROM teams WHERE vk_id = %s";
         $sql = sprintf($sql_template, $this->socialUserId);
         $result = SQL::getInstance()->query($sql);
         if ($result instanceof ErrorPoint) {
             return $result;
         }
         track_stats();
         // Отслеживаем производительность
         if ($result->num_rows) {
             $loadedTeam = $result->fetch_object();
             $this->isInstalled = 1;
             $this->initFromDB($loadedTeam);
             track_stats();
             // Отслеживаем производительность
             $this->footballers = FootballerSatellite::initForTeam($this);
             if ($this->footballers instanceof ErrorPoint) {
                 return $this->footballers;
             }
             track_stats();
             // Отслеживаем производительность
             $this->sponsors = SponsorSatellite::initForTeam($this);
             if ($this->sponsors instanceof ErrorPoint) {
                 return $this->sponsors;
             }
             return true;
         } else {
             if (GlobalParameters::getCommand() != COMMAND_PING && GlobalParameters::getCommand() != COMMAND_FRIEND_INFO && GlobalParameters::getCommand() != COMMAND_SYSTEM && GlobalParameters::getCommand() != COMMAND_WELCOME) {
                 // Utils::forDebug("Не найдена команда по ID#" . $this->socialUserId . " " . $sql);
                 return false;
                 return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Не найдена команда по ID#" . $this->socialUserId, ErrorPoint::TYPE_SYSTEM);
             } else {
                 $this->inTeam = 0;
                 return false;
             }
         }
     } else {
         $this->initFromRAM($teamInstance);
         $this->isInstalled = 1;
         track_stats();
         // Отслеживаем производительность
         $this->footballers = FootballerSatellite::initForTeam($this);
         if ($this->footballers instanceof ErrorPoint) {
             return $this->footballers;
         }
         track_stats();
         // Отслеживаем производительность
         $this->sponsors = SponsorSatellite::initForTeam($this);
         if ($this->sponsors instanceof ErrorPoint) {
             return $this->sponsors;
         }
         track_stats();
         // Отслеживаем производительность
         return true;
     }
 }