public static function erase()
 {
     $sql_template = "DELETE FROM sponsors WHERE vk_id = %d";
     $sql = sprintf($sql_template, UserParameters::getUserId());
     $SQLresult = SQL::getInstance()->query($sql);
     return $SQLresult;
 }
 public function action()
 {
     $teamLogoId = intval($this->parameters->teamLogoId);
     $teamTitle = trim($this->parameters->teamTitle);
     if (empty($teamLogoId) || empty($teamTitle)) {
         $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Не указан логотип или название команды", ErrorPoint::TYPE_USER);
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $this->teamProfile->setTeamName($teamTitle);
     $this->teamProfile->setTeamLogoId($teamLogoId);
     $actionResult = $this->teamProfile->save();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $actionResult = $api->setStatus(UserParameters::getUserId(), sprintf(VK_APPLICATION_STATUS, $this->teamProfile->getTeamName()));
     track_stats();
     // Отслеживаем производительность
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     return $actionResult;
 }
 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 static function update($report_)
 {
     Logger::debug('main', "Abstract_ReportSession::update");
     $SQL = SQL::getInstance();
     $report = Abstract_ReportSession::load($report_->getID());
     if (!is_object($report)) {
         Logger::debug('main', "Abstract_ReportSession::updateSession failed to load report " . $report_->getID());
         return false;
     }
     $ret = $SQL->DoQuery('UPDATE @1 SET @2=%3,@4=%5,@6=%7 WHERE @8 = %9 LIMIT 1', $SQL->prefix . 'sessions_history', 'stop_why', $report_->stop_why, 'user', $report_->user, 'server', $report_->server, 'id', $report_->getID());
     return $ret;
 }
 private function getTodayPayments()
 {
     track_stats();
     // Отслеживаем производительность
     $sql_template = "SELECT SUM(payments.values) as summer FROM payments WHERE paymant_date > '%s 00:00:00';";
     $sql = sprintf($sql_template, date("Y-m-d"));
     $onLineResult = SQL::getInstance()->query($sql);
     if ($onLineResult instanceof ErrorPoint) {
         return $onLineResult;
     }
     track_stats();
     // Отслеживаем производительность
     $object = $onLineResult->fetch_object();
     $this->result['todayPayments'] = intval($object->summer);
 }
 public static function load_partial($t0_, $t1_)
 {
     $sql = SQL::getInstance();
     $sql->DoQuery('SELECT * FROM #1 WHERE @2 BETWEEN %3 AND %4 ORDER BY @2 ASC;', self::table, 'timestamp', date('c', $t0_), date('c', $t1_));
     $rows = $sql->FetchAllResults();
     $reports = array();
     foreach ($rows as $row) {
         $report = self::generateFromRow($row);
         if (!is_object($report)) {
             continue;
         }
         $reports[] = $report;
     }
     return $reports;
 }
 public function action()
 {
     $actionResult = NULL;
     track_stats();
     // Отслеживаем производительность
     $stadiumInstance = new Stadium();
     $stadiumInstance->initById($this->parameters->stadiumId);
     track_stats();
     // Отслеживаем производительность
     if ($stadiumInstance instanceof ErrorPoint) {
         return $stadiumInstance;
     }
     if ($this->parameters->isInGame && $stadiumInstance->getRequiredLevel() > $this->teamProfile->getLevel()) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Для соверщения этой операции недостаточно уровня. У Вас " . $this->teamProfile->getLevel() . ", а необходим " . $structure->getRequiredLevel(), ErrorPoint::TYPE_USER);
     }
     if ($this->parameters->isInGame) {
         if ($stadiumInstance->getPrice() > $this->teamProfile->getMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     } else {
         if ($stadiumInstance->getRealPrice() > $this->teamProfile->getRealMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     track_stats();
     // Отслеживаем производительность
     if ($this->teamProfile->getStadiumId() == $stadiumInstance->getId()) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Вы уже приобрели выбранный стадион позже", ErrorPoint::TYPE_USER);
     }
     $this->teamProfile->setStadiumInstance($stadiumInstance);
     if ($this->parameters->isInGame) {
         $this->teamProfile->setMoney($this->teamProfile->getMoney() - $stadiumInstance->getPrice());
     } else {
         $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() - $stadiumInstance->getRealPrice());
     }
     $actionResult = $this->teamProfile->save();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
示例#8
0
 public function save()
 {
     $sql_template = "INSERT INTO sponsors (\n    sponsor_id,\n    vk_id\n) VALUES (\n    %d,\n    %d\n)";
     $sql = sprintf($sql_template, $this->getId(), UserParameters::getUserId());
     $SQLResult = SQL::getInstance()->query($sql);
     if ($SQLResult instanceof ErrorPoint) {
         return $SQLResult;
     }
     $sponsor = RAM::getInstance()->getSponsorById($this->getId(), UserParameters::getUserId());
     if (empty($sponsor)) {
         $currentIndex = RAM::getInstance()->getMaxObjectIndexForTeam(UserParameters::getUserId(), RAM::RAM_TYPE_SPONSOR);
         RAM::getInstance()->setSponsor($this, UserParameters::getUserId(), $currentIndex);
     } else {
         RAM::getInstance()->setSponsor($this, UserParameters::getUserId());
     }
 }
 public static function load_limited($number_, $offset_ = 0)
 {
     Logger::debug('main', 'Starting Abstract_AdminAction::load_limited');
     $SQL = SQL::getInstance();
     $SQL->DoQuery('SELECT * FROM #1 ORDER BY @2 DESC LIMIT ' . intval($number_) . ' OFFSET ' . intval($offset_), self::table, 'when');
     $rows = $SQL->FetchAllResults();
     $actions = array();
     foreach ($rows as $row) {
         $action = self::generateFromRow($row);
         if (!is_object($action)) {
             continue;
         }
         $actions[] = $action;
     }
     return $actions;
 }
示例#10
0
 public function accountingStatistic($statistic)
 {
     return;
     $SQL = '';
     if ($statistic->mainMenu) {
         foreach ($statistic->mainMenu as $mainMenu => $count) {
             $SQL .= "update statistic_main_menu set stat_count_click = (stat_count_click + " . intval($count) . ") where stat_name = '{$mainMenu}';\r\n ";
         }
     }
     if ($statistic->shopItems) {
         foreach ($statistic->shopItems as $itemStatId => $itemStat) {
             $SQL .= "\nINSERT INTO statistic_shop (stat_id, stat_count_click, stat_count_hover) VALUES (" . $itemStatId . ", " . $itemStat->clk . ", " . $itemStat->hvr . ")\nON DUPLICATE KEY UPDATE stat_count_click = stat_count_click + " . $itemStat->clk . ", stat_count_hover = stat_count_hover + " . $itemStat->hvr . " ;\r\n\n";
         }
     }
     SQL::getInstance()->query($SQL);
 }
 public function action()
 {
     $friendId = intval($this->parameters->friendId);
     if (empty($friendId)) {
         $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Получен не правильный номер друга", ErrorPoint::TYPE_USER);
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = TeamSatellite::isAvailableToPrize($friendId);
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     if ($actionResult === false) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Выбранному пользователю вы уже дарили подарок. Теперь только завтра", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = TeamSatellite::cratePrizeDateLabel($friendId);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = TeamSatellite::prizeStudyPoint($friendId);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     SQL::getInstance()->commit();
     track_stats();
     // Отслеживаем производительность
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $api->setCounter($friendId, TeamSatellite::getPrizeStudyPoint($friendId));
     return $actionResult;
 }
示例#12
0
 public function initById($stadiumId)
 {
     $stadiumPrototype = RAM::getInstance()->getStadiumPrototypeById($stadiumId);
     if (empty($stadiumPrototype)) {
         $sql_template = "SELECT * FROM item_stadiums WHERE id = '%s'";
         $sql = sprintf($sql_template, intval($stadiumId));
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $object = $SQLresult->fetch_object();
             $this->initFromParameters($object);
             RAM::getInstance()->setStadiumPrototype($object);
         } else {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Не найден стадион по указаному номеру ", ErrorPoint::TYPE_SYSTEM);
         }
     } else {
         $this->initFromParameters($stadiumPrototype);
     }
 }
 public function action()
 {
     track_stats();
     // Отслеживаем производительность
     $actionResult = NULL;
     $superId = intval($this->parameters->footballerId);
     $footballerInstance = $this->teamProfile->getFootballerById($superId);
     if (empty($footballerInstance)) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Выбранный футболист не найден в вашей команде", ErrorPoint::TYPE_USER);
     }
     $footballerPricePromotion = GlobalParameters::SUPER_PRICE;
     if ($this->teamProfile->getRealMoney() < $footballerPricePromotion) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно средств для совершения этих действий", ErrorPoint::TYPE_USER);
     }
     if ($footballerInstance->getIsSuper()) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Данный футболист уже являться фаворитным", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     $footballerInstance->setAsSuper(true);
     $actionResult = $footballerInstance->update();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() - $footballerPricePromotion);
     $actionResult = $this->teamProfile->save();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
 public function action()
 {
     $actionResult = NULL;
     $isInGame = $this->parameters->isInGame;
     $paymentId = $this->parameters->paymentId;
     if (!array_key_exists($paymentId, $this->payments)) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Не выбран тип покупки", ErrorPoint::TYPE_USER);
     }
     $paymentInstance = $this->payments[$paymentId];
     if ($isInGame) {
         if ($paymentInstance->price > $this->teamProfile->getMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     } else {
         if ($paymentInstance->realPrice > $this->teamProfile->getRealMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     $this->teamProfile->setStudyPoints($this->teamProfile->getStudyPoints() + $paymentInstance->studyCount);
     if ($this->parameters->isInGame) {
         $this->teamProfile->setMoney($this->teamProfile->getMoney() - $paymentInstance->price);
     } else {
         $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() - $paymentInstance->realPrice);
     }
     $actionResult = $this->teamProfile->save();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
        $apiResult = NULL;
        $apiResult = $api->sendNotification($teamObject->vk_id, $notify_message);
        usleep(VK_MAILING_SPEED);
        /*      $teamId = $teamObject->vk_id; echo $teamId . "\n";
                $team = RAM::getInstance()->getTeamById($teamId);
                if(!empty($team)){
                    RAM::getInstance()->changeTeamField($teamId, 'tourBonus', $bonus);
                    RAM::getInstance()->changeTeamField($teamId, 'tourBonusTime', 0);
                }*/
    }
}
//////////////////// Это подготовка к новому //////////////////
TourSatellite::setTimerDate(time(), time() + 5 * 24 * 60 * 60, TOUR_NOTIFY_NEW);
$sql_template = "UPDATE teams SET tour_notify = " . TOUR_NOTIFY_NEW . ", tour_III = 0;";
// tour_III = 0
$SQLResultTeams = SQL::getInstance()->query($sql_template);
/*
//////////////////// Обновляем всех в памяти //////////////////

$sql_template = "SELECT vk_id FROM teams ;";
$sql = $sql_template;

$SQLresultSeelctTeam = SQL::getInstance()->query($sql);
if($SQLresultSeelctTeam instanceof ErrorPoint){
    return $SQLresultSeelctTeam;
}

echo "Upgrading for All users, count records: " . $SQLresultSeelctTeam->num_rows . " teams"  . PHP_EOL ;

if($SQLresultSeelctTeam->num_rows){
 public function action()
 {
     track_stats();
     // Отслеживаем производительность
     $levelSum = 0;
     if (count($this->parameters)) {
         foreach ($this->parameters as $footballer_id => $footballerParameters) {
             $levelSum += intval($footballerParameters->level);
         }
     }
     $currentSumLevelCount = $this->teamProfile->getFootballerSumLevel();
     track_stats();
     // Отслеживаем производительность
     $spentStudyPoints = $levelSum - $currentSumLevelCount;
     if ($spentStudyPoints > $this->teamProfile->getStudyPoints() * 2) {
         $errorMessage = "Вы потратили слишком много очков обучения. У вас есть " . $this->teamProfile->getStudyPoints() . ", а потрачено " . $spentStudyPoints . ". Действие отменено";
         return new ErrorPoint(ErrorPoint::CODE_SECURITY, $errorMessage, ErrorPoint::TYPE_USER);
     }
     SQL::getInstance()->autocommit(false);
     track_stats();
     // Отслеживаем производительность
     $footballersInDB = $this->teamProfile->getFootballers();
     $isExistsGoalKeeper = false;
     foreach ($footballersInDB as &$footballerParameters) {
         $footballerId = $footballerParameters->getId();
         if (!isset($this->parameters->{$footballerId})) {
             continue;
             // SQL::getInstance()->rollback();
             // return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Футболист под номером " + $footballerId + " не найден", ErrorPoint::TYPE_USER);
         }
         $this->parameters->{$footballerId}->isActive = intval($this->parameters->{$footballerId}->isActive);
         $this->parameters->{$footballerId}->type = intval($this->parameters->{$footballerId}->type);
         $this->parameters->{$footballerId}->level = intval($this->parameters->{$footballerId}->level);
         if ($this->parameters->{$footballerId}->level != $footballerParameters->getLevel() || $this->parameters->{$footballerId}->type != $footballerParameters->getType() || $this->parameters->{$footballerId}->isActive != $footballerParameters->getIsActive()) {
             $footballerParameters->setLevel($this->parameters->{$footballerId}->level);
             $footballerParameters->setType($this->parameters->{$footballerId}->type);
             $footballerParameters->setActive($this->parameters->{$footballerId}->isActive);
             $updateResult = $footballerParameters->update();
             if ($updateResult instanceof ErrorPoint) {
                 SQL::getInstance()->rollback();
                 return $updateResult;
             }
         }
         if ($footballerParameters->getIsActive() && $footballerParameters->getType() == TYPE_FOOTBALLER_GOALKEEPER_CODE) {
             $isExistsGoalKeeper = true;
         }
     }
     track_stats();
     // Отслеживаем производительность
     if ($isExistsGoalKeeper === false) {
         SQL::getInstance()->rollback();
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "В основном составе команды обязательно должен присутствовать вратарь", ErrorPoint::TYPE_USER);
     }
     if ($this->teamProfile->getActiveCount() > GlobalParameters::MAX_TEAM) {
         SQL::getInstance()->rollback();
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваша команда имеет неправильный состав игроков (Активных игроков: " . $this->teamProfile->getActiveCount() . ")", ErrorPoint::TYPE_SYSTEM);
     }
     track_stats();
     // Отслеживаем производительность
     $this->teamProfile->updateTeamParameters();
     track_stats();
     // Отслеживаем производительность
     $spentStudyPoints = $spentStudyPoints < 0 ? 0 : $spentStudyPoints;
     $this->teamProfile->setStudyPoints($this->teamProfile->getStudyPoints() - $spentStudyPoints);
     $actionResult = $this->teamProfile->save();
     track_stats();
     // Отслеживаем производительность
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     return $actionResult;
 }
示例#17
0
 public function load_by_server($fqdn_)
 {
     Logger::debug('main', 'Starting Abstract_Task::load_from_server(' . $fqdn_ . ')');
     $SQL = SQL::getInstance();
     $SQL->DoQuery('SELECT * FROM @1 WHERE @2 = %3', $SQL->prefix . 'tasks', 'server', $fqdn_);
     $rows = $SQL->FetchAllResults();
     $tasks = array();
     foreach ($rows as $row) {
         $task = self::generateFromRow($row);
         if (!is_object($task)) {
             continue;
         }
         $tasks[] = $task;
     }
     return $tasks;
 }
示例#18
0
文件: sql.php 项目: skdong/nfs-ovd
 public function update($group_)
 {
     Logger::debug('main', "ApplicationsGroupDB::sql::update({$group_})");
     if (!is_object($group_)) {
         Logger::error('main', "ApplicationsGroupDB::sql::update({$group_}) the parameter is not an object");
         return false;
     }
     if (array_key_exists($group_->id, $this->cache)) {
         unset($this->cache[$group_->id]);
     }
     $sql2 = SQL::getInstance();
     $res = $sql2->DoQuery('UPDATE @1  SET @2 = %3 , @4 = %5 , @6 = %7  WHERE @8 = %9', $this->table, 'published', $group_->published, 'name', $group_->name, 'description', $group_->description, 'id', $group_->id);
     return $res !== false;
 }
示例#19
0
 public function update($usergroup_)
 {
     Logger::debug('main', 'UserGroupDBDynamic::internal::update');
     $old_usergroup = $this->import($usergroup_->id);
     $old_rules = $old_usergroup->rules;
     $sql2 = SQL::getInstance();
     $res = $sql2->DoQuery('UPDATE #1  SET @2 = %3 , @4 = %5 , @6 = %7 , @10 = %11  WHERE @8 = %9', self::table, 'published', $usergroup_->published, 'name', $usergroup_->name, 'description', $usergroup_->description, 'id', $usergroup_->id, 'validation_type', $usergroup_->validation_type);
     if ($res === false) {
         Logger::error('main', 'UserGroupDBDynamic::internal::update failed to update the group from DB');
         return false;
     }
     foreach ($old_rules as $a_rule) {
         Abstract_UserGroup_Rule::delete($a_rule->id);
     }
     $new_rules = $usergroup_->rules;
     foreach ($new_rules as $a_rule) {
         $a_rule->usergroup_id = $usergroup_->getUniqueID();
         Abstract_UserGroup_Rule::save($a_rule);
     }
     return true;
 }
示例#20
0
//////////////////// Обновляем всех в памяти //////////////////
$sql_template = "SELECT vk_id, tour_place_vk, tour_place_country, tour_place_city, tour_place_uni FROM teams\nWHERE ( tour_place_vk > 0 or tour_place_country > 0 or tour_place_city > 0 or tour_place_uni > 0 ) AND date_reg IS NOT NULL and  vk_id = 100206819;";
$sql = $sql_template;
$SQLresultSeelctTeam = SQL::getInstance()->query($sql);
if ($SQLresultSeelctTeam instanceof ErrorPoint) {
    return $SQLresultSeelctTeam;
}
echo "Upgrading for All users, count records: " . $SQLresultSeelctTeam->num_rows . " teams" . PHP_EOL;
if ($SQLresultSeelctTeam->num_rows) {
    while ($teamObject = $SQLresultSeelctTeam->fetch_object()) {
        $bonus = 1;
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_VK, $teamObject->tour_place_vk);
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_COUNTRY, $teamObject->tour_place_country);
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_CITY, $teamObject->tour_place_city);
        $bonus *= GoldCointsGrid::getInstance()->getBonusByPlace(TOUR_TYPE_UNI, $teamObject->tour_place_uni);
        if ($bonus > GlobalParameters::MAX_TOUR_BONUS) {
            $bonus = GlobalParameters::MAX_TOUR_BONUS;
        }
        $sql_template = "UPDATE teams set tour_bonus = %f, tour_bonus_time = 0;";
        $sql = sprintf($sql_template, round($bonus, 2));
        $SQLResultTeamsFake = SQL::getInstance()->query($sql);
        echo $bonus;
        exit;
        /*      $teamId = $teamObject->vk_id; echo $teamId . "\n";
                $team = RAM::getInstance()->getTeamById($teamId);
                if(!empty($team)){
                    RAM::getInstance()->changeTeamField($teamId, 'tourBonus', $bonus);
                    RAM::getInstance()->changeTeamField($teamId, 'tourBonusTime', 0);
                }*/
    }
}
            $mainText = substr($mainText, 0, strpos($mainText, $badText));
        }
        $mainText = strip_tags($mainText);
        $mainText = trim($mainText);
        $mainText = str_replace("ё", "е", $mainText);
        $mainText = str_replace("Ё", "Е", $mainText);
        $subTitle = strip_tags($subTitle);
        $subTitle = trim($subTitle);
        $subTitle = str_replace("ё", "е", $subTitle);
        $subTitle = str_replace("Ё", "Е", $subTitle);
        $destinationName = "news_image_" . $count;
        copyPhotoFile("http://www.euro-football.ru" . $imageLink, $destinationName . ".jpg");
        // $imageLink = substr($imageLink, 0, -4);
        $sql_template = 'INSERT INTO news_sport (title, content, image, sub_title) values("%s", "%s", "%s", "%s");';
        $sql = sprintf($sql_template, SQL::getInstance()->real_escape_string($title), SQL::getInstance()->real_escape_string($mainText), SQL::getInstance()->real_escape_string($destinationName), SQL::getInstance()->real_escape_string($subTitle));
        $SQLresultTemp = SQL::getInstance()->query($sql);
        if ($SQLresultTemp instanceof ErrorPoint) {
            continue;
        }
        $newsObject = new stdClass();
        $newsObject->news_id = $count;
        $newsObject->title = $title;
        $newsObject->content = $mainText;
        $newsObject->image = $destinationName;
        $newsObject->sub_title = $subTitle;
        $news = new NewsEntry($newsObject);
        RAM::getInstance()->setNews($news);
    } else {
        $count--;
    }
}
 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;
 }
