Exemple #1
0
 public static function execute()
 {
     error_log("RUNNING GAMEDAY CHECKER:");
     $db = new KKL_DB();
     $leagues = $db->getLeagues();
     foreach ($leagues as $league) {
         error_log("checking league: " . utf8_decode($league->name));
         $current_season = $db->getSeason($league->current_season);
         if ($current_season && $current_season->active) {
             error_log("- current season is " . utf8_decode($current_season->name));
             $current_day = $db->getGameDay($current_season->current_game_day);
             if ($current_day) {
                 error_log("-- current day is " . $current_day->number);
                 $next_day = $db->getNextGameDay($current_day);
                 $now = time();
                 if ($next_day->fixture) {
                     error_log("-- next day is " . $next_day->number);
                     $fixture = strtotime($next_day->fixture);
                     error_log("--- now: " . $now);
                     error_log("--- fixture: " . $fixture);
                     error_log("--- diff: " . ($now - $fixture));
                     if ($fixture < $now) {
                         error_log("--- setting next day");
                         $db->setCurrentGameDay($current_season, $next_day);
                     }
                 }
             }
         }
     }
 }
    public function form($instance)
    {
        $db = new KKL_DB();
        $leagues = $db->getLeagues();
        if (isset($instance['title'])) {
            $title = $instance['title'];
        } else {
            $title = __('New title', 'text_domain');
        }
        ?>
		<p>
		<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:');
        ?>
</label> 
		<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />		
		</p>
		<?php 
    }
 function display_content()
 {
     $season = $this->get_item();
     $db = new KKL_DB();
     $leagues = $db->getLeagues();
     $season_options = array("" => __('please_select', 'kkl-ligatool'));
     foreach ($leagues as $league) {
         $league_options[$league->id] = $league->name;
     }
     $days = $db->getGameDaysForSeason($season->id);
     $day_options = array("" => __('please_select', 'kkl-ligatool'));
     foreach ($days as $day) {
         $day_options[$day->id] = 'Spieltag ' . $day->number;
     }
     $active_checked = $season->active == 1;
     if ($this->errors && $_POST['active']) {
         $active_checked = true;
     }
     echo $this->form_table(array(array('type' => 'hidden', 'name' => 'id', 'value' => $season->id), array('title' => __('name', 'kkl-ligatool'), 'type' => 'text', 'name' => 'name', 'value' => $this->errors ? $_POST['name'] : $season->name, 'extra' => $this->errors['name'] ? array('style' => "border-color: red;") : array()), array('title' => __('league', 'kkl-ligatool'), 'type' => 'select', 'name' => 'league', 'choices' => $league_options, 'selected' => $this->errors ? $_POST['league'] : $season->league_id, 'extra' => $this->errors['league'] ? array('style' => "border-color: red;") : array()), array('title' => __('start_date', 'kkl-ligatool'), 'type' => 'text', 'name' => 'start_date', 'value' => $season->start_date, 'extra' => array('class' => 'datetimepicker')), array('title' => __('end_date', 'kkl-ligatool'), 'type' => 'text', 'name' => 'end_date', 'value' => $season->end_date, 'extra' => array('class' => 'datetimepicker')), array('title' => __('current_game_day', 'kkl-ligatool'), 'type' => 'select', 'name' => 'current_game_day', 'choices' => $day_options, 'selected' => $season->current_game_day), array('title' => __('active', 'kkl-ligatool'), 'type' => 'checkbox', 'name' => 'active', 'checked' => $active_checked)));
 }
 function get_leagues()
 {
     if ($this->leagues) {
         return $this->leagues;
     }
     $db = new KKL_DB();
     $leagues = $db->getLeagues();
     $keyed = array();
     foreach ($leagues as $league) {
         $keyed[$league->id] = $league;
     }
     $this->leagues = $keyed;
     return $keyed;
 }
    public function form($instance)
    {
        $db = new KKL_DB();
        $leagues = $db->getLeagues();
        if (isset($instance['title'])) {
            $title = $instance['title'];
        } else {
            $title = __('New title', 'text_domain');
        }
        if (isset($instance['league'])) {
            $league = $instance['league'];
        } else {
            $league = __('Set League', 'text_domain');
        }
        ?>
		<p>
		<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:');
        ?>
</label> 
		<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
		<br/><br/>
		<label for="<?php 
        echo $this->get_field_id('league');
        ?>
"><?php 
        _e('League:');
        ?>
</label> 
		<select id="<?php 
        echo $this->get_field_id('league');
        ?>
" name="<?php 
        echo $this->get_field_name('league');
        ?>
">
			<option value=""><?php 
        echo __('get from context', 'kkl-ligatool');
        ?>
</option>
			<?php 
        foreach ($leagues as $l) {
            $selected = false;
            if ($l->id == $league) {
                $selected = true;
            }
            echo "<option value=\"{$l->id}\"";
            if ($selected) {
                echo ' selected="selected"';
            }
            echo ">";
            echo $l->name;
            echo "</option>";
        }
        ?>
		</select>
		</p>
		<?php 
    }
     $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;
     $output['schedules'] = $schedules;
 } else {
     $context = KKL::getContext();
     foreach ($db->getLeagues() as $league) {
         if ($league->active != 1) {
             continue;
         }
         $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 = get_site_url() . '/team/' . KKL::getLink('club', array('club' => $club->short_name));
         }
         $ranking->league->link = get_site_url() . '/spielplan/' . KKL::getLink('league', array('league' => $league->code, 'season' => date('Y', strtotime($season->start_date)), 'game_day' => $day->number));
         $rankings[] = $ranking;