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; }
function setSponsor(Sponsor $object, $inTeam, $indexInRAM = null) { if (!$this->isRAMEnabled) { return null; } if (is_null($indexInRAM)) { $linkName = $this->get(RAM::RAM_TYPE_SPONSOR . "_" . $inTeam . "_" . $object->getId()); } else { $linkName = RAM::RAM_TYPE_SPONSOR . "_" . $inTeam . "_" . $indexInRAM; $result = $this->set(RAM::RAM_TYPE_SPONSOR . "_" . $inTeam . "_" . $object->getId(), $linkName); } $result = $this->set($linkName, $object); return $result; }