Exemple #1
0
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  * 
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 function prepare_items()
 {
     // process bulk actions
     $this->process_bulk_action();
     // get pagination state
     $current_page = $this->get_pagenum();
     $per_page = $this->get_items_per_page('listings_per_page', 20);
     // regard max table rows limit
     if ($max_per_page = get_option('wplister_force_table_items_limit')) {
         $per_page = min($per_page, $max_per_page);
     }
     // define columns
     $this->_column_headers = $this->get_column_info();
     // fetch listings from model - if no selected products were found
     if (!$this->selectedItems) {
         $result = WPLE_ListingQueryHelper::getPageItems($current_page, $per_page);
         $this->items = $result->items;
         $this->total_items = $result->total_items;
     } else {
         $this->items = $this->selectedItems;
         $this->total_items = count($this->selectedItems);
     }
     // register our pagination options & calculations.
     $this->set_pagination_args(array('total_items' => $this->total_items, 'per_page' => $per_page, 'total_pages' => ceil($this->total_items / $per_page)));
 }