public static function footballers($footballers) { $forJSON = array(); foreach ($footballers as $footballerInstance) { $footballer = JSONPrepare::footballer($footballerInstance); $forJSON[] = $footballer; } return $forJSON; }
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; }
public function action() { $this->result['teams'] = array(); track_stats(); // Отслеживаем производительность $sql_template = "SELECT\n *, unix_timestamp(tour_bonus_time) as tour_bonus_time \n FROM teams\n WHERE \n%d < param_sum AND param_sum < %d AND MOD(vk_id, %d) = 0 AND able_to_choose = 1\n LIMIT 30"; $sql = sprintf($sql_template, $this->teamProfile->getParameterSum() - GlobalParameters::ENEMY_RANGE, $this->teamProfile->getParameterSum() + GlobalParameters::ENEMY_RANGE, rand(0, 29)); $teamResult = SQL::getInstance()->query($sql); if ($teamResult instanceof ErrorPoint) { return $teamResult; } track_stats(); // Отслеживаем производительность if ($teamResult->num_rows) { while ($teamObject = $teamResult->fetch_object()) { if (empty($teamObject->user_name) || $teamObject->vk_id == $this->teamProfile->getSocialUserId()) { continue; } $team = new Team(); $team->initFromDB($teamObject); $chnase = Utils::detectChanceOfWin($this->teamProfile, $team); $teamInJSON = JSONPrepare::team($team); $teamInJSON["score"] = md5($chnase . $team->getSocialUserId() . SECRET_KEY); $this->result['teams'][] = $teamInJSON; } track_stats(); // Отслеживаем производительность } else { $sql_template = "SELECT\n *, unix_timestamp(tour_bonus_time) as tour_bonus_time\nFROM teams\n WHERE\n%d < (param_sum) AND\n(param_sum) < %d AND\nMOD(vk_id, %d) = 0 and able_to_choose = 1\n LIMIT 30"; $sql = sprintf($sql_template, $this->teamProfile->getParameterSum() - GlobalParameters::ENEMY_RANGE * 3, $this->teamProfile->getParameterSum() + GlobalParameters::ENEMY_RANGE * 3, rand(0, 29)); $teamResult = SQL::getInstance()->query($sql); if ($teamResult instanceof ErrorPoint) { return $teamResult; } track_stats(); // Отслеживаем производительность if ($teamResult->num_rows) { while ($teamObject = $teamResult->fetch_object()) { if (empty($teamObject->user_name) || $teamObject->vk_id == $this->teamProfile->getSocialUserId()) { continue; } $team = new Team(); $team->initFromDB($teamObject); $teamInJSON = JSONPrepare::team($team); $chnase = Utils::detectChanceOfWin($this->teamProfile, $team); //$teamInJSON["score"] = Utils::detectChanceOfWin($this->teamProfile, $team); $teamInJSON["score"] = md5($chnase . $team->getSocialUserId() . SECRET_KEY); $this->result['teams'][] = $teamInJSON; } track_stats(); // Отслеживаем производительность } } }
public function getResult() { $this->result["teamProfiler"] = JSONPrepare::team($this->teamProfile); return $this->result; }
public function action() { $groupType = intval($this->parameters->groupType); $placerId = intval($this->parameters->placerId); if ($groupType == 0 || $groupType == TOUR_TYPE_VK && $placerId != 0) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ошибка в программе", ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность $sql_template = "SELECT vk_id, wins, ties, loses, score, group_number, in_play_off, tour_group_id FROM tour_groups WHERE was_closed = 0 and tour_type = %d and tour_placer_id = %d;"; $sql = sprintf($sql_template, $groupType, $placerId); $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } $group = array(); track_stats(); // Отслеживаем производительность if ($SQLresult->num_rows) { while ($teamObject = $SQLresult->fetch_object()) { $group[$teamObject->group_number][] = $teamObject; $team = new Team(); $team->initById($teamObject->vk_id); $teamInJSON = JSONPrepare::team($team); $this->result['teams'][] = $teamInJSON; if ($teamObject->vk_id == $this->teamProfile->getSocialUserId()) { $this->userInGroups = array($teamObject->tour_group_id, $teamObject->group_number); if ($teamObject->in_play_off) { $this->userInPlayOff = true; } } } } track_stats(); // Отслеживаем производительность $this->result['group'] = $group; $playOff = array(); $currentStep = 4; $playOff[$currentStep] = $this->getPlayOffByStep($currentStep, $groupType, $placerId); $currentStep--; $playOff[$currentStep] = $this->getPlayOffByStep($currentStep, $groupType, $placerId); $currentStep--; $playOff[$currentStep] = $this->getPlayOffByStep($currentStep, $groupType, $placerId); $currentStep--; $playOff[$currentStep] = $this->getPlayOffByStep($currentStep, $groupType, $placerId); $this->result['playOff'] = $playOff; track_stats(); // Отслеживаем производительность $this->result['groupSteps'] = array(); if ($this->userInGroups) { $sql_template = "SELECT finished, goals_enemy, goals, result, vk_id_enemy, vk_id, group_details_id FROM tour_groups_details WHERE tour_group_id = %d and vk_id = %d ORDER BY group_details_id ;"; $sql = sprintf($sql_template, $this->userInGroups[0], $this->teamProfile->getSocialUserId()); $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } $finishedCounter = 0; if ($SQLresult->num_rows) { while ($groupStepObject = $SQLresult->fetch_object()) { $this->result['groupSteps'][$groupStepObject->group_details_id] = $groupStepObject; $this->result['groupSteps'][$groupStepObject->group_details_id]->group_number = $this->userInGroups[1]; $finishedCounter += $groupStepObject->finished; } } if ($finishedCounter == 3) { $this->result['groupSteps'] = array(); } } track_stats(); // Отслеживаем производительность $this->result['playOffSteps'] = array(); if ($this->userInPlayOff) { $sql_template = "SELECT vk_id_enemy, result, goals, goals_enemy, finished, play_off_step, play_off_id FROM tour_play_off WHERE vk_id = %d and tour_type = %d and tour_placer_id = %d ORDER BY play_off_id ;"; $sql = sprintf($sql_template, $this->teamProfile->getSocialUserId(), $groupType, $placerId); $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } if ($SQLresult->num_rows) { while ($playOffStepObject = $SQLresult->fetch_object()) { $this->result['playOffSteps'][$playOffStepObject->play_off_step] = $playOffStepObject; } } } track_stats(); // Отслеживаем производительность }
public function getResult() { $this->result['isOk'] = 1; $this->result['footballer'] = JSONPrepare::footballer($this->result['footballer']); return $this->result; }
register_shutdown_function('shutdown'); set_error_handler("handlerError"); $userId = intval($_GET["userId"]); $authKey = @trim($_GET["authKey"]); $checkSum = @trim($_GET["checkSum"]); $serverCheckSum = md5($authKey . SECRET_KEY . $userId); if ($serverCheckSum != $checkSum) { $actionResult = new ErrorPoint(ErrorPoint::CODE_BAD_MD5, "WFT", ErrorPoint::TYPE_USER); } if (!in_array(getRealIP(), $allowIPForSystemCommand)) { $actionResult = new ErrorPoint(ErrorPoint::CODE_BAD_MD5, "WFT!: " . getRealIP(), ErrorPoint::TYPE_USER); } UserParameters::setUserId($userId); if (SQL::getInstance()->connect_error) { $actionResult = new ErrorPoint(ErrorPoint::CODE_SQL, "Невозможно подключиться (" . SQL::getInstance()->connect_error . ")", ErrorPoint::TYPE_SYSTEM); break; } echo '<?xml version="1.0"?> <userInfo>'; if (!array_key_exists("onlyProfile", $_GET)) { echo '<requests>'; getUsersActivity(); echo "</requests>"; } $team = new Team(); $team->initById(UserParameters::getUserId()); echo "<team><![CDATA[" . json_encode(JSONPrepare::team($team)) . "]]></team>"; echo "</userInfo>"; ob_end_flush(); ?>
public function update() { if ($this->teamId != UserParameters::getUserId()) { return new ErrorPoint(ErrorPoint::CODE_SECURITY, "Техническая ошибка", ErrorPoint::TYPE_SYSTEM); } if ($this->getIsFriend()) { $sql_template = "UPDATE footballers_friends SET\nlevel = %d,\nis_active = %d,\ntype = %d,\nsuper = %d,\nhealth_down = %d,\nlogger = '%s'\nWHERE\nowner_vk_id = %d AND\nvk_id = %d"; $sql = sprintf($sql_template, $this->getLevel(), $this->getIsActive(), $this->getType(), $this->getIsSuper(), $this->getHealthDown(), get_caller_method() . "\n\n" . json_encode(JSONPrepare::footballer($this)) . $this->teamId . "|" . UserParameters::getUserId() . $this->SQL, UserParameters::getUserId(), $this->getId()); /* $footballerInRAM = RAM::getInstance()->getFootballerFriendById($this->getId()); if($footballerInRAM === false){ $currentIndex = RAM::getInstance()->getMaxObjectIndexForTeam(UserParameters::getUserId(), RAM::RAM_TYPE_FOOTBALLER_FRIEND); RAM::getInstance()->setFootballerFriend($this, UserParameters::getUserId(), $currentIndex); }else{ RAM::getInstance()->setFootballerFriend($this); }*/ } else { $sql_template = "UPDATE footballers SET\nlevel = %d,\nis_active = %d,\nsuper = %d,\nhealth_down = %d,\nlogger = '%s'\nWHERE\nowner_vk_id = %d AND\nfootballer_id = %d"; $sql = sprintf($sql_template, $this->getLevel(), $this->getIsActive(), $this->getIsSuper(), $this->getHealthDown(), get_caller_method() . "\n\n" . json_encode(JSONPrepare::footballer($this)) . $this->teamId . "|" . UserParameters::getUserId() . $this->SQL, UserParameters::getUserId(), $this->getId()); /* $footballerInRAM = RAM::getInstance()->getFootballerById($this->getId(), UserParameters::getUserId()); if($footballerInRAM === false){ $currentIndex = RAM::getInstance()->getMaxObjectIndexForTeam(UserParameters::getUserId(), RAM::RAM_TYPE_FOOTBALLER);; RAM::getInstance()->setFootballer($this, UserParameters::getUserId(), $currentIndex); }else{ RAM::getInstance()->setFootballer($this, UserParameters::getUserId()); }*/ } $result = SQL::getInstance()->query($sql); if ($result instanceof ErrorPoint) { return $result; } }
public function action() { $this->result["isInstalled"] = $this->teamProfile->getIsInstalled(); track_stats(); // ќтслеживаем производительность $startAt = RAM::getInstance()->getTourStart(); $finishAt = RAM::getInstance()->getTourFinish(); track_stats(); // ќтслеживаем производительность if (empty($startAt) || empty($finishAt)) { $tourTimer = TourSatellite::getTimerDate(); $startAt = $tourTimer->startAt; $finishAt = $tourTimer->finishAt; RAM::getInstance()->setTourStart($startAt); RAM::getInstance()->setTourFinish($finishAt); } track_stats(); // ќтслеживаем производительность $this->result["tourStartAt"] = $startAt; $this->result["tourFinishedAt"] = $finishAt; $this->result["serverTime"] = time(); if ($this->teamProfile->getIsInstalled()) { track_stats(); // ќтслеживаем производительность $energyTimer = RAM::getInstance()->getEnergyLastUpdate(); if (empty($energyTimer)) { $energyTimer = filemtime(SYSTEM_LOGS . "/cron.updateEnergy.log"); // microtime RAM::getInstance()->setEnergyLastUpdate($energyTimer); } $this->result['energyTimer'] = $energyTimer; track_stats(); // ќтслеживаем производительность if ($this->teamProfile->isNeedDailyBonus()) { $dailyBonus = $this->teamProfile->getTotalStadiumBonus(); $this->teamProfile->setMoney($this->teamProfile->getMoney() + $dailyBonus); $actionResult = TeamSatellite::accrueDailyBonus(UserParameters::getUserId(), $this->teamProfile->getMoney()); if ($actionResult instanceof ErrorPoint) { return $actionResult; } } track_stats(); // ќтслеживаем производительность if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() == 0) { $finishBonusAt = time() + 1 * 24 * 60 * 60; $actionResult = TeamSatellite::startTourBonus(UserParameters::getUserId(), $finishBonusAt); if ($actionResult instanceof ErrorPoint) { return $actionResult; } $this->teamProfile->setTourBonusTime($finishBonusAt); } track_stats(); // ќтслеживаем производительность $this->result["teamInfo"] = JSONPrepare::team($this->teamProfile); track_stats(); // ќтслеживаем производительность // Ёто надо обновить после отдачи профайла if ($this->teamProfile->getTourNotify() == TOUR_NOTIFY_START || $this->teamProfile->getTourNotify() == TOUR_NOTIFY_NEW) { $actionResult = TeamSatellite::updateTourNotify(UserParameters::getUserId(), $this->teamProfile->getTourNotify() - 2); if ($actionResult instanceof ErrorPoint) { return $actionResult; } } track_stats(); // ќтслеживаем производительность if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() < time()) { $actionResult = TeamSatellite::eraseTourBonus(UserParameters::getUserId()); if ($actionResult instanceof ErrorPoint) { return $actionResult; } $this->teamProfile->setTourBonus(0); $this->teamProfile->setTourBonusTime(0); } track_stats(); // ќтслеживаем производительность if ($this->teamProfile->getStudyPointsViaPrize() > 0) { $actionResult = TeamSatellite::resetPrizeStudyPoint(UserParameters::getUserId()); if ($actionResult instanceof ErrorPoint) { return $actionResult; } } //Utils::forDebug($this->teamProfile); } }
public function action() { $detailId = 0; if (isset($this->parameters->detailId)) { $detailId = intval($this->parameters->detailId); } $typeTour = 0; if (isset($this->parameters->typeTour)) { $typeTour = intval($this->parameters->typeTour); } if ($this->teamProfile->getCurrentEnergy() < GlobalParameters::ENERGY_PER_MATCH) { return new ErrorPoint(ErrorPoint::CODE_SECURITY, "Для проведения новых матчей нужна энергия. На новый матч надо " . GlobalParameters::ENERGY_PER_MATCH, ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность $enemyTeam = new Team(); $actionResult = $enemyTeam->initById($this->parameters->enemyTeamId); if ($actionResult instanceof ErrorPoint) { return $actionResult; } track_stats(); // Отслеживаем производительность $isTourRun = isset($this->parameters->type) && $detailId && $typeTour; $this->result = JSONPrepare::footballers($enemyTeam->getFootballers()); track_stats(); // Отслеживаем производительность $this->result["healthDown"] = 0; $score1 = md5("1" . $this->parameters->enemyTeamId . SECRET_KEY); $score2 = md5("-1" . $this->parameters->enemyTeamId . SECRET_KEY); $score3 = md5("0" . $this->parameters->enemyTeamId . SECRET_KEY); $scoreTE = 0; $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH_TIE; $addonMoney = GlobalParameters::MONEY_PER_MATCH_TIE; switch ($this->parameters->score) { case $score1: $scoreTE = 1; if (1 == rand(1, 100) && $this->teamProfile->getLevel() > 3) { $this->result["healthDown"] = $this->healthDownFootballer(); } $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH; $addonMoney = GlobalParameters::MONEY_PER_MATCH; $this->teamProfile->increaseWonRating(); if (!$isTourRun) { $this->teamProfile->setTourIII($this->teamProfile->getTourIII() + 3); } break; case $score2: $scoreTE = -1; if (1 == rand(1, 30) && $this->teamProfile->getLevel() > 3) { $this->result["healthDown"] = $this->healthDownFootballer(); } $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH_LOSE; $addonMoney = GlobalParameters::MONEY_PER_MATCH_LOSE; $this->teamProfile->increaseLoseRating(); break; case $score3: if (1 == rand(1, 60) && $this->teamProfile->getLevel() > 5) { $this->result["healthDown"] = $this->healthDownFootballer(); } $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH_TIE; $addonMoney = GlobalParameters::MONEY_PER_MATCH_TIE; $this->teamProfile->increaseTieRating(); if (!$isTourRun) { $this->teamProfile->setTourIII($this->teamProfile->getTourIII() + 1); } break; } track_stats(); // Отслеживаем производительность $addonExperiance = $this->getAddOnXPorMoney($addonExperiance, $this->teamProfile->getLevel()); $addonMoney = $this->getAddOnXPorMoney($addonMoney, $this->teamProfile->getLevel(), 10); $stadiumMoney = 0; if ($this->teamProfile->getStadiumId() && 1 == rand(1, 10)) { $stadiumMoney = $addonMoney * ($scoreTE + 2); } $stadiumMoney = $stadiumMoney < 10000 ? $stadiumMoney : 0; $addonExperiance = $addonExperiance < 10000 ? $addonExperiance : 0; $addonMoney = $addonMoney < 10000 ? $addonMoney : 0; $this->teamProfile->setEnergy($this->teamProfile->getCurrentEnergy() - GlobalParameters::ENERGY_PER_MATCH); $this->teamProfile->addExperience($addonExperiance); $this->teamProfile->setMoney($this->teamProfile->getMoney() + $addonMoney + $stadiumMoney); $this->result["stadiumBonus"] = $stadiumMoney; $this->result["addonEx"] = $addonExperiance; $this->result["addonMoney"] = $addonMoney; $this->result["currentEnergy"] = $this->teamProfile->getCurrentEnergy(); $this->result["maxEnergy"] = $this->teamProfile->getEnergyMax(); $this->result["score"] = $scoreTE; $this->result["bonus"] = null; $this->result["bonusTime"] = null; $this->result["totalBonus"] = null; track_stats(); // Отслеживаем производительность $markAsFreeResult = TeamSatellite::increaseChooseRating($this->parameters->enemyTeamId); if ($markAsFreeResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $markAsFreeResult; } track_stats(); // Отслеживаем производительность if ($isTourRun) { $sql = NULL; switch ($this->parameters->type) { case 'groupsFight': $sqlTemplate = "UPDATE tour_groups_details SET finished = 1 WHERE vk_id = %d AND group_details_id = %d"; $sql = sprintf($sqlTemplate, UserParameters::getUserId(), $detailId); break; case 'playOffFight': $sqlTemplate = "UPDATE tour_play_off SET finished = 1 WHERE vk_id = %d AND play_off_id = %d and tour_type = %d"; $sql = sprintf($sqlTemplate, UserParameters::getUserId(), $detailId, $typeTour); break; } track_stats(); // Отслеживаем производительность if (!is_null($sql)) { $SQLResult = SQL::getInstance()->query($sql); if ($SQLResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $SQLResult; } track_stats(); // Отслеживаем производительность if ($this->parameters->type == 'playOffFight' && SQL::getInstance()->affected_rows == 1) { $tourFinished = TeamSatellite::isTourWasFinished($typeTour, $detailId); if ($tourFinished instanceof ErrorPoint) { return $tourFinished; } if ($tourFinished) { $bonus = 1; switch ($typeTour) { case TOUR_TYPE_VK: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceVK()); break; case TOUR_TYPE_COUNTRY: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceCountry()); break; case TOUR_TYPE_CITY: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceCity()); break; case TOUR_TYPE_UNI: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceUniversity()); break; } $this->teamProfile->setTourBonus($this->teamProfile->getTourBonus() > 0 ? $bonus * $this->teamProfile->getTourBonus() : $bonus); $this->result["bonus"] = $bonus; //$this->result["bonusTime"] = $this->teamProfile->getTourBonusTime(); $this->result["totalBonus"] = $this->teamProfile->getTourBonus(); } } track_stats(); // Отслеживаем производительность } } if (is_infinite($this->teamProfile->getMoney())) { $this->teamProfile->setMoney(10000); } $actionResult = $this->teamProfile->save(); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность logUserEnergy(); track_stats(); // Отслеживаем производительность SQL::getInstance()->commit(); track_stats(); // Отслеживаем производительность }
private function getFriendsTeams() { $this->result['teams'] = array(); $this->result['news'] = array(); $this->result['rating'] = array(); if ($this->parameters->groupSourceId) { logGroupSource($this->parameters->groupSourceId); } $needToUpgrade = false; $userCountry = intval($this->parameters->userCountry); $userCity = intval($this->parameters->userCity); $userUniversity = intval($this->parameters->userUniversity); track_stats(); // Отслеживаем производительность if ($userCountry != $this->teamProfile->getUserCountry()) { $this->teamProfile->setUserCountry($userCountry); $needToUpgrade = true; } if ($userCity != $this->teamProfile->getUserCity()) { $this->teamProfile->setUserCity($userCity); $needToUpgrade = true; } if ($userUniversity != $this->teamProfile->getUserUniversity()) { $this->teamProfile->setUserUniversity($userUniversity); $needToUpgrade = true; } if (isset($this->parameters->groupBonusNeeded) && $this->parameters->groupBonusNeeded == 1 && $this->teamProfile->getInGroup() == 0) { $this->teamProfile->setInGroup(1); $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() + GlobalParameters::GROUP_BONUS_REAL); $needToUpgrade = true; } track_stats(); // Отслеживаем производительность if ($needToUpgrade) { $actionResult = $this->teamProfile->save(); if ($actionResult instanceof ErrorPoint) { return $actionResult; } } if ($this->parameters->uids) { if (!is_object($this->parameters->uids)) { $this->parameters->uids = str_replace('\\\\', '', $this->parameters->uids); $this->parameters->uids = str_replace('\\"', '', $this->parameters->uids); $this->parameters->uids = json_decode($this->parameters->uids); } track_stats(); // Отслеживаем производительность $sql_template = "SELECT\n teams.team_name,\n teams.param_forward,\n teams.param_half,\n teams.param_safe,\n teams.user_photo,\n teams.user_name, \n teams.team_logo_id, \n teams.vk_id,\n teams.level\nFROM teams\nWHERE teams.vk_id IN (%s) order by teams.level desc, teams.counter_won desc "; $sql = sprintf($sql_template, Utils::IdsSeparetedByComma($this->parameters->uids)); $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } if ($SQLresult->num_rows) { $counterPlace = 1; while ($teamObject = $SQLresult->fetch_object()) { $team = new Team(); $team->initFromDB($teamObject, false); if ($team->getLevel() == 0) { continue; } $team->place = $counterPlace; $teamInJSON = JSONPrepare::team($team); $counterPlace++; $this->result['teams'][] = $teamInJSON; // $this->result['teams'][] = $teamObject; } } } $this->result['news'] = RAM::getInstance()->getNews(); if (count($this->result['news']) == 0) { $sql_template = "SELECT news_sport.* FROM news_sport ORDER BY news_id"; $sql = $sql_template; $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } if ($SQLresult->num_rows) { $counter = 0; while ($newsObject = $SQLresult->fetch_object()) { $news = new NewsEntry($newsObject); $news->id = $counter; $this->result['news'][] = $news; RAM::getInstance()->setNews($news); $counter++; } } } $leadTeams = RAM::getInstance()->getLeaders(); if (count($leadTeams) == 0) { $sql_template = "SELECT teams.* FROM teams WHERE total_place is not NULL ORDER BY total_place LIMIT 6"; $sql = $sql_template; $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } if ($SQLresult->num_rows) { $counter = 0; while ($teamObject = $SQLresult->fetch_object()) { $team = new Team(); $team->initFromDB($teamObject); RAM::getInstance()->setLeader($team, $counter); $counter++; $teamInJSON = JSONPrepare::team($team); $this->result['rating'][] = $teamInJSON; } } } else { foreach ($leadTeams as $team) { $teamInJSON = JSONPrepare::team($team); $this->result['rating'][] = $teamInJSON; } } }