Exemple #1
0
 public static function tableOverview($atts, $content, $tag)
 {
     global $kkl_twig;
     $db = new KKL_DB();
     $context = KKL::getContext();
     $rankings = array();
     foreach ($db->getActiveLeagues() as $league) {
         $season = $db->getSeason($league->current_season);
         $day = $db->getGameDay($season->current_game_day);
         $ranking = new stdClass();
         $ranking->league = $league;
         $ranking->ranks = $db->getRankingForLeagueAndSeasonAndGameDay($league->id, $season->id, $day->number);
         foreach ($ranking->ranks as $rank) {
             $team = $db->getTeam($rank->team_id);
             $club = $db->getClub($team->club_id);
             $rank->team->link = KKL::getLink('club', array('club' => $club->short_name));
         }
         $ranking->league->link = KKL::getLink('league', array('league' => $league->code, 'season' => date('Y', strtotime($season->start_date)), 'game_day' => $day->number));
         $rankings[] = $ranking;
     }
     return $kkl_twig->render('shortcodes/table.tpl', array('context' => $context, 'rankings' => $rankings));
 }
 function display_content()
 {
     $db = new KKL_DB();
     $db_locations = $db->getLocations();
     $locations = array();
     $locations[0] = __('unknown location', 'kkl-ligatool');
     foreach ($db_locations as $location) {
         $locations[$location->id] = $location->title;
     }
     $match = $this->get_item();
     $current_game_day = $this->get_game_day();
     $db_game_days = $this->get_game_days();
     $game_days = array();
     foreach ($db_game_days as $game_day) {
         $game_days[$game_day->id] = $game_day->number;
     }
     $db_teams = $db->getTeamsForSeason($current_game_day->season_id);
     $teams = array();
     foreach ($db_teams as $team) {
         $teams[$team->id] = $team->name;
     }
     $db_games = $db->getMatchesByGameDay($current_game_day->id);
     $games = array();
     $games[0] = __('back to overview', 'kkl-ligatool');
     $games[1] = __('create new game', 'kkl-ligatool');
     foreach ($db_games as $game) {
         $home = $db->getTeam($game->home_team);
         $away = $db->getTeam($game->away_team);
         $games[$game->id] = $home->name . " - " . $away->name;
     }
     $final_checked = $match->status == 3;
     if ($this->errors && $_POST['final_score']) {
         $final_checked = true;
     }
     $fixture = $this->cleanDate($match->fixture);
     echo $this->form_table(array(array('type' => 'hidden', 'name' => 'id', 'value' => $match->id), array('title' => __('game_day', 'kkl-ligatool'), 'type' => 'select', 'name' => 'game_day', 'value' => $game_days, 'selected' => $this->errors ? $_POST['game_day'] : $current_game_day->id), array('title' => __('fixture', 'kkl-ligatool'), 'type' => 'text', 'name' => 'fixture', 'value' => $fixture, 'extra' => array('class' => "pickfixture")), array('title' => __('team_home', 'kkl-ligatool'), 'type' => 'select', 'name' => 'team_home', 'value' => $teams, 'selected' => $this->errors ? $_POST['team_home'] : $match->home_team), array('title' => __('team_away', 'kkl-ligatool'), 'type' => 'select', 'name' => 'team_away', 'value' => $teams, 'selected' => $this->errors ? $_POST['team_away'] : $match->away_team), array('title' => __('location', 'kkl-ligatool'), 'type' => 'select', 'name' => 'location', 'value' => $locations), array('title' => __('goals_home', 'kkl-ligatool'), 'type' => 'select', 'name' => 'goals_home', 'value' => $this->get_goals_array(), 'selected' => $this->errors ? $_POST['goals_home'] : $match->goals_home), array('title' => __('goals_away', 'kkl-ligatool'), 'type' => 'select', 'name' => 'goals_away', 'value' => $this->get_goals_array(), 'selected' => $this->errors ? $_POST['goals_away'] : $match->goals_away), array('title' => __('score_home', 'kkl-ligatool'), 'type' => 'select', 'name' => 'score_home', 'value' => $this->get_score_array(), 'selected' => $this->errors ? $_POST['score_home'] : $match->score_home), array('title' => __('score_away', 'kkl-ligatool'), 'type' => 'select', 'name' => 'score_away', 'value' => $this->get_score_array(), 'selected' => $this->errors ? $_POST['score_away'] : $match->score_away), array('title' => __('final_score', 'kkl-ligatool'), 'type' => 'checkbox', 'name' => 'final_score', 'checked' => $final_checked), array('title' => __('description', 'kkl-ligatool'), 'type' => 'textarea', 'name' => 'description', 'value' => $this->errors ? $_POST['description'] : $match->notes, 'extra' => array('rows' => 7, 'cols' => 100)), array('title' => __('next_game', 'kkl-ligatool'), 'type' => 'select', 'name' => 'next_game', 'value' => $games, 'selected' => $this->errors ? $_POST['next_game'] : null)));
 }
 function save()
 {
     $team = new stdClass();
     $team->id = $_POST['id'];
     $team->name = $_POST['name'];
     $team->short_name = $_POST['short_name'];
     $team->season_id = $_POST['season'];
     $team->club_id = $_POST['club'];
     $db = new KKL_DB();
     $team = $db->createOrUpdateTeam($team);
     $properties = array();
     $properties['location'] = false;
     $properties['current_league_winner'] = false;
     $properties['current_cup_winner'] = false;
     if ($_POST['location']) {
         $properties['location'] = $_POST['location'];
     }
     if ($_POST['current_league_winner']) {
         $properties['current_league_winner'] = "true";
     }
     if ($_POST['current_cup_winner']) {
         $properties['current_cup_winner'] = "true";
     }
     if (!empty($properties)) {
         $db->setTeamProperties($team, $properties);
     }
     return $db->getTeam($team->id);
 }
    }
}
$KKL->setContext($context);
if (isset($wp_query->query_vars['json'])) {
    header('Content-Type: application/json');
    global $kkl_twig;
    $db = new KKL_DB();
    $context = KKL::getContext();
    $rankings = array();
    $output = array();
    if (!$overview) {
        $ranking = new stdClass();
        $ranking->league = $context['league'];
        $ranking->ranks = $db->getRankingForLeagueAndSeasonAndGameDay($context['league']->id, $context['season']->id, $context['game_day']->number);
        foreach ($ranking->ranks as $rank) {
            $team = $db->getTeam($rank->team_id);
            $club = $db->getClub($team->club_id);
            $rank->team->link = get_site_url() . '/team/' . KKL::getLink('club', array('club' => $club->short_name));
        }
        $rankings[] = $ranking;
        $output['rankings'] = $rankings;
        $schedules = array();
        $schedule = $db->getScheduleForGameDay($context['game_day']);
        foreach ($schedule->matches as $match) {
            $home_club = $db->getClub($match->home->club_id);
            $away_club = $db->getClub($match->away->club_id);
            $match->home->link = get_site_url() . '/team/' . KKL::getLink('club', array('club' => $home_club->short_name));
            $match->away->link = get_site_url() . '/team/' . KKL::getLink('club', array('club' => $away_club->short_name));
        }
        $schedule->link = get_site_url() . '/spielplan/' . KKL::getLink('schedule', array('league' => $context['league']->code, 'season' => date('Y', strtotime($context['season']->start_date))));
        $schedules[] = $schedule;