Beispiel #1
0
 /**
  * Function to display League Matches
  *
  *	[matches league_id="1" mode="all|home|racing" template="name" roster=ID]
  *
  * - league_id is the ID of league
  * - league_name: get league by name and not ID (optional)
  * - mode can be either "all" or "home". For racing it must be "racing". If it is not specified the matches are displayed on a weekly basis
  * - season: display specific season (optional)
  * - template is the template used for displaying. Replace name appropriately. Templates must be named "matches-template.php" (optional)
  * - archive: true or false, check if archive page
  * - roster is the ID of individual team member (currently only works with racing)
  * - match_day: specific match day (integer)
  *
  * @param array $atts
  * @return the content
  */
 function showMatches($atts)
 {
     global $leaguemanager, $championship;
     extract(shortcode_atts(array('league_id' => 0, 'league_name' => '', 'team' => 0, 'template' => '', 'mode' => '', 'season' => '', 'limit' => false, 'archive' => false, 'roster' => false, 'order' => false, 'match_day' => false, 'match_date' => false, 'group' => false, 'time' => false, 'dateformat' => '', 'timeformat' => ''), $atts));
     $search = !empty($league_name) ? $league_name : $league_id;
     $league = $leaguemanager->getLeague($search);
     $league_id = $this->league_id = $league->id;
     $leaguemanager->setLeagueId($league_id);
     $match_date = $match_date . " 00:00:00";
     $class = 'alternate';
     if ($league->mode == 'championship') {
         $championship->initialize($league->id);
     }
     if (!$group && isset($_GET['group'])) {
         $group = $_GET['group'];
     }
     if (!isset($_GET['match'])) {
         $season = $leaguemanager->getSeason($league, $season);
         $league->num_match_days = $season['num_match_days'];
         $season = $season['name'];
         $leaguemanager->setSeason($season);
         $league->match_days = (!$match_day && empty($mode) || $mode == 'racing') && !$time && $league->num_match_days > 0 ? true : false;
         $league->isCurrMatchDay = $archive ? false : true;
         if (!$league_id) {
             $teams = $leaguemanager->getTeams("`league_id` != '' AND `season` != ''", "`title` ASC", 'ARRAY');
             $search = "`league_id` != '' AND `season` != '' AND `final` = ''";
         } else {
             $teams = $leaguemanager->getTeams("`league_id` = " . $league_id . " AND `season` = '" . $season . "'", "`title` ASC", 'ARRAY');
             $search = "`league_id` = '" . $league_id . "' AND `season` = '" . $season . "' AND `final` = ''";
         }
         if ($mode != 'racing') {
             // Standard is match day based with team dropdown
             //				if ( empty($mode) ) {
             if (!empty($team) || isset($_GET['team_id']) && !empty($_GET['team_id'])) {
                 $team_id = !empty($team) ? $team : (int) $_GET['team_id'];
             }
             $match_day = $match_day ? $match_day : $leaguemanager->getMatchDay(true);
             if (isset($team_id)) {
                 $search .= " AND ( `home_team`= {$team_id} OR `away_team` = {$team_id} )";
             } elseif ($group) {
                 $search .= " AND `group` = '" . $group . "'";
             } elseif ($league->mode != 'championship' && !$time) {
                 $search .= " AND `match_day` = '" . $match_day . "'";
             }
             //				}
             if ($time) {
                 if ($time == 'next') {
                     $search .= " AND DATEDIFF(NOW(), `date`) <= 0";
                 } elseif ($time == 'prev') {
                     $search .= " AND DATEDIFF(NOW(), `date`) > 0";
                 } elseif ($time == 'prev1') {
                     $search .= " AND DATEDIFF(NOW(), `date`) > 0) AND (`winner_id` != 0) ";
                 } elseif ($time == 'today') {
                     $search .= " AND DATEDIFF(NOW(), `date`) = 0";
                 } elseif ($time == 'day') {
                     $search .= " AND DATEDIFF('" . $match_date . "', `date`) = 0";
                 }
             }
             // Only get Home Teams
             if ($mode == 'home') {
                 $search .= parent::buildHomeOnlyQuery($league_id);
             }
         } else {
             if (isset($_GET['match_day']) && !empty($_GET['match_day'])) {
                 $match_day = (int) $_GET['match_day'];
                 $search .= " AND `match_day` = '" . $match_day . "'";
             } elseif ($match_day) {
                 $search .= " AND `match_day` = '" . $match_day . "'";
             }
         }
         $matches = $leaguemanager->getMatches($search, $limit, $order);
         foreach ($matches as $key => $row) {
             $matchdate[$key] = $row->date;
         }
         if ($time == 'prev1') {
             array_multisort($matchdate, SORT_ASC, $matches);
         }
         $i = 0;
         foreach ($matches as $match) {
             $class = 'alternate' == $class ? '' : 'alternate';
             $matches[$i]->class = $class;
             $matches[$i]->hadPenalty = $match->hadPenalty = isset($match->penalty) && $match->penalty['home'] != '' && $match->penalty['away'] != '' ? true : false;
             $matches[$i]->hadOvertime = $match->hadOvertime = isset($match->overtime) && $match->overtime['home'] != '' && $match->overtime['away'] != '' ? true : false;
             $url = get_permalink();
             $url = add_query_arg('match', $match->id, $url);
             $matches[$i]->pageURL = $url;
             if ($timeformat) {
                 $matches[$i]->start_time = '00' == $match->hour && '00' == $match->minutes ? '' : mysql2date($timeformat, $match->date);
             } else {
                 $matches[$i]->start_time = '00' == $match->hour && '00' == $match->minutes ? '' : mysql2date(get_option('time_format'), $match->date);
             }
             if ($dateformat) {
                 $matches[$i]->date = substr($match->date, 0, 10) == '0000-00-00' ? 'N/A' : mysql2date($dateformat, $match->date);
             } else {
                 $matches[$i]->date = substr($match->date, 0, 10) == '0000-00-00' ? 'N/A' : mysql2date(get_option('date_format'), $match->date);
             }
             //				$matches[$i]->start_time = ( '00' == $match->hour && '00' == $match->minutes ) ? '' : mysql2date(get_option('time_format'), $match->date);
             //				$matches[$i]->date = ( substr($match->date, 0, 10) == '0000-00-00' ) ? 'N/A' : mysql2date(get_option('date_format'), $match->date);
             $matches[$i]->title = isset($matches[$i]->title) && !empty($matches[$i]->title) ? $match->title : $teams[$match->home_team]['title'] . ' &#8211; ' . $teams[$match->away_team]['title'];
             $matches[$i]->title = apply_filters('leaguemanager_matchtitle_' . $league->sport, $matches[$i]->title, $match, $teams);
             if (parent::isHomeTeamMatch($match->home_team, $match->away_team, $teams)) {
                 $matches[$i]->title = '<strong>' . $matches[$i]->title . '</strong>';
             }
             $matches[$i]->report = $match->post_id != 0 ? '(<a href="' . get_permalink($match->post_id) . '">' . __('Report', 'leaguemanager') . '</a>)' : '';
             if ($match->hadPenalty) {
                 $matches[$i]->score = sprintf("%s - %s", $match->penalty['home'] + $match->overtime['home'], $match->penalty['away'] + $match->overtime['away']) . " " . _x('o.P.|on penalty', 'leaguemanager');
             } elseif ($match->hadOvertime) {
                 //	$matches[$i]->score = sprintf("%s - %s", $match->overtime['home'], $match->overtime['away'])." "._x( 'AET|after extra time', 'leaguemanager' );
                 $matches[$i]->score = sprintf("%s - %s", $matches[$i]->home_points, $matches[$i]->away_points);
             } elseif ($match->home_points != NULL && $match->away_points != NULL) {
                 $matches[$i]->score = sprintf("%s - %s", $matches[$i]->home_points, $matches[$i]->away_points);
             } else {
                 $matches[$i]->score = "-:-";
             }
             $i++;
         }
     }
     if (empty($template) && $this->checkTemplate('matches-' . $league->sport)) {
         $filename = 'matches-' . $league->sport;
     } else {
         $filename = !empty($template) ? 'matches-' . $template : 'matches';
     }
     $out = $this->loadTemplate($filename, array('league' => $league, 'matches' => $matches, 'teams' => $teams, 'season' => $season, 'roster' => $roster));
     return $out;
 }