示例#23
0
 public static function getByFSUser($fs_user_login_)
 {
     $SQL = SQL::getInstance();
     $SQL->DoQuery('SELECT * FROM @1 WHERE @2 LIKE %3', $SQL->prefix . 'sessions', 'settings', '%fs_access_login%' . $fs_user_login_ . '%');
     $rows = $SQL->FetchAllResults();
     $sessions = array();
     foreach ($rows as $row) {
         $session = self::generateFromRow($row);
         if (!is_object($session)) {
             continue;
         }
         $sessions[] = $session;
     }
     return $sessions;
 }
 public function action()
 {
     $friendId = intval($this->parameters->friendId);
     if (empty($friendId)) {
         $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Получен не правильный номер друга", ErrorPoint::TYPE_USER);
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $alreadyExists = $this->teamProfile->getFootballerById($friendId);
     if ($alreadyExists) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже играет за вас", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = FootballerSatellite::getFootballerOwner($friendId);
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     if ($actionResult !== false) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже числиться в другом футбольном клубе", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     $friendFootballer = new Footballer();
     $actionResult = $friendFootballer->addFriend($friendId, NULL, $this->teamProfile->getActiveCount());
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $addonPoints = 0;
     if (TeamSatellite::isFreshFriend($friendId)) {
         // Даються очьку обучения как среднее по всех футболистов
         if (count($this->teamProfile->getFootballers()) != 0) {
             $addonPoints = floor($this->teamProfile->getFootballerSumLevel() / count($this->teamProfile->getFootballers()));
             $this->teamProfile->setStudyPoints($this->teamProfile->getStudyPoints() + $addonPoints);
             $actionResult = $this->teamProfile->save();
             if ($actionResult instanceof ErrorPoint) {
                 SQL::getInstance()->rollback();
                 return $actionResult;
             }
         }
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = Team::markTeamAsSelected($friendId);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersFriendsCount', $this->teamProfile->getAllFootballersFriendsCount() + 1);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
         $this->result['footballer'] = $friendFootballer;
         $this->result['addonStadyPoints'] = $addonPoints;
         $this->result['totalStadyPoints'] = $this->teamProfile->getStudyPoints();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
示例#25
0
 public function update($conf)
 {
     if (array_key_exists($conf->getAttribute('id'), $this->cache)) {
         unset($this->cache[$conf->getAttribute('id')]);
     }
     if ($this->isOK($conf)) {
         $query = 'UPDATE#1 SET ';
         $attributes = $conf->getAttributesList();
         foreach ($attributes as $key) {
             $value = $conf->getAttribute($key);
             if ($key == 'values') {
                 $value = json_serialize($value);
             }
             $query .= '`' . $key . '` = \'' . mysql_escape_string($value) . '\' , ';
         }
         $query = substr($query, 0, -2);
         // del the last ,
         $query .= ' WHERE `id` =\'' . $conf->getAttribute('id') . '\'';
         $sql2 = SQL::getInstance();
         $res = $sql2->DoQuery($query, self::table);
         if ($res === false) {
             return false;
         }
         return true;
     }
     return false;
 }
        case TYPE_FOOTBALLER_FORWARD:
        case TYPE_FOOTBALLER_GOALKEEPER:
        case TYPE_FOOTBALLER_HALFSAFER:
        case TYPE_FOOTBALLER_SAFER:
            switch ($item->shopType) {
                case TYPE_FOOTBALLER_FORWARD:
                    $line = TYPE_FOOTBALLER_FORWARD_CODE;
                    break;
                case TYPE_FOOTBALLER_GOALKEEPER:
                    $line = TYPE_FOOTBALLER_GOALKEEPER_CODE;
                    break;
                case TYPE_FOOTBALLER_HALFSAFER:
                    $line = TYPE_FOOTBALLER_HALFSAFER_CODE;
                    break;
                case TYPE_FOOTBALLER_SAFER:
                    $line = TYPE_FOOTBALLER_SAFER_CODE;
                    break;
            }
            $SQL = "INSERT INTO item_footballers (\n    id,\n    required_level,\n    price,\n    real_price,\n    param_level,\n    line\n    ) VALUES (\n    " . intval($itemId) . ",\n    " . floatval($item->requiredLevel) . ",\n    " . floatval($item->price) . ",\n    " . floatval($item->realprice) . ",\n    " . intval($item->params->level) . ",\n    " . $line . "\n    )";
            break;
        case TYPE_FOOTBALLER_TEAMLEAD:
            $SQL = "INSERT INTO item_teamleads (\n    id,\n    required_level,\n    price,\n    real_price,\n    param_study_rate\n    ) VALUES (\n    " . intval($itemId) . ",\n    " . floatval($item->requiredLevel) . ",\n    " . floatval($item->price) . ",\n    " . floatval($item->realprice) . ",\n    " . floatval($item->params->studyRate) . "\n    )";
            break;
        case TYPE_LOGO_SPONSOR:
            $SQL = "INSERT INTO item_sponsors (\n    id,\n    required_level,\n    energy\n    ) VALUES (\n    " . intval($itemId) . ",\n    " . floatval($item->requiredLevel) . ",\n    " . floatval($item->params->energy) . "\n    )";
            break;
    }
    if (!is_null($SQL)) {
        SQL::getInstance()->query($SQL);
    }
}
示例#27
0
文件: sql.php 项目: skdong/nfs-ovd
 public function update($usergroup_)
 {
     Logger::debug('main', "USERGROUPDB::update({$usergroup_})");
     if (array_key_exists($usergroup_->id, $this->cache)) {
         unset($this->cache[$usergroup_->id]);
     }
     $sql2 = SQL::getInstance();
     $res = $sql2->DoQuery('UPDATE @1  SET @2 = %3 , @4 = %5 , @6 = %7  WHERE @8 = %9', $this->table, 'published', $usergroup_->published, 'name', $usergroup_->name, 'description', $usergroup_->description, 'id', $usergroup_->id);
     return $res !== false;
 }
 private function getPlayOffByStep($currentStep, $groupType, $placerId)
 {
     $sql_template = "select * from tour_play_off where play_off_step = %d and tour_type = %d and tour_placer_id = %d ORDER BY play_off_id ;";
     $sql = sprintf($sql_template, $currentStep, $groupType, $placerId);
     $SQLresult = SQL::getInstance()->query($sql);
     if ($SQLresult instanceof ErrorPoint) {
         return $SQLresult;
     }
     $group = array();
     if ($SQLresult->num_rows) {
         while ($teamObject = $SQLresult->fetch_object()) {
             if (isset($group[$teamObject->vk_id_enemy])) {
                 $group[$teamObject->vk_id_enemy]['teamEnemy'] = $teamObject->vk_id;
                 continue;
             }
             if (!isset($group[$teamObject->vk_id])) {
                 $group[$teamObject->vk_id] = array("team" => $teamObject->vk_id, "teamEnemy" => 0, "goal" => $teamObject->goals, "goalEnemy" => $teamObject->goals_enemy);
             }
         }
     }
     $forReturn = array();
     foreach ($group as $groupItem) {
         $forReturn[] = $groupItem;
     }
     return $forReturn;
 }
 private function install($teamParam)
 {
     $team = json_decode($teamParam);
     /*if(empty($team)){
           return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Информация о команде получена неполностью, повторите попытку", ErrorPoint::TYPE_USER, $teamParam);  
       }*/
     track_stats();
     // Отслеживаем производительность
     $actionResult = $this->teamProfile->initById(UserParameters::getUserId());
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     if ($actionResult === true) {
         return;
     }
     SQL::getInstance()->autocommit(false);
     $addOnStudyPoints = 0;
     $this->teamProfile->setTeamName(isset($team->teamName) ? $team->teamName : "Футболлер");
     $this->teamProfile->setTeamLogoId(isset($team->teamLogoId) ? $team->teamLogoId : "42326");
     $this->teamProfile->setUserPhoto($this->parameters->userPhoto);
     $this->teamProfile->setUserName($this->parameters->userName);
     $this->teamProfile->setUserYear(isset($this->parameters->userYear) ? intval($this->parameters->userYear) : 0);
     $this->teamProfile->setUserCountry(isset($this->parameters->userCountry) ? intval($this->parameters->userCountry) : 0);
     $this->teamProfile->setParameterForward(0);
     $this->teamProfile->setParameterHalf(0);
     $this->teamProfile->setParameterSafe(0);
     $this->teamProfile->setInGroup(0);
     $installResult = $this->teamProfile->install();
     track_stats();
     // Отслеживаем производительность
     if ($installResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     if ($addOnStudyPoints > GlobalParameters::MAX_TEAM) {
         SQL::getInstance()->rollback();
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Друзей в команду набрано больше чем допустимо", ErrorPoint::TYPE_USER);
     }
     $needRandomFootballers = GlobalParameters::MAX_TEAM - $addOnStudyPoints;
     track_stats();
     // Отслеживаем производительность
     if ($needRandomFootballers) {
         $prototypes = FootballerSatellite::getRandomPrototypes($needRandomFootballers);
         if ($prototypes instanceof ErrorPoint) {
             SQL::getInstance()->rollback();
             return $prototypes;
         }
         foreach ($prototypes as $footballerPrototype) {
             $footballer = new Footballer();
             $actionResult = $footballer->add($footballerPrototype, $needRandomFootballers--);
             if ($actionResult instanceof ErrorPoint) {
                 SQL::getInstance()->rollback();
                 return $actionResult;
             }
             $this->teamProfile->addFootballerToStore($footballer);
         }
     }
     track_stats();
     // Отслеживаем производительность
     $this->teamProfile->updateTeamParameters();
     $addOnStudyPoints += 5;
     // Дадим ещё немного очков, для заманухи
     $this->teamProfile->setStudyPoints($addOnStudyPoints);
     $installResult = $this->teamProfile->save();
     track_stats();
     // Отслеживаем производительность
     if ($installResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     } else {
         SQL::getInstance()->commit();
     }
     /*        $getResult = $this->teamProfile->initById(UserParameters::getUserId());
     
             if($getResult instanceof ErrorPoint){
                 SQL::getInstance()->rollback();
                 return $actionResult;
             }
     */
     track_stats();
     // Отслеживаем производительность
     $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED);
     $api->setStatus(UserParameters::getUserId(), sprintf(VK_APPLICATION_STATUS, $this->teamProfile->getTeamName()));
     track_stats();
     // Отслеживаем производительность
     return $installResult;
 }
include_once SYSTEM_PATH . "/System/function.php";
$startString = "Running Detecting total place III ... ";
echo $startString . date("[Y-m-d H:i:s.m]") . PHP_EOL;
register_shutdown_function('shutdown');
set_error_handler("handlerError");
$actionResult = null;
$scoreStore = array();
if (SQL::getInstance()->connect_error) {
    $actionResult = new ErrorPoint(ErrorPoint::CODE_SQL, "Соединение провалено (" . SQL::getInstance()->connect_error . ")", ErrorPoint::TYPE_SYSTEM);
    die("No connection");
}
$sql = "SELECT \n    teams.vk_id\nFROM teams\norder by teams.level desc, teams.counter_won desc ";
$SQLresult = SQL::getInstance()->query($sql);
if ($SQLresult instanceof ErrorPoint) {
    return $SQLresult;
}
echo "Need to upgrade " . $SQLresult->num_rows . " country tours" . PHP_EOL;
if ($SQLresult->num_rows) {
    $counterPlace = 1;
    $sql = "";
    while ($teamObject = $SQLresult->fetch_object()) {
        if ($counterPlace % 100 == 0) {
            SQL::getInstance()->query($sql);
            $sql = "";
        }
        $sql_template = "UPDATE teams SET total_place = %d WHERE teams.vk_id = (%s);";
        $sql .= sprintf($sql_template, $counterPlace, $teamObject->vk_id);
        $counterPlace++;
    }
}
print " stop..." . date("[Y-m-d H:i:s.m]") . '<br/>' . PHP_EOL;