Пример #1
0
    static function get_match($args)
    {
        global $wpdb;
        $defaults = array('from_date' => 0, 'id' => false, 'game_id' => false, 'sum_tickets' => false, 'limit' => 0, 'offset' => 0, 'orderby' => 'id', 'order' => 'asc');
        $args = \WP_Clanwars\Utils::extract_args($args, $defaults);
        extract($args);
        $where_query = '';
        $limit_query = '';
        $order_query = '';
        $order = strtolower($order);
        if ($order != 'asc' && $order != 'desc') {
            $order = 'asc';
        }
        $order_query = 'ORDER BY t1.`' . $orderby . '` ' . $order;
        if ($id != 'all' && $id !== false) {
            if (!is_array($id)) {
                $id = array($id);
            }
            $id = array_map('intval', $id);
            $where_query[] = 't1.id IN (' . join(', ', $id) . ')';
        }
        if ($game_id != 'all' && $game_id !== false) {
            if (!is_array($game_id)) {
                $game_id = array($game_id);
            }
            $game_id = array_map('intval', $game_id);
            $where_query[] = 't1.game_id IN (' . join(', ', $game_id) . ')';
        }
        if ($from_date > 0) {
            $where_query[] = 't1.date >= FROM_UNIXTIME(' . intval($from_date) . ')';
        }
        if ($limit > 0) {
            $limit_query = $wpdb->prepare('LIMIT %d, %d', $offset, $limit);
        }
        if (!empty($where_query)) {
            $where_query = 'WHERE ' . join(' AND ', $where_query);
        }
        $rounds_table = \WP_Clanwars\Rounds::table();
        $games_table = \WP_Clanwars\Games::table();
        $teams_table = \WP_Clanwars\Teams::table();
        $matches_table = static::table();
        if ($sum_tickets) {
            $subquery = <<<SQL
\t
\t\t\t(
\t\t\t\tSELECT SUM(sumt1.tickets1) 
\t\t\t\tFROM `{$rounds_table}` AS sumt1 
\t\t\t\tWHERE sumt1.match_id = t1.id
\t\t\t) AS team1_tickets,

\t\t\t(
\t\t\t\tSELECT SUM(sumt2.tickets2) 
\t\t\t\tFROM `{$rounds_table}` AS sumt2 
\t\t\t\tWHERE sumt2.match_id = t1.id
\t\t\t) AS team2_tickets

SQL;
            $subquery = trim($subquery);
        } else {
            $subquery = 'NULL';
        }
        $query = <<<SQL

\t\tSELECT
\t\t\tt1.*, 
\t\t\tt2.title AS game_title, 
\t\t\tt2.abbr AS game_abbr, 
\t\t\tt2.icon AS game_icon,
\t\t\ttt1.title AS team1_title, 
\t\t\ttt2.title AS team2_title,
\t\t\ttt1.country AS team1_country, 
\t\t\ttt2.country AS team2_country,
\t\t\t{$subquery}

\t\tFROM `{$matches_table}` AS t1
\t\t\tLEFT JOIN `{$games_table}` AS t2 ON t1.game_id = t2.id
\t\t\tLEFT JOIN `{$teams_table}` AS tt1 ON t1.team1 = tt1.id
\t\t\tLEFT JOIN `{$teams_table}` AS tt2 ON t1.team2 = tt2.id

\t\t{$where_query}
\t\t{$order_query}
\t\t{$limit_query}

SQL;
        return \WP_Clanwars\DB::get_results($query);
    }
Пример #2
0
 public function on_uninstall()
 {
     global $wpdb;
     delete_option(WP_CLANWARS_CATEGORY);
     delete_option(WP_CLANWARS_DEFAULTCSS);
     \WP_Clanwars\ACL::destroy();
     $tables = array();
     array_push(\WP_Clanwars\Games::table());
     array_push(\WP_Clanwars\Maps::table());
     array_push(\WP_Clanwars\Rounds::table());
     array_push(\WP_Clanwars\Matches::table());
     array_push(\WP_Clanwars\Teams::table());
     foreach ($tables as $table) {
         $wpdb->query("DROP TABLE `{$table}`");
     }
 }
Пример #3
0
 static function most_popular_countries()
 {
     global $wpdb;
     static $cache = false;
     $limit = 10;
     if ($cache !== false) {
         return $cache;
     }
     $teams_table = \WP_Clanwars\Teams::table();
     $matches_table = \WP_Clanwars\Matches::table();
     $query = $wpdb->prepare("(SELECT t1.country, COUNT(t2.id) AS cnt\n\t\t\tFROM {$teams_table} AS t1, {$matches_table} AS t2\n\t\t\tWHERE t1.id = t2.team1\n\t\t\tGROUP BY t1.country\n\t\t\tLIMIT %d)\n\t\t\tUNION\n\t\t\t(SELECT t1.country, COUNT(t2.id) AS cnt\n\t\t\tFROM {$teams_table} AS t1, {$matches_table} AS t2\n\t\t\tWHERE t1.id = t2.team2\n\t\t\tGROUP BY t1.country\n\t\t\tLIMIT %d)\n\t\t\tORDER BY cnt DESC\n\t\t\tLIMIT %d", $limit, $limit, $limit);
     $cache = $wpdb->get_results($query, ARRAY_A);
     return $cache;
 }