示例#1
0
 public static function export(\Rebond\Core\ModelInterface $module)
 {
     $exportPath = \Rebond\Config::path('export');
     $tempPath = \Rebond\Config::path('temp');
     // TODO add XML model node
     // generate data script
     $dataScriptPath = $tempPath . 'data.sql';
     $table = 'app_' . strtolower($module->getTitle());
     $db = new Util\Data();
     $result = $db->select('SELECT * FROM ' . $table);
     $script = $db->backupData($table, $result);
     $result = $db->select('SELECT * FROM cms_content WHERE module_id = ?', [$module->getId()]);
     $script .= $db->backupData('cms_content', $result);
     File::save($dataScriptPath, 'w', $script);
     // create zip
     $zipFile = $module->getTitle() . '.zip';
     $zip = new \ZipArchive();
     $res = $zip->open($exportPath . $zipFile, \ZIPARCHIVE::OVERWRITE);
     if (!$res) {
         return $res;
     }
     $modulePath = FULL_PATH . 'Rebond/App/' . $module->getTitle() . '/';
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($modulePath));
     foreach ($iterator as $file) {
         $filename = str_replace($modulePath, '', str_replace('\\', '/', $file));
         if (file_exists($file) && substr($filename, -1) != '.') {
             $zip->addFile($file, $filename);
         }
     }
     $zip->addFile($dataScriptPath, 'data.sql');
     $zip->close();
     return $zipFile;
 }
示例#2
0
文件: Service.php 项目: vincium/lot
 public static function fillCPU($tournament)
 {
     $need = $tournament->getSize() - count($tournament->getTournamentPlayers());
     $db = new Util\Data();
     if ($need > 0) {
         $sqlBusyPlayer = 'SELECT DISTINCT tp.player_id
             FROM bus_tournament_player tp
             JOIN bus_tournament t ON t.id = tp.tournament_id
             WHERE t.status < 3';
         $rows = $db->select($sqlBusyPlayer);
         $busyPlayers = [0];
         if (count($rows) > 0) {
             $list = $rows->fetchAll(\PDO::FETCH_COLUMN);
             foreach ($list as $key => $value) {
                 $busyPlayers[] = $value;
             }
         }
         $sql = 'SELECT DISTINCT p.id
             FROM bus_player p
             LEFT JOIN bus_tournament_player tp ON tp.player_id = p.id
             WHERE p.active = 1
             AND p.user_id = 0
             AND (tp.player_id IS NULL OR tp.player_id NOT IN (?))
             ORDER BY p.tour_ranking';
         $players = $db->select($sql, [implode(',', $busyPlayers)]);
         if (count($players) == 0) {
             Util\Log::log(Util\Code::CRON, 'Not enough CPU, tournamentId: ' . $tournament->getId() . ', 0 / ' . $need, __FILE__, __LINE__);
             return false;
         }
         $players = $players->fetchAll(\PDO::FETCH_ASSOC);
         if (count($players) < $need) {
             Util\Log::log(Util\Code::CRON, 'Not enough CPU, tournamentId: ' . $tournament->getId() . ', ' . count($players) . ' / ' . $need, __FILE__, __LINE__);
             return false;
         }
         $playerIds = Engine::findCPU($players, $need, $tournament->getClassification());
         if (count($playerIds) < $need) {
             Util\Log::log(Util\Code::CRON, 'Not enough CPU found, tournamentId: ' . $tournament->getId() . ', ' . count($playerIds) . ' / ' . $need, __FILE__, __LINE__);
             return false;
         }
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\Player\Data::getList(['id']);
         $options['where'][] = 'player.id IN (' . implode(',', $playerIds) . ')';
         $players = \Own\Bus\Player\Data::loadAll($options);
         foreach ($players as $player) {
             $tp = new \Own\Bus\TournamentPlayer\Model();
             $tp->setTournamentId($tournament->getId());
             $tp->setPlayerId($player->getId());
             $tp->save();
         }
     }
     return true;
 }
