public function prepare_items()
 {
     // number of items per page
     $per_page = get_user_meta(get_current_user_id(), 'podlove_seasons_per_page', true);
     if (empty($per_page)) {
         $per_page = 10;
     }
     // define column headers
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // retrieve data
     $data = Season::find_all_by_where("1 = 1 ORDER BY start_date ASC");
     // get current page
     $current_page = $this->get_pagenum();
     // get total items
     $total_items = count($data);
     // extrage page for current page only
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     // add items to table
     $this->items = $data;
     // register pagination options & calculations
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
 /**
  * List of podcast seasons
  * 
  * @accessor
  * @dynamicAccessor podcast.seasons
  */
 public static function accessorPodcastSeasons($return, $method_name, $podcast, $args = [])
 {
     return $podcast->with_blog_scope(function () use($return, $method_name, $podcast, $args) {
         return array_map(function ($season) {
             return new Template\Season($season);
         }, Season::find_all_by_where("1 = 1 ORDER BY start_date ASC"));
     });
 }
 public function testDetectsDuplicateStartDates()
 {
     Season::create(['start_date' => '2011-01-01']);
     Season::create(['start_date' => '2011-01-01']);
     $validator = new SeasonsValidator();
     $validator->validate();
     $issues = $validator->issues();
     $this->assertEquals(1, count($issues));
     $issue = $issues[0];
     $this->assertEquals('duplicate_start_dates', $issue->type);
     $this->assertEquals('Some of your seasons have the same start date.', $issue->message());
 }
 public function was_activated($module_name)
 {
     Season::build();
 }
 /**
  * Season number.
  * 
  * Automatically determined season number.
  * 
  * One season may have no start date and is assumed to be the first season.
  * 
  * @return int
  */
 public function number()
 {
     $seasons = Season::find_all_by_where("start_date < '" . $this->start_date . "' OR start_date IS NULL AND id != " . $this->id);
     return count($seasons) + 1;
 }
 private function edit_template()
 {
     $season = Season::find_by_id($_REQUEST['season']);
     echo '<h3>' . sprintf(__('Edit Season: %s', 'podlove'), $season->title) . '</h3>';
     $this->form_template($season, 'save');
 }
 public function testGetByDate()
 {
     $season0 = Season::create();
     $season1 = Season::create(['start_date' => '2011-01-01']);
     $episodes = $this->_generate_episodes_for_dates(['2010-10-10', '2010-10-11', '2013-01-01']);
     $this->assertNull(Season::by_date(strtotime('2005-10-10')));
     $this->assertEquals($season0->id, Season::by_date(strtotime('2010-10-10'))->id);
     $this->assertEquals($season1->id, Season::by_date(strtotime('2013-01-02'))->id);
 }
 /**
  * Get season for an episode
  * 
  * @accessor
  * @dynamicAccessor episode.season
  */
 public static function accessorEpisodeSeason($return, $method_name, $episode, $post, $args = [])
 {
     return new Template\Season(Model\Season::for_episode($episode));
 }