Exemplo n.º 1
0
 /**
  * Delete team in player's history
  *
  * @param  none
  * @return string
  */
 public function delete_player_history_team()
 {
     global $wpdb;
     $db = new PHPLeague_Database();
     $id_player_team = (int) $_POST['id_player_team'];
     $db->delete_player_history_team($id_player_team);
     $db->delete_player_team_data($id_player_team);
     _e('Team deleted successfully from the player history with all the data associated.', 'phpleague');
     die;
 }
Exemplo n.º 2
0
 /**
  * Widget method
  *
  * @param  mixed $args
  * @param  mixed $instance
  * @return void
  */
 public function widget($args, $instance)
 {
     // PHPLeague_Database
     $db = new PHPLeague_Database();
     // Extract arguments
     extract($args);
     // Get the league ID
     $league = !empty($instance['league_id']) ? (int) $instance['league_id'] : 1;
     // Show what we want before the widget...
     echo $before_widget;
     // Widget title
     $title = $db->return_league_name($league);
     // Display title if not null
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     // Display the ranking table
     if ($league) {
         $front = new PHPLeague_Front();
         echo $front->widget_ranking_table($league);
     }
     // Show what we want after the widget...
     echo $after_widget;
 }
 /**
  * Admin menu generation
  *
  * @param  none
  * @return void
  */
 public static function admin_menu()
 {
     $instance = new PHPLeague_Admin();
     $parent = 'phpleague_overview';
     $user_ID = get_current_user_id();
     $my_clubs = array();
     if ($user_ID != 0) {
         $db = new PHPLeague_Database();
         $my_clubs = $db->get_user_clubs_information($user_ID);
     }
     if (count($my_clubs) > 0 && function_exists('add_menu_page')) {
         add_menu_page(__('Results (PHPLeague)', 'phpleague'), __('My results', 'phpleague'), 'read', 'phpleague_my_results', array($instance, 'admin_page'), plugins_url('assets/img/league.png', dirname(__FILE__)));
     }
     if (function_exists('add_menu_page')) {
         add_menu_page(__('Dashboard (PHPLeague)', 'phpleague'), __('PHPLeague', 'phpleague'), PHPLeague::$access, $parent, array($instance, 'admin_page'), plugins_url('assets/img/league.png', dirname(__FILE__)));
     }
     if (function_exists('add_submenu_page')) {
         add_submenu_page($parent, __('Dashboard (PHPLeague)', 'phpleague'), __('Dashboard', 'phpleague'), PHPLeague::$access, $parent, array($instance, 'admin_page'));
         add_submenu_page($parent, __('Clubs (PHPLeague)', 'phpleague'), __('Clubs', 'phpleague'), PHPLeague::$access, 'phpleague_club', array($instance, 'admin_page'));
         add_submenu_page($parent, __('Players (PHPLeague)', 'phpleague'), __('Players', 'phpleague'), PHPLeague::$access, 'phpleague_player', array($instance, 'admin_page'));
         add_submenu_page($parent, __('About (PHPLeague)', 'phpleague'), __('About', 'phpleague'), PHPLeague::$access, 'phpleague_about', array($instance, 'admin_page'));
     }
 }
 /**
  * Fill-in data in the league table
  *
  * @param  integer  $id_league
  * @param  integer  $start
  * @param  integer  $fixture
  * @param  integer  $nb_clubs
  * @param  integer  $pt_victory
  * @param  integer  $pt_draw
  * @param  integer  $pt_defeat
  * @return object
  */
 public function fill_league_table($id_league, $start, $fixture, $nb_clubs, $sport, $pt_v, $pt_d, $pt_l)
 {
     global $wpdb;
     $self = new PHPLeague_Database();
     // Delete old data
     $wpdb->query("DELETE FROM {$wpdb->table_cache} WHERE id_league = {$id_league}");
     if (!$fixture) {
         $fixture = $nb_clubs * 2 - 2;
     }
     if (!$start) {
         $start = 1;
     }
     // Get settings
     $pt_victory = $pt_v;
     $pt_draw = $pt_d;
     $pt_defeat = $pt_l;
     // Home victory
     $query = "SELECT t_home.id, COUNT(t_home.id) as count_home_id, c.name, SUM(g.goal_home) as g_home, SUM(g.goal_away) as g_away\n                    FROM {$wpdb->team} t_home, {$wpdb->club} c, {$wpdb->match} g, {$wpdb->fixture} d, {$wpdb->league} l\n                    WHERE t_home.id_league = {$id_league}\n                    AND t_home.id_club = c.id\n                    AND t_home.id = g.id_team_home\n                    AND g.goal_home > g.goal_away\n                    AND l.id = d.id_league\n                    AND d.id = g.id_fixture\n                    AND d.number >= {$start}\n                    AND d.number <= {$fixture}\n                    GROUP BY c.name";
     foreach ($wpdb->get_results($wpdb->prepare($query, NULL)) as $row) {
         $name = trim($row->name);
         $table[$name]['home_v'] = $row->count_home_id;
         if (!isset($table[$name]['home_g_for'])) {
             $table[$name]['home_g_for'] = $row->g_home;
         } else {
             $table[$name]['home_g_for'] += $row->g_home;
         }
         if (!isset($table[$name]['home_g_against'])) {
             $table[$name]['home_g_against'] = $row->g_away;
         } else {
             $table[$name]['home_g_against'] += $row->g_away;
         }
     }
     // Home defeat
     $query = "SELECT t_home.id, COUNT(t_home.id) as count_home_id, c.name, SUM(g.goal_home) as g_home, SUM(g.goal_away) as g_away\n                    FROM {$wpdb->team} t_home, {$wpdb->club} c, {$wpdb->match} g, {$wpdb->fixture} d, {$wpdb->league} l\n                    WHERE t_home.id_league = {$id_league}\n                    AND t_home.id_club = c.id\n                    AND t_home.id = g.id_team_home\n                    AND g.goal_home < g.goal_away\n                    AND l.id = d.id_league\n                    AND d.id = g.id_fixture\n                    AND d.number >= {$start}\n                    AND d.number <= {$fixture}\n                    GROUP BY c.name";
     foreach ($wpdb->get_results($wpdb->prepare($query, NULL)) as $row) {
         $name = trim($row->name);
         $table[$name]['home_l'] = $row->count_home_id;
         if (!isset($table[$name]['home_g_for'])) {
             $table[$name]['home_g_for'] = $row->g_home;
         } else {
             $table[$name]['home_g_for'] += $row->g_home;
         }
         if (!isset($table[$name]['home_g_against'])) {
             $table[$name]['home_g_against'] = $row->g_away;
         } else {
             $table[$name]['home_g_against'] += $row->g_away;
         }
     }
     // Home draw
     $query = "SELECT t_home.id, COUNT(t_home.id) as count_home_id, c.name, SUM(g.goal_home) as g_home, SUM(g.goal_away) as g_away\n                    FROM {$wpdb->team} t_home, {$wpdb->club} c, {$wpdb->match} g, {$wpdb->fixture} d, {$wpdb->league} l\n                    WHERE t_home.id_league = {$id_league}\n                    AND t_home.id_club = c.id\n                    AND t_home.id = g.id_team_home\n                    AND g.goal_home = g.goal_away\n                    AND g.goal_home IS NOT NULL\n                    AND g.goal_away IS NOT NULL\n                    AND l.id = d.id_league\n                    AND d.id = g.id_fixture\n                    AND d.number >= {$start}\n                    AND d.number <= {$fixture}\n                    GROUP BY c.name";
     foreach ($wpdb->get_results($wpdb->prepare($query, NULL)) as $row) {
         $name = trim($row->name);
         $table[$name]['home_d'] = $row->count_home_id;
         if (!isset($table[$name]['home_g_for'])) {
             $table[$name]['home_g_for'] = $row->g_home;
         } else {
             $table[$name]['home_g_for'] += $row->g_home;
         }
         if (!isset($table[$name]['home_g_against'])) {
             $table[$name]['home_g_against'] = $row->g_away;
         } else {
             $table[$name]['home_g_against'] += $row->g_away;
         }
     }
     // Away victory
     $query = "SELECT t_away.id, COUNT(t_away.id) as count_away_id, c.name, SUM(g.goal_home) as g_home, SUM(g.goal_away) as g_away\n                    FROM {$wpdb->team} t_away, {$wpdb->club} c, {$wpdb->match} g, {$wpdb->fixture} d, {$wpdb->league} l\n                    WHERE t_away.id_league = {$id_league}\n                    AND t_away.id_club = c.id\n                    AND t_away.id = g.id_team_away\n                    AND g.goal_away > g.goal_home\n                    AND l.id = d.id_league\n                    AND d.id = g.id_fixture\n                    AND d.number >= {$start}\n                    AND d.number <= {$fixture}\n                    GROUP BY c.name";
     foreach ($wpdb->get_results($wpdb->prepare($query, NULL)) as $row) {
         $name = trim($row->name);
         $table[$name]['away_v'] = $row->count_away_id;
         if (!isset($table[$name]['away_g_for'])) {
             $table[$name]['away_g_for'] = $row->g_away;
         } else {
             $table[$name]['away_g_for'] += $row->g_away;
         }
         if (!isset($table[$name]['away_g_against'])) {
             $table[$name]['away_g_against'] = $row->g_home;
         } else {
             $table[$name]['away_g_against'] += $row->g_home;
         }
     }
     // Away defeat
     $query = "SELECT t_away.id, COUNT(t_away.id) as count_away_id, c.name, SUM(g.goal_home) as g_home, SUM(g.goal_away) as g_away\n                    FROM {$wpdb->team} t_away, {$wpdb->club} c, {$wpdb->match} g, {$wpdb->fixture} d, {$wpdb->league} l\n                    WHERE t_away.id_league = {$id_league}\n                    AND t_away.id_club = c.id\n                    AND t_away.id = g.id_team_away\n                    AND g.goal_away < g.goal_home\n                    AND l.id = d.id_league\n                    AND d.id = g.id_fixture\n                    AND d.number >= {$start}\n                    AND d.number <= {$fixture}\n                    GROUP BY c.name";
     foreach ($wpdb->get_results($wpdb->prepare($query, NULL)) as $row) {
         $name = trim($row->name);
         $table[$name]['away_l'] = $row->count_away_id;
         if (!isset($table[$name]['away_g_for'])) {
             $table[$name]['away_g_for'] = $row->g_away;
         } else {
             $table[$name]['away_g_for'] += $row->g_away;
         }
         if (!isset($table[$name]['away_g_against'])) {
             $table[$name]['away_g_against'] = $row->g_home;
         } else {
             $table[$name]['away_g_against'] += $row->g_home;
         }
     }
     // Away draw
     $query = "SELECT t_away.id, COUNT(t_away.id) as count_away_id, c.name, SUM(g.goal_home) as g_home, SUM(g.goal_away) as g_away\n                    FROM {$wpdb->team} t_away, {$wpdb->club} c, {$wpdb->match} g, {$wpdb->fixture} d, {$wpdb->league} l\n                    WHERE t_away.id_league = {$id_league}\n                    AND t_away.id_club = c.id\n                    AND t_away.id = g.id_team_away\n                    AND g.goal_away = g.goal_home\n                    AND g.goal_away IS NOT NULL\n                    AND g.goal_home IS NOT NULL\n                    AND l.id = d.id_league\n                    AND d.id = g.id_fixture\n                    AND d.number >= {$start}\n                    AND d.number <= {$fixture}\n                    GROUP BY c.name";
     foreach ($wpdb->get_results($wpdb->prepare($query, NULL)) as $row) {
         $name = trim($row->name);
         $table[$name]['away_d'] = $row->count_away_id;
         if (!isset($table[$name]['away_g_for'])) {
             $table[$name]['away_g_for'] = $row->g_away;
         } else {
             $table[$name]['away_g_for'] += $row->g_away;
         }
         if (!isset($table[$name]['away_g_against'])) {
             $table[$name]['away_g_against'] = $row->g_home;
         } else {
             $table[$name]['away_g_against'] += $row->g_home;
         }
     }
     // Get all the data we need to fill in the table
     foreach ($self->get_teams_information_table($id_league) as $row) {
         $name = trim($row->name);
         $home_victory = isset($table[$name]['home_v']) ? $table[$name]['home_v'] : '';
         $home_draw = isset($table[$name]['home_d']) ? $table[$name]['home_d'] : '';
         $home_defeat = isset($table[$name]['home_l']) ? $table[$name]['home_l'] : '';
         $away_victory = isset($table[$name]['away_v']) ? $table[$name]['away_v'] : '';
         $away_draw = isset($table[$name]['away_d']) ? $table[$name]['away_d'] : '';
         $away_defeat = isset($table[$name]['away_l']) ? $table[$name]['away_l'] : '';
         $away_g_for = isset($table[$name]['away_g_for']) ? $table[$name]['away_g_for'] : '';
         $home_g_for = isset($table[$name]['home_g_for']) ? $table[$name]['home_g_for'] : '';
         $away_g_aga = isset($table[$name]['away_g_against']) ? $table[$name]['away_g_against'] : '';
         $home_g_aga = isset($table[$name]['home_g_against']) ? $table[$name]['home_g_against'] : '';
         $home_played = $home_victory + $home_draw + $home_defeat;
         $away_played = $away_victory + $away_draw + $away_defeat;
         $played = $home_played + $away_played;
         $home_pts = $home_victory * $pt_victory + $home_draw * $pt_draw + $home_defeat * $pt_defeat;
         $away_pts = $away_victory * $pt_victory + $away_draw * $pt_draw + $away_defeat * $pt_defeat;
         $points = $home_pts + $away_pts + $row->penalty;
         $nb_victory = $home_victory + $away_victory;
         $nb_draw = $home_draw + $away_draw;
         $nb_defeat = $home_defeat + $away_defeat;
         $home_v = $home_victory;
         $home_d = $home_draw;
         $home_l = $home_defeat;
         $away_v = $away_victory;
         $away_d = $away_draw;
         $away_l = $away_defeat;
         $goal_for = $away_g_for + $home_g_for;
         $home_g_for = $home_g_for;
         $away_g_for = $away_g_for;
         $goal_against = $home_g_aga + $away_g_aga;
         $home_g_against = $home_g_aga;
         $away_g_against = $away_g_aga;
         $diff = $goal_for - $goal_against;
         $home_diff = $home_g_for - $home_g_against;
         $away_diff = $away_g_for - $away_g_against;
         $wpdb->insert($wpdb->table_cache, array('club_name' => $name, 'id_team' => $row->team_id, 'id_league' => $id_league, 'points' => $points, 'home_points' => $home_pts, 'away_points' => $away_pts, 'played' => $played, 'home_played' => $home_played, 'away_played' => $away_played, 'victory' => $nb_victory, 'draw' => $nb_draw, 'defeat' => $nb_defeat, 'home_v' => $home_v, 'home_d' => $home_d, 'home_l' => $home_l, 'away_v' => $away_v, 'away_d' => $away_d, 'away_l' => $away_l, 'goal_for' => $goal_for, 'goal_against' => $goal_against, 'home_g_for' => $home_g_for, 'home_g_against' => $home_g_against, 'away_g_for' => $away_g_for, 'away_g_against' => $away_g_against, 'diff' => $diff, 'home_diff' => $home_diff, 'away_diff' => $away_diff, 'pen' => $row->penalty), array('%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d'));
     }
 }
 /**
  * Show the league ranking as widget.
  *
  * @param  integer $id_league
  * @return string
  */
 public function widget_ranking_table($id_league)
 {
     global $wpdb;
     $db = new PHPLeague_Database();
     // League not found in the database
     if ($db->is_league_exists($id_league) === FALSE) {
         return;
     }
     $setting = $db->get_league_settings($id_league);
     $nb_teams = (int) $setting->nb_teams;
     $favorite = (int) $setting->id_favorite;
     $output = '<table id="phpleague"><thead><tr>
                 <th class="centered">' . __('Pos', 'phpleague') . '</th>
                 <th>' . __('Team', 'phpleague') . '</th>
                 <th class="centered">' . __('Pts', 'phpleague') . '</th>
                 <th class="centered">' . __('P', 'phpleague') . '</th>
                 <th class="centered">' . __('+/-', 'phpleague') . '</th></tr></thead><tbody>';
     $place = 1;
     foreach ($db->get_league_table_data('general', $id_league, $nb_teams) as $row) {
         if ($place <= $nb_teams) {
             if ($favorite == $row->id_team) {
                 $output .= '<tr class="id-favorite">';
             } else {
                 $output .= '<tr>';
             }
             $points = (int) $row->points;
             $played = (int) $row->played;
             $diff = (int) $row->diff;
             $output .= '<td class="centered">' . $place . '</td>';
             $output .= '<td>' . esc_html($row->club_name) . '</td>';
             $output .= '<td class="centered">' . $points . '</td>';
             $output .= '<td class="centered">' . $played . '</td>';
             $output .= '<td class="centered">' . $diff . '</td></tr>';
             $place++;
         }
     }
     $output .= '</tbody></table>';
     return $output;
 }