示例#3
0
文件: Data.php 项目: vincium/lot
 public static function loadPlayersWithOldMatches()
 {
     $query = 'SELECT player_id, COUNT(*) as total FROM bus_player_match
         WHERE has_viewed = 0 AND modified_date < NOW() - INTERVAL ? HOUR
         GROUP BY player_id';
     $db = new Util\Data();
     return $db->select($query, [\Own\Bus\Engine::DAY * 7]);
 }
示例#4
0
文件: Data.php 项目: vincium/resa
 public static function loadPartners($playerId)
 {
     $db = new Util\Data();
     $sql = 'SELECT player.id, player.level, user.firstname, user.lastname, GROUP_CONCAT(mc.court_id) as courts, 0 as play
         FROM bus_player player
         JOIN core_user user ON user.id = player.id
         JOIN bus_player_membership pm ON pm.player_id = player.id
         JOIN bus_membership membership ON membership.id = pm.membership_id
         JOIN bus_membership_court mc ON mc.membership_id = membership.id
         WHERE membership.start_date <= CURDATE()
         AND membership.end_date >= CURDATE()
         AND user.status = 1
         AND player.id != ?
         GROUP BY player.id, player.level, user.firstname, user.lastname';
     $players = $db->select($sql, [$playerId]);
     $players = array_column($players->fetchAll(\PDO::FETCH_ASSOC), null, 'id');
     $sql = 'SELECT IF(player1_id = ?, player2_id, player1_id) AS id, SUM(1) total
         FROM bus_book
         WHERE (player1_id = ? OR player2_id = ?)
         AND booking_date > NOW() - INTERVAL 6 MONTH
         GROUP BY IF(player1_id = ?, player2_id, player1_id)
         ORDER BY total DESC
         LIMIT 10';
     $commonPlayers = $db->select($sql, [$playerId, $playerId, $playerId, $playerId]);
     while ($row = $commonPlayers->fetch(\PDO::FETCH_ASSOC)) {
         if (array_key_exists($row['id'], $players)) {
             $players[$row['id']]['play'] = (int) $row['total'];
         }
     }
     usort($players, function ($a, $b) {
         if ($a['play'] == $b['play']) {
             return $a['firstname'] > $b['firstname'];
         }
         return $a['play'] < $b['play'];
     });
     return $players;
 }
示例#5
0
 protected static function mapList(Util\Data $db)
 {
     $rows = $db->select();
     if (count($rows) === 0) {
         return [];
     }
     $models = [];
     while ($row = $rows->fetch(\PDO::FETCH_ASSOC)) {
         $models[] = self::mapper($row);
     }
     return $models;
 }
示例#6
0
文件: Data.php 项目: vincium/lot
 public static function updatePlayerPoints($playerIds, $createdDate)
 {
     // tour
     $db = new Util\Data();
     $sql = 'SELECT player_id, SUM(tp.points) as points, COUNT(player_id) as total
         FROM bus_tournament_player tp
         JOIN bus_tournament t ON t.id = tp.tournament_id
         WHERE t.start_date > NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR
         AND tp.points > 0
         AND player_id IN (' . implode(',', $playerIds) . ')
         GROUP BY player_id
         ORDER BY points DESC';
     $result = $db->select($sql);
     if (count($result) == 0) {
         return;
     }
     while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
         if ($row['total'] <= 18) {
             \Own\Bus\Player\Data::updateTourPointsByPlayerId($row['player_id'], $row['points']);
             continue;
         }
         $sql = 'SELECT SUM(points) as points
             FROM (
                 SELECT points
                 FROM bus_tournament_player tp
                 JOIN bus_tournament t ON t.id = tp.tournament_id
                 WHERE player_id = ?
                 AND t.start_date > NOW() - INTERVAL ? HOUR
                 ORDER BY points DESC
                 LIMIT 18
             ) AS subquery';
         $subRow = $db->selectOne($sql, [$row['player_id'], Engine::DAY * 336]);
         if (isset($subRow)) {
             \Own\Bus\Player\Data::updateTourPointsByPlayerId($row['player_id'], $subRow['points']);
         }
     }
     // race
     $startYearDate = \Own\Bus\Engine::getStartYearDate($createdDate);
     $sql = 'SELECT player_id, SUM(tp.points) as points, COUNT(player_id) as total
         FROM bus_tournament_player tp
         JOIN bus_tournament t ON t.id = tp.tournament_id
         WHERE t.start_date > \'' . $startYearDate . '\'
         AND tp.points > 0
         AND player_id IN (' . implode(',', $playerIds) . ')
         GROUP BY player_id
         ORDER BY points DESC';
     $result = $db->execute($sql);
     if (count($result) == 0) {
         return;
     }
     while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
         if ($row['total'] <= 18) {
             \Own\Bus\Player\Data::updateRacePointsByPlayerId($row['player_id'], $row['points']);
             continue;
         }
         $sql = 'SELECT SUM(points) as points
             FROM (
                 SELECT points
                 FROM bus_tournament_player tp
                 JOIN bus_tournament t ON t.id = tp.tournament_id
                 WHERE player_id = ? AND t.start_date > ?
                 ORDER BY points DESC
                 LIMIT 18
             ) AS subquery';
         $subRow = $db->selectOne($sql, [$row['player_id'], $startYearDate]);
         if (isset($subRow)) {
             \Own\Bus\Player\Data::updateRacePointsByPlayerId($row['player_id'], $subRow['points']);
         }
     }
 }
