Public Member Functions | |
| __construct ($model=null, $list_display=array(), $search_fields=array()) | |
| configure ($list_display, $search_fields=array(), $sort_fields=array()) | |
| setFromRequest ($request) | |
| render ($id='') | |
| render_array () | |
| footer () | |
| body () | |
| bodyLine ($item) | |
| getEditAction ($text, $item) | |
| filter () | |
| colHeaders () | |
| headerSortLinks ($field, $title='') | |
| searchField () | |
| getUrl ($get_params=array(), $encoded=true) | |
| __get ($prop) | |
Public Attributes | |
| $items = null | |
| $item_extra_props = array() | |
| $list_filters = array() | |
| $extra_classes = array() | |
| $forced_where = null | |
| $model_view = null | |
| $items_per_page = 50 | |
| $current_page = 1 | |
| $page_number = 1 | |
| $search_string = '' | |
| $no_results_text = 'No items found' | |
| $sort_fields = array() | |
| $sort_order = array() | |
| $sort_reverse_order = array() | |
| $sort_link_title = false | |
| $edit_action = '' | |
| $action = '' | |
| $id = '' | |
| $class = '' | |
| $extra = null | |
| $summary = '' | |
| $nb_items = 0 | |
Protected Attributes | |
| $model | |
| $list_display = array() | |
| $search_fields = array() | |
| $where_clause = null | |
| $active_list_filter = array() | |
The paginator has several methods to render the complete table in one call or to give more freedom to the end user in the table by doing it item by item.
An example of usage is as follow:
$model = new Pluf_Permission(); $pag = new Pluf_Paginator($model); // Set the action to the page listing the permissions $pag->action = 'view_name'; // Get the paginator parameters from the request $pag->setFromRequest($request); print $pag->render();
This example shows the fast way. That means that the items will be shown according to the default values of the paginator or with the details given in the admin definition of the model.
| Pluf_Paginator::__construct | ( | $ | model = null, |
|
| $ | list_display = array(), |
|||
| $ | search_fields = array() | |||
| ) |
Construct the paginator for a model.
| object | Model to paginate (null). | |
| array | List of the headers to show (array()). | |
| array | List of the fields to search (array()). |
| Pluf_Paginator::configure | ( | $ | list_display, | |
| $ | search_fields = array(), |
|||
| $ | sort_fields = array() | |||
| ) |
Configure the paginator.
| array | List of the headers to show. | |
| array | List of the fields to search (array()) | |
| array | List of the fields to sort the data set (array()) |
| Pluf_Paginator::setFromRequest | ( | $ | request | ) |
Set the parameters from the request.
Possible parameters are: _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.
| Pluf_HTTP_Request | The request |
| Pluf_Paginator::render | ( | $ | id = '' |
) |
Render the complete table.
When an id is provided, the generated table receive this id.
| string | Table id ('') |
| Pluf_Paginator::render_array | ( | ) |
Render as array.
An array rendering do not honor the limits, that is, all the items are returned. Also, the output is not formatted values from the db are directly returned. This is perfect to then use the values in a JSON response.
| Pluf_Paginator::footer | ( | ) |
Generate the footer of the table.
| Pluf_Paginator::body | ( | ) |
Generate the body of the list.
| Pluf_Paginator::bodyLine | ( | $ | item | ) |
Generate a standard "line" of the body
| Pluf_Paginator::getEditAction | ( | $ | text, | |
| $ | item | |||
| ) |
Get the edit action.
| string | Text to put in the action. No escaping of the text is performed. | |
| object | Model for the action. |
| Pluf_Paginator::filter | ( | ) |
Generate the where clause.
| Pluf_Paginator::colHeaders | ( | ) |
Generate the column headers for the table.
| Pluf_Paginator::headerSortLinks | ( | $ | field, | |
| $ | title = '' | |||
| ) |
Generate the little text on the header to allow sorting if available.
If the title is set, the link is directly made on the title.
| string | Name of the field | |
| string | Title ('') |
| Pluf_Paginator::searchField | ( | ) |
Get the search field XHTML.
| Pluf_Paginator::getUrl | ( | $ | get_params = array(), |
|
| $ | encoded = true | |||
| ) |
Using $this->action and the $get_params array, generate the URL with the data.
| array | Get parameters (array()). | |
| bool | Encoded to be put in href="" (true). |
| Pluf_Paginator::__get | ( | $ | prop | ) |
Overloading of the get method.
| string | Property to get |
Pluf_Paginator::$model [protected] |
The model being paginated.
| Pluf_Paginator::$items = null |
The items being paginated. If no model is given when creating the paginator, it will use the items to list them.
| Pluf_Paginator::$item_extra_props = array() |
Extra property/value for the items.
This can be practical if you want some values for the edit action which are not available in the model data.
Pluf_Paginator::$list_display = array() [protected] |
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.
| Pluf_Paginator::$list_filters = array() |
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.
| Pluf_Paginator::$extra_classes = array() |
Extra classes that will be applied to the td of each cell of each column.
If you have 3 columns and put array('one', '', 'foo') all the td of the first column will have the class 'one' set and the tds of the last column will have the 'foo' class set.
Pluf_Paginator::$search_fields = array() [protected] |
The fields being searched.
Pluf_Paginator::$where_clause = null [protected] |
The where clause from the search.
| Pluf_Paginator::$forced_where = null |
The forced where clause on top of the search.
| Pluf_Paginator::$model_view = null |
View of the model to be used.
| Pluf_Paginator::$items_per_page = 50 |
Maximum number of items per page.
| Pluf_Paginator::$current_page = 1 |
Current page.
| Pluf_Paginator::$page_number = 1 |
Number of pages.
| Pluf_Paginator::$search_string = '' |
Search string.
| Pluf_Paginator::$no_results_text = 'No items found' |
Text to display when no results are found.
| Pluf_Paginator::$sort_fields = array() |
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.
| Pluf_Paginator::$sort_order = array() |
Current sort order. An array with first value the field and second the order of the sort.
| Pluf_Paginator::$sort_reverse_order = array() |
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.
| Pluf_Paginator::$sort_link_title = false |
Do not add the little sort links but directly make the title of the column a link to sort.
| Pluf_Paginator::$edit_action = '' |
Edit action.
| Pluf_Paginator::$action = '' |
Action for search/next/previous.
| Pluf_Paginator::$id = '' |
Id/class of the generated table.
| Pluf_Paginator::$class = '' |
| Pluf_Paginator::$extra = null |
Extra parameters for the modification function call.
| Pluf_Paginator::$summary = '' |
Summary for the table.
| Pluf_Paginator::$nb_items = 0 |
Total number of items.
Available only after the rendering of the paginator.
Pluf_Paginator::$active_list_filter = array() [protected] |