/** * Prepares the items for rendering * @since 1.0 * @param string|boolean $search string you want to search for. Default false. * @see WP_List_Table::prepare_items() */ function prepare_items($search = false) { $orderby = $this->sanitize_orderby(); $order = $this->sanitize_order(); $columns = $this->get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->process_bulk_action(); $per_page = $this->get_items_per_page('per_page', 25); $current_page = $this->get_pagenum(); $offset = ($current_page - 1) * $per_page; $total_items = Mail::query()->search($search)->find(true); $mails = Mail::query()->search($search)->sort_by($orderby)->order($order)->limit($per_page)->offset($offset)->find(); foreach ($mails as $mail) { /* @var $mail Mail */ $this->items[] = $mail->to_array(); } $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page)); }
/** * Get oldest mail. * @return Mail */ private function oldest_mail() { return ImmutableArray::create(Mail::query()->sort_by(Mail::get_primary_key())->order('asc')->limit(1)->find())->first(); }