Exemplo n.º 6
0
 public function results_table($id_league)
 {
     global $wpdb;
     $db = new PHPLeague_Database();
     // Prepare results
     $results = array();
     foreach ($db->get_fixtures_by_league($id_league) as $row) {
         if (!isset($results[$row->id_team_home])) {
             $results[$row->id_team_home] = new PHPLeague_Volley_Result($row->id_team_home, $row->home_name);
         }
         if (!isset($results[$row->id_team_away])) {
             $results[$row->id_team_away] = new PHPLeague_Volley_Result($row->id_team_away, $row->away_name);
         }
         $home = $results[$row->id_team_home];
         $this->add_result($home, $row, true);
         $away = $results[$row->id_team_away];
         $this->add_result($away, $row, false);
     }
     $ranking = $this->sort_results($results);
     // Display
     $output = '<table id="phpleague" class="volley-results"><thead><tr>' . '<th class="centered" rowspan="2">' . __('Pos', 'phpleague') . '</th>' . '<th rowspan="2">' . __('Team', 'phpleague') . '</th>' . '<th class="centered" rowspan="2">' . __('Pts', 'phpleague') . '</th>' . '<th class="centered" rowspan="2">' . __('P', 'phpleague') . '</th>' . '<th class="centered" colspan="3">' . __('W', 'phpleague') . '</th>' . '<th class="centered" colspan="3">' . __('L', 'phpleague') . '</th>' . '<th class="centered" rowspan="2">' . __('Forfeits', 'phpleague') . '</th>' . '<th class="centered" rowspan="2">' . __('Won sets', 'phpleague') . '</th>' . '<th class="centered" rowspan="2">' . __('Lost sets', 'phpleague') . '</th>' . '<th class="centered" rowspan="2">' . __('+/-', 'phpleague') . '</th>' . '</tr><tr>' . '<th>3-0</th><th>3-1</th><th>3-2</th><th>3-0</th><th>3-1</th><th>3-2</th>' . '</tr></thead><tbody>';
     for ($i = 0; $i < count($ranking); $i++) {
         $result = $ranking[$i];
         $output .= '<tr>';
         $output .= '<td class="header">' . ($i + 1) . '</td>';
         $output .= '<td class="header">' . $result->team_name . '</td>';
         $output .= '<td class="strong">' . $result->points . '</td>';
         $output .= '<td>' . $result->played . '</td>';
         $output .= '<td>' . $result->won3_0 . '</td>';
         $output .= '<td>' . $result->won3_1 . '</td>';
         $output .= '<td>' . $result->won3_2 . '</td>';
         $output .= '<td>' . $result->lost3_0 . '</td>';
         $output .= '<td>' . $result->lost3_1 . '</td>';
         $output .= '<td>' . $result->lost3_2 . '</td>';
         $output .= '<td>' . $result->forfeits . '</td>';
         $output .= '<td>' . $result->get_won_sets() . '</td>';
         $output .= '<td>' . $result->get_lost_sets() . '</td>';
         $output .= '<td class="strong">' . $result->get_sets_advantage() . '</td>';
         $output .= '</tr>';
     }
     $output .= '</tbody></table>';
     return $output;
 }
Exemplo n.º 7
0
/*
 * This file is part of the PHPLeague package.
 *
 * (c) Maxime Dizerens <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
define("FORFEIT_INPUT", "/");
// Get leagues for user
$user_ID = get_current_user_id();
$my_clubs = array();
$my_club_ids = array();
if ($user_ID != 0) {
    $db = new PHPLeague_Database();
    $clubs = $db->get_user_clubs_information($user_ID);
    foreach ($clubs as $club) {
        $my_clubs[] = $club;
    }
}
$leagues = $db->get_every_league(0, $db->count_leagues());
$my_leagues = array();
foreach ($leagues as $league) {
    foreach ($my_clubs as $club) {
        if (!$db->is_club_already_in_league($league->id, $club->id)) {
            // is_club_already_in_league returns false when in league
            $my_leagues[] = $league;
            break;
        }
    }