public static function initForTeam(&$team)
 {
     $sponsorsStore = array();
     $sponsorRate = 1;
     $sponsorsStore = RAM::getInstance()->getObjectsForTeam($team->getSocialUserId(), RAM::RAM_TYPE_SPONSOR);
     if (count($sponsorsStore) != $team->getSponsorsCount() || $team->getSponsorsCount() == 0) {
         //] || GlobalParameters::$IS_FAKE_ENTER
         // || GlobalParameters::MODER_ID == $team->getSocialUserId()){
         $sponsorsStore = array();
         $sql_template = "SELECT\n    item_sponsors.id,\n    item_sponsors.energy,\n    item_sponsors.required_level\nFROM sponsors\nLEFT JOIN item_sponsors ON item_sponsors.id = sponsors.sponsor_id\nWHERE vk_id = '%s'";
         $sql = sprintf($sql_template, $team->getSocialUserId());
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         $team->setSponsorsCount($SQLresult->num_rows, true);
         if ($SQLresult->num_rows) {
             $counter = 0;
             while ($sponsor = $SQLresult->fetch_object()) {
                 $sponsorInstance = new Sponsor();
                 $sponsorInstance->initFromParameters($sponsor);
                 $sponsorRate *= $sponsorInstance->getEnergy();
                 $sponsorsStore[$sponsorInstance->getId()] = $sponsorInstance;
                 RAM::getInstance()->setSponsor($sponsorInstance, $team->getSocialUserId(), $counter);
                 $counter++;
             }
             if (count($sponsorsStore) > GlobalParameters::SPONSORS_LIMIT) {
                 return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Количество спонсоров превышет допустимого значения " . count($sponsorsStore) . " - " . $SQLresult->num_rows, ErrorPoint::TYPE_SYSTEM);
             }
             $team->setSponsorRate($sponsorRate);
             $team->setMaxEnergy($sponsorRate * LevelsGrid::getInstance()->getBaseEnergy($team->getLevel()));
         }
     } else {
         foreach ($sponsorsStore as $sponsorInstance) {
             $sponsorRate *= $sponsorInstance->getEnergy();
         }
     }
     return $sponsorsStore;
 }
 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;
 }