Exemple #1
0
 public static function deleteSecure($userId, $type = null)
 {
     $db = new Util\Data();
     if (isset($type)) {
         $query = 'DELETE FROM core_user_security WHERE user_id = ? AND type = ?';
         return $db->execute($query, [$userId, $type]);
     }
     $query = 'DELETE FROM core_user_security WHERE user_id = ?';
     return $db->execute($query, [$userId]);
 }
Exemple #2
0
 public static function clear($code)
 {
     $db = new Util\Data();
     if ($code != 0) {
         $query = 'DELETE FROM core_log WHERE code = ?';
         return $db->execute($query, [$code]);
     }
     $query = 'DELETE FROM core_log ORDER BY id DESC LIMIT 200';
     return $db->execute($query);
 }
Exemple #3
0
 public static function savePassword(\Rebond\Core\User\Model $user)
 {
     Util\Log::log(Util\Error::PASSWORD_CHANGE, $user->getId(), __FILE__, __LINE__);
     $db = new Util\Data();
     $query = 'UPDATE core_user SET password = ?, modified_date = ? WHERE id = ?';
     return $db->execute($query, [$user->getPassword(), Util\Format::date(time(), 'sqlDatetime'), $user->getId()]);
 }
Exemple #4
0
 private static function loadFriendlyUrl($pageId)
 {
     $db = new Util\Data();
     $query = 'SELECT p.id, p.friendly_url, p.friendly_url_path
         FROM cms_page p
         WHERE p.id = ?';
     return $db->execute($query, [$pageId]);
 }
Exemple #5
0
 /**
  * Delete Book by sequence 
  * @param int $sequence
  * @return int
  */
 public static function deleteBySequence($sequence)
 {
     if ($sequence == 0) {
         return 0;
     }
     $db = new Util\Data();
     $query = 'DELETE FROM bus_book WHERE sequence = ? AND booking_date > NOW()';
     return $db->execute($query, [$sequence]);
 }
Exemple #6
0
 public static function updateIsInMatchPlayers($tournament)
 {
     $db = new Util\Data();
     $playerIds = [];
     foreach ($tournament->getTournamentPlayers() as $tp) {
         $playerIds[] = $tp->getPlayerId();
     }
     if (count($playerIds) == 0) {
         return;
     }
     $sql = 'UPDATE bus_player SET is_in_match = true, is_in_tournament = true WHERE id IN (' . implode(',', $playerIds) . ')';
     $db->execute($sql);
 }
Exemple #7
0
 public static function deleteByPublisherId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM cms_content WHERE publisher_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #8
0
 public static function deleteByModuleId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM cms_module_media WHERE module_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #9
0
 public static function removeAndAddPlayer()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username']);
     $options['where'][] = 'player.user_id = 0';
     $options['where'][] = 'player.active = 1';
     $players = \Own\Bus\Player\Data::loadAll($options);
     if (count($players) > 0) {
         $db = new Util\Data();
         $pick = \Own\Bus\Engine::dice(0, count($players) - 1);
         $remove = 'UPDATE bus_player SET active = 0 WHERE id = ' . $players[$pick]->getId();
         $db->execute($remove);
         Util\Log::log(Util\Code::CRON, 'player retired: ' . $players[$pick]->getUsername() . ' (' . $players[$pick]->getId() . ')', __FILE__, __LINE__);
         $leagues = \Own\Bus\League\Data::loadAll();
         $player = new \Own\Bus\Player\Model();
         $player->setRandom(1);
         $player->setActive(true);
         if (count($leagues) > 0) {
             $player->setLeagueId(\Own\Bus\Engine::findLeague($leagues, 1));
         }
         $player->save();
         Util\Log::log(Util\Code::CRON, 'new player: ' . $player->getUsername() . ' (' . $player->getId() . ')', __FILE__, __LINE__);
     }
 }
Exemple #10
0
 public static function deleteByParentId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM core_folder WHERE parent_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #11
0
 public static function cleanHasViewed()
 {
     $query = 'UPDATE bus_player_match SET has_viewed = 1 WHERE has_viewed = 0 AND modified_date < NOW() - INTERVAL ? HOUR';
     $db = new Util\Data();
     return $db->execute($query, [\Own\Bus\Engine::DAY * 7]);
 }
Exemple #12
0
 public static function clean()
 {
     $sql = 'DELETE FROM bus_notification WHERE has_read = 1 AND created_date < NOW() - INTERVAL ? HOUR';
     $db = new Util\Data();
     return $db->execute($sql, [\Own\Bus\Engine::DAY * 56]);
 }
