public function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     $db = new KKL_DB();
     $league_id = $instance['league'];
     if (!$league_id) {
         $context = KKL::getContext();
         $league_id = $context['league']->id;
         if (!$league_id) {
             $team = $context['team'];
             if ($team) {
                 $current_team = $db->getCurrentTeamForClub($team->club_id);
                 $data = $db->getGamesForTeam($current_team->id);
                 echo $this->tpl->render('widgets/upcoming_games.tpl', array('schedule' => $data, 'display_result' => true));
             } else {
                 $data = $db->getAllUpcomingGames();
                 $games = array();
                 $leagues = array();
                 foreach ($data as $game) {
                     $leagues[$game->league_id] = true;
                     $games[$game->league_id][] = $game;
                 }
                 foreach (array_keys($leagues) as $league_id) {
                     $league = $db->getLeague($league_id);
                     echo $this->tpl->render('widgets/upcoming_games.tpl', array('schedule' => $games[$league_id], 'league' => $league));
                 }
             }
         } else {
             $data = $db->getUpcomingGames($league_id);
             echo $this->tpl->render('widgets/upcoming_games.tpl', array('schedule' => $data));
         }
     }
     echo $after_widget;
 }
Exemple #2
0
 public static function clubDetail($atts, $content, $tag)
 {
     global $kkl_twig;
     $db = new KKL_DB();
     $context = KKL::getContext();
     $contextClub = $context['club'];
     $contextClub->logo = $contextClub->logo;
     $seasonTeams = $db->getTeamsForClub($contextClub->id);
     $teams = array();
     foreach ($seasonTeams as $seasonTeam) {
         $seasonTeam->season = $db->getSeason($seasonTeam->season_id);
         $seasonTeam->season->league = $db->getLeague($seasonTeam->season->league_id);
         $ranking = $db->getRankingForLeagueAndSeasonAndGameDay($seasonTeam->season->league_id, $seasonTeam->season->id, $seasonTeam->season->current_game_day);
         $position = 1;
         foreach ($ranking as $rank) {
             if ($rank->team_id == $seasonTeam->id) {
                 $seasonTeam->scores = $rank;
                 $seasonTeam->scores->position = $position;
                 break;
             }
             $position++;
         }
         $seasonTeam->link = KKL::getLink('club', array('club' => $contextClub->short_name));
         $seasonTeam->schedule_link = KKL::getLink('schedule', array('league' => $seasonTeam->season->league->code, 'season' => date('Y', strtotime($seasonTeam->season->start_date)), 'team' => $seasonTeam->short_name));
         $teams[$seasonTeam->id] = $seasonTeam;
     }
     $currentTeam = $db->getCurrentTeamForClub($contextClub->id);
     $currentLocation = $db->getLocation($currentTeam->properties['location']);
     return $kkl_twig->render('shortcodes/club_detail.tpl', array('context' => $context, 'club' => $contextClub, 'teams' => $teams, 'current_location' => $currentLocation));
 }