/**
  * 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;
 }
예제 #2
0
 /**
  * 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;
 }