Exemple #13
0
 public static function deleteByRoleId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM core_user_role WHERE role_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #14
0
 public static function clearFilter($filterId)
 {
     $query = 'UPDATE cms_content SET filter_id = 0 WHERE filter_id = ?';
     $db = new Util\Data();
     return $db->execute($query, [$filterId]);
 }
Exemple #15
0
 public static function deleteOldMatches()
 {
     $db = new Util\Data();
     $query = 'DELETE FROM bus_log WHERE match_id IN (SELECT id FROM bus_match WHERE modified_date < NOW() - INTERVAL ? HOUR)';
     return $db->execute($query, [\Own\Bus\Engine::DAY * 7]);
 }
Exemple #16
0
 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']);
         }
     }
 }
Exemple #17
0
 public static function updateGameplayBatch()
 {
     $db = new Util\Data();
     $query = 'UPDATE bus_player SET
         gameplay = gameplay + ROUND((300 + (CAST(adaptation AS SIGNED) * 50) - CAST(gameplay AS SIGNED)) / 100),
         last_gameplay_update = NOW()
     WHERE active = 1
     AND last_gameplay_update < NOW() - INTERVAL ' . Engine::DAY * 60 / 10 . ' MINUTE';
     return $db->execute($query);
 }
Exemple #18
0
 private function addBookings(array $bookings)
 {
     $sql = "INSERT INTO bus_book (sequence, court_id, type, player1_id, player2_id, booking_date, title, color, guest, pay) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0)";
     $count = 0;
     $bookingsCount = count($bookings);
     $db = new Util\Data();
     for ($t = 0; $t < $bookingsCount; $t++) {
         $time = explode(':', $bookings[$t][0]['time']);
         $bookingDate = $this->date;
         $bookingDate->setTime($time[0], $time[1], 0);
         $bookingDate = $bookingDate->format('Y-m-d H:i:s');
         for ($c = 1; $c < count($bookings[$t]); $c++) {
             if (isset($bookings[$t][$c]['players'])) {
                 $playerIds = $bookings[$t][$c]['players'];
                 $type = BookingType::PARTNER;
                 $playerIds[1] = $playerIds[1] != 0 ? $playerIds[1] : 1;
                 if ($playerIds[1] == 0) {
                     // guest
                     $type = BookingType::GUEST;
                 }
                 $db->execute($sql, ['', $bookings[$t][$c]['court'], $type, $playerIds[0], $playerIds[1], $bookingDate, '', '', '']);
                 $count++;
             } else {
                 if (isset($bookings[$t][$c]['text'])) {
                     $text = $bookings[$t][$c]['text'];
                     if (strcasecmp($text, 'ledig') != 0 && $text != '') {
                         $color = $this->renderColor($text);
                         $db->execute($sql, [uniqid(), $bookings[$t][$c]['court'], BookingType::ADMIN, 0, 0, $bookingDate, $text, $color, '']);
                         $count++;
                     }
                 } else {
                     echo 'nope';
                     exit;
                     // should not happen
                 }
             }
         }
     }
     return $count . ' bookings added. (' . $bookingsCount * (count($bookings[0]) - 1) . ')';
 }
Exemple #19
0
 public static function deleteById($contentId)
 {
     if ($contentId === 0) {
         return 0;
     }
     $query = 'DELETE FROM app_standard WHERE app_id = ?';
     $db = new Util\Data();
     return $db->execute($query, [$contentId]);
 }
Exemple #20
0
 public static function updateSurfaceBatch()
 {
     $db = new Util\Data();
     $query = 'UPDATE bus_league SET surface = FLOOR(RAND() * 3) + 1';
     return $db->execute($query);
 }
Exemple #21
0
 public static function deleteByFilterId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM cms_gadget WHERE filter_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #22
0
 public static function deleteByPermissionId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM core_role_permission WHERE permission_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #23
0
 public static function deleteByUserId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM core_log WHERE user_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #24
0
 public static function deleteByLayoutId($id)
 {
     $db = new Util\Data();
     $query = 'DELETE FROM cms_page WHERE layout_id = ?';
     return $db->execute($query, [$id]);
 }
Exemple #25
0
 public static function deleteById($id)
 {
     if ($id === 0) {
         return 0;
     }
     $query = 'DELETE FROM core_user WHERE id = ?';
     $db = new Util\Data();
     return $db->execute($query, [$id]);
 }
Exemple #26
0
 public static function moveToRoot($folderId)
 {
     $query = 'UPDATE core_media SET folder_id = 1 WHERE folder_id = ?';
     $db = new Util\Data();
     return $db->execute($query, [$folderId]);
 }