Beispiel #1
0
 public function deleteFootballerFromStore(Footballer $footballer)
 {
     if ($footballer->getIsFriend()) {
         $sql_template = "DELETE FROM footballers_friends WHERE owner_vk_id = '%s' AND vk_id = %d";
         $sql = sprintf($sql_template, UserParameters::getUserId(), $footballer->getId());
         RAM::getInstance()->deleteFootballerFriend($footballer->getId());
     } else {
         $sql_template = "DELETE FROM footballers WHERE owner_vk_id = '%s' AND footballer_id = %d";
         $sql = sprintf($sql_template, UserParameters::getUserId(), $footballer->getId());
         RAM::getInstance()->deleteFootballer($footballer->getId(), UserParameters::getUserId());
     }
     $SQLresult = SQL::getInstance()->query($sql);
     if ($SQLresult instanceof ErrorPoint) {
         return $SQLresult;
     }
     unset($this->footballers[$footballer->getId()]);
 }
 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;
 }
Beispiel #3
0
 function setFootballerFriend(Footballer $object, $inTeam = null, $indexInRAM = null)
 {
     if (!$this->isRAMEnabled) {
         return null;
     }
     if (is_null($inTeam) || is_null($indexInRAM)) {
         $linkName = $this->get(RAM::RAM_TYPE_FOOTBALLER_FRIEND . "_" . $object->getId());
         //  $linkName = $linkName->linkInRAM;
     } else {
         $linkName = RAM::RAM_TYPE_FOOTBALLER_FRIEND . "_" . $inTeam . "_" . $indexInRAM;
         $result = $this->set(RAM::RAM_TYPE_FOOTBALLER_FRIEND . "_" . $object->getId(), $linkName);
     }
     $result = $this->set($linkName, $object);
     if ($result === false) {
         return new ErrorPoint(ErrorPoint::CODE_RAM, "Невозможно записать данные футболисте в память", ErrorPoint::TYPE_SYSTEM);
     }
     return $result;
 }
 public static function footballer(Footballer $footballerInstance)
 {
     $footballer = array("id" => $footballerInstance->getId(), "footballerName" => $footballerInstance->getFootballerName(), "level" => $footballerInstance->getLevel(), "type" => $footballerInstance->getType(), "isFriend" => $footballerInstance->getIsFriend(), "isActive" => $footballerInstance->getIsActive(), "photoForFriend" => $footballerInstance->getPhotoForFriend(), "year" => $footballerInstance->getYear(), "country" => $footballerInstance->getCountry(), "team_name" => $footballerInstance->getTeamName(), "favorite" => $footballerInstance->getIsSuper(), "healthDown" => $footballerInstance->getHealthDown());
     return $footballer;
 }