示例#1
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;
 }
 /**
  * Show the league fixtures.
  * Also possible to show only for one particular team.
  *
  * @param  integer $id_league
  * @param  integer $id_team
  * @return string
  */
 public function get_league_fixtures($id_league, $id_team = NULL)
 {
     global $wpdb;
     $db = new PHPLeague_Database();
     // League not found in the database
     if ($db->is_league_exists((int) $id_league) === FALSE) {
         return;
     }
     $fixtures = $db->get_fixtures_league($id_league);
     // We got a team...
     if (isset($id_team) && $db->is_team_already_in_league($id_league, $id_team) === FALSE) {
         $output = '<table id="phpleague" class="team-fixtures-table"><tbody><tr>' . '<th class="centered">' . __('Fixture', 'phpleague') . '</th>' . '<th class="centered">' . __('Date', 'phpleague') . '</th>' . '<th class="centered">' . __('Match', 'phpleague') . '</th>' . '<th class="centered">' . __('Score', 'phpleague') . '</th></tr>';
         foreach ($db->get_fixtures_by_team((int) $id_team, (int) $id_league) as $row) {
             $fixture = $fixtures[$row->number - 1];
             $current_num = $row->number;
             $date = DateTime::createFromFormat("Y-m-d", $fixture->scheduled);
             $start_date = DateTime::createFromFormat("Y-m-d", $fixture->scheduled);
             $end_date = DateTime::createFromFormat("Y-m-d", $fixture->scheduled);
             $day_of_week = (int) date("w", $date->getTimestamp());
             $start_date->sub(new DateInterval("P" . ($day_of_week - 1) . "D"));
             $end_date->add(new DateInterval("P" . (7 - $day_of_week) . "D"));
             $output .= '<tr>';
             $output .= '<td class="centered">' . (int) $row->number . '</td>';
             $output .= '<td>' . date_i18n(get_option('date_format'), $start_date->getTimestamp()) . " - " . date_i18n(get_option('date_format'), $end_date->getTimestamp()) . '</td>';
             $output .= '<td>' . esc_html($row->home_name) . ' - ' . esc_html($row->away_name) . '</td>';
             if (date('Y-m-d') >= $row->played) {
                 $output .= '<td class="centered">' . $row->goal_home . ' - ' . $row->goal_away . '</td>';
             } else {
                 $output .= '<td class="centered"> - </td>';
             }
             $output .= '</tr>';
         }
     } else {
         $current_num = NULL;
         foreach ($db->get_fixtures_by_league((int) $id_league) as $row) {
             if ($current_num != $row->number) {
                 if ($curent_num != NULL) {
                     $output .= '</tbody></table>';
                 }
                 $fixture = $fixtures[$row->number - 1];
                 $current_num = $row->number;
                 // Display header
                 $date = DateTime::createFromFormat("Y-m-d", $fixture->scheduled);
                 $start_date = DateTime::createFromFormat("Y-m-d", $fixture->scheduled);
                 $end_date = DateTime::createFromFormat("Y-m-d", $fixture->scheduled);
                 $day_of_week = (int) date("w", $date->getTimestamp());
                 $start_date->sub(new DateInterval("P" . ($day_of_week - 1) . "D"));
                 $end_date->add(new DateInterval("P" . (7 - $day_of_week) . "D"));
                 $output .= '<table id="phpleague" class="fixtures-table"><tbody><tr>' . '<th colspan="3">' . __('Fixture', 'phpleague') . ' ' . (int) $row->number . ' (' . date_i18n(get_option('date_format'), $start_date->getTimestamp()) . " - " . date_i18n(get_option('date_format'), $end_date->getTimestamp()) . ')</th>';
                 $output .= '</tr>';
             }
             $output .= '<tr>';
             $output .= '<td class="right">' . esc_html($row->home_name) . '</td>';
             //if (date('Y-m-d') >= $row->played)
             $output .= '<td class="centered">' . $row->goal_home . ' - ' . $row->goal_away . '</td>';
             //else
             //    $output .= '<td class="centered"> - </td>';
             $output .= '<td class="left">' . esc_html($row->away_name) . '</td>';
             $output .= '</tr>';
         }
     }
     $output .= '</tbody></table>';
     return $output;
 }
 /**
  * Show the league fixtures.
  * Also possible to show only for one particular team.
  *
  * @param  integer $id_league
  * @param  integer $id_team
  * @return string
  */
 public function get_league_fixtures($id_league, $id_team = NULL)
 {
     global $wpdb;
     $db = new PHPLeague_Database();
     // League not found in the database
     if ($db->is_league_exists((int) $id_league) === FALSE) {
         return;
     }
     $output = '<table id="phpleague"><tbody><tr>' . '<th>' . __('Date', 'phpleague') . '</th>' . '<th class="centered">' . __('Fixture', 'phpleague') . '</th>' . '<th>' . __('Match', 'phpleague') . '</th>' . '<th class="centered">' . __('Score', 'phpleague') . '</th></tr>';
     // We got a team...
     if (isset($id_team) && $db->is_team_already_in_league($id_league, $id_team) === FALSE) {
         foreach ($db->get_fixtures_by_team((int) $id_team, (int) $id_league) as $row) {
             $output .= '<tr>';
             $output .= '<td>' . strftime("%d.%m.%Y, %H:%M", strtotime($row->played)) . '</td>';
             $output .= '<td class="centered">' . (int) $row->number . '</td>';
             $output .= '<td>' . esc_html($row->home_name) . ' - ' . esc_html($row->away_name) . '</td>';
             if (date('Y-m-d') >= $row->played) {
                 $output .= '<td class="centered">' . $row->goal_home . ' - ' . $row->goal_away . '</td>';
             } else {
                 $output .= '<td class="centered"> - </td>';
             }
             $output .= '</tr>';
         }
     } else {
         foreach ($db->get_fixtures_by_league((int) $id_league) as $row) {
             $output .= '<tr>';
             $output .= '<td>' . strftime("%d.%m.%Y, %H:%M", strtotime($row->played)) . '</td>';
             $output .= '<td class="centered">' . (int) $row->number . '</td>';
             $output .= '<td>' . esc_html($row->home_name) . ' - ' . esc_html($row->away_name) . '</td>';
             if (date('Y-m-d') >= $row->played) {
                 $output .= '<td class="centered">' . $row->goal_home . ' - ' . $row->goal_away . '</td>';
             } else {
                 $output .= '<td class="centered"> - </td>';
             }
             $output .= '</tr>';
         }
     }
     $output .= '</tbody></table>';
     return $output;
 }