\Pluf_Paginator

Model pagination

Model paginator is used to select and perform an action on part of models in the model collection.

این صفحه بند روش‌های متفاوتی را برای تولید یک نمایش از فهرست مدلها دارد که از این میان می‌تواند به روش تولید یک جدول اشاره کرد. علاوه بر این، این صفحه بند آزادی عمل مناسبی را برای کاربران ایجاد می‌کند تا داده‌های موجود در فهرست را به سادگی نمایش دهند.

Here is an example showes how to use the class:

$pag = new Pluf_Paginator(new Pluf_Model()); // Get the paginator parameters from the request $pag->setFromRequest($request); print $pag->render();

در نمونه بالا یک روش سریع برای نمایش داده‌ها آورده شده است. به بیان دیگر تمام خصوصیت‌های مورد نیاز برای صفحه بندی داده‌ها بر اساس خصوصیت‌های پیش فرض صفحه‌بند تعیین می‌شود.

Summary

Methods
Properties
Constants
__construct()
configure()
setFromRequest()
render_array()
render_object()
fetchItems()
fetchItemsCount()
getNumberOfPages()
$model
$items
$list_display
$list_filters
$search_fields
$where_clause
$forced_where
$model_view
$items_per_page
$current_page
$search_string
$sort_fields
$sort_order
$sort_reverse_order
SEARCH_QUERY_KEY
CURRENT_PAGE_KEY
PAGE_SIZE_KEY
SORT_KEY_KEY
SORT_ORDER_KEY
FILTER_KEY_KEY
FILTER_VALUE_KEY
No protected methods found
No protected properties found
N/A
getFilters()
getOrders()
filterDisplayData()
loadSortOptions()
loadFilterOptions()
$count
$page_number
N/A

Constants

SEARCH_QUERY_KEY

SEARCH_QUERY_KEY = '_px_q'

CURRENT_PAGE_KEY

CURRENT_PAGE_KEY = '_px_p'

PAGE_SIZE_KEY

PAGE_SIZE_KEY = '_px_ps'

SORT_KEY_KEY

SORT_KEY_KEY = '_px_sk'

SORT_ORDER_KEY

SORT_ORDER_KEY = '_px_so'

FILTER_KEY_KEY

FILTER_KEY_KEY = '_px_fk'

FILTER_VALUE_KEY

FILTER_VALUE_KEY = '_px_fv'

Properties

$model

$model : \Pluf_Model

Data model of the items

Type

\Pluf_Model

$items

$items : array

The items being paginated.

If no model is given when creating the paginator, it will use the items to list them.

Type

array

$list_display

$list_display : 

The fields being shown.

If no fields are given, the __toString representation of the item will be used to show the item.

If an item in the list_display is an array the format is the following: array('field', 'Custom_Function_ToApply', 'custom header name')

The signature of the the Custom_Function_ToApply is: string = Custom_Function_ToApply('field', $item);

By using for example 'id' as field with a custom header name you can create new columns in the table.

Type

$list_filters

$list_filters : 

List filter.

Allow the generation of filtering options for the list. If you provide a list of fields having a "choices" option, you will be able to filter on the choice values.

Type

$search_fields

$search_fields : 

The fields being searched.

Type

$where_clause

$where_clause : 

The where clause from the search.

Type

$forced_where

$forced_where : 

The forced where clause on top of the search.

Type

$model_view

$model_view : 

نمایشی از مدل داده‌ای را تعیین می‌کند که باید در این صفحه بندی استفاده شود.

Type

$items_per_page

$items_per_page : 

Maximum number of items per page.

Type

$current_page

$current_page : 

Current page.

Type

$search_string

$search_string : 

Search string.

Type

$sort_fields

$sort_fields : 

Which fields of the model can be used to sort the dataset.

To be useable these fields must be in the $list_display so that the sort links can be shown for the user to click on them and sort the list.

Type

$sort_order

$sort_order : 

Current sort order.

An array with first value the field and second the order of the sort.

Type

$sort_reverse_order

$sort_reverse_order : 

Keys where the sort is reversed.

Let say, you have a column using a timestamp but displaying the information as an age. If you sort "ASC" you espect to get the youngest first, but as the timestamp is used, you get the oldest. But the key here and the sort will be reverted.

Type

$count

$count : integer

Total number of items matched with this pagination

If any parameters of the pagination is changed value of this field is not valid yet.

Type

integer

$page_number

$page_number : 

Number of pages.

Type

Methods

__construct()

__construct(\Pluf_Model  $model = null, array  $list_display = array(), array  $search_fields = array()) 

Creates new instance of paginator

Parameters

\Pluf_Model $model

The main pagination model

array $list_display

fields to display

array $search_fields

fields to search in

configure()

configure(array  $list_display, array  $search_fields = array(), array  $sort_fields = array()) 

Configure paginated list

Parameters

array $list_display

تمام سرآیندهایی که باید نمایش داده شود.

array $search_fields

پارامترهایی که می‌تواند جستجو شود.

array $sort_fields

از داده‌ها که قابلیت مرتب شدن را دارند.

setFromRequest()

setFromRequest(  $request) 

Load options from user request

Here is list of all possible values

  • _px_q : Query string to search.
  • _px_p : Current page.
  • _px_sk : Sort key.
  • _px_so : Sort order.
  • _px_fk : Filter key.
  • _px_fv : Filter value.
    • Parameters

      $request

render_array()

render_array() : \Array.

Creates data array from the request

آرایه ایجاد شده هیچ محدودیتی ندارد و شامل تمام مواردی است که قبل در سیستم ایجاد می‌شود. علاوه بر این داده‌هایی که از پایگاه داده به دست آمده اند به صورت مستقیم برگردانده می‌شوند و شامل هیچ ساختاری نیستند. این روش برای استفاده از داده‌ها در ساختارهایی مانند JSON بسیار مناسب خواهد بود.

Returns

\Array.

render_object()

render_object() : array

Render object in a page

A page is an object with the following fields:

Returns

array

fetchItems()

fetchItems() : array|\ArrayObject

Fetch itmes from DB

Returns

array|\ArrayObject

fetchItemsCount()

fetchItemsCount() : \number

Fetch count of itmes

Returns

\number —

of all items

getNumberOfPages()

getNumberOfPages() 

getFilters()

getFilters() : string

Generate the where clause.

Returns

string —

The ready to use where clause.

getOrders()

getOrders() : NULL|string

Generates an order list and return

All sort options will be loaded form $this->sort_order.

You can set soert order as follow

$pag->sort_order = array(
'param',
'DESC'
);

The result value is

param DESC

For moltiple options:

$pag->sort_order = array(
array(
'param1',
'DESC'
),
array(
'param2',
'ASC'
)
);

The result value is

param1 DESC, param2 ASC

Returns

NULL|string

filterDisplayData()

filterDisplayData(array  $items) : array<mixed,array>

Filter all input data based on display list

It the display list is empty {id} is used as default list.

Parameters

array $items

to filter

Returns

array<mixed,array>

loadSortOptions()

loadSortOptions(  $request) 

Parameters

$request

loadFilterOptions()

loadFilterOptions(  $request) 

Parameters

$request