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"));
     });
 }
 /**
  * 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;
 }