示例#7
0
文件: Data.php 项目: vincium/lot
 public static function loadStatsByPlayerId($playerId, $self = true)
 {
     $stats = ['winP' => 0, 'lossP' => 0, 'winT' => 0, 'lossT' => 0, 'winL' => 0, 'lossL' => 0, 'totalP' => 0, 'totalT' => 0, 'totalL' => 0, 'win' => 0, 'loss' => 0, 'total' => 0];
     $hasViewed1 = $self ? ' AND pm1.has_viewed = true' : '';
     $hasViewed2 = $self ? ' AND pm2.has_viewed = true' : '';
     $sql = 'SELECT m.winner_id, m.type, m.player_match1_id, p1.id as player1Id, m.player_match2_id, p2.id as player2Id
         FROM bus_match m
         JOIN bus_player_match pm1 ON pm1.id = m.player_match1_id
         JOIN bus_player_match pm2 ON pm2.id = m.player_match2_id
         JOIN bus_player p1 ON p1.id = pm1.player_id
         JOIN bus_player p2 ON p2.id = pm2.player_id
         WHERE m.status = ' . MatchStatus::FINISHED . '
         AND (
             (pm1.player_id = ' . $playerId . $hasViewed1 . ')
             OR
             (pm2.player_id = ' . $playerId . $hasViewed2 . ')
         )';
     $db = new Util\Data();
     $result = $db->select($sql);
     if (count($result) == 0) {
         return $stats;
     }
     while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
         if ($playerId == $row['player1Id'] && $row['winner_id'] == $row['player_match1_id'] || $playerId == $row['player2Id'] && $row['winner_id'] == $row['player_match2_id']) {
             switch ($row['type']) {
                 case MatchType::PRACTICE:
                     $stats['winP']++;
                     break;
                 case MatchType::LEAGUE:
                     $stats['winL']++;
                     break;
                 case MatchType::TOURNAMENT:
                     $stats['winT']++;
                     break;
             }
         } else {
             switch ($row['type']) {
                 case MatchType::PRACTICE:
                     $stats['lossP']++;
                     break;
                 case MatchType::LEAGUE:
                     $stats['lossL']++;
                     break;
                 case MatchType::TOURNAMENT:
                     $stats['lossT']++;
                     break;
             }
         }
     }
     $stats['win'] = $stats['winL'] + $stats['winT'];
     $stats['loss'] = $stats['lossL'] + $stats['lossT'];
     $stats['total'] = $stats['win'] + $stats['loss'];
     $stats['totalP'] = $stats['winP'] + $stats['lossP'];
     $stats['totalL'] = $stats['winL'] + $stats['lossL'];
     $stats['totalT'] = $stats['winT'] + $stats['lossT'];
     return $stats;
 }