Sorter Class Reference
[Controller]
Class to create a sorting widget and to process search results. More...
Inheritance diagram for Sorter:
Public Member Functions |
|
__construct (PageData $page_data, $columns, $default_column_key=false, $adapter=false) | |
Constructor. |
|
apply ($query) | |
Do what should be done. |
|
prepare_view ($view) | |
Sets sorter_data on view, so WidgetSorter can be applied.
|
|
Static Public Member Functions |
|
static | apply_to_url ($url, $column, $order) |
Prepare URL so filter gets applied. |
|
Public Attributes |
|
const | DO_INDEX_SORTED = 0 |
const | DONT_INDEX_SORTED = 1 |
Protected Attributes |
|
$adapter | |
$sorter_data = array() |
Detailed Description
Class to create a sorting widget and to process search results.
Definition at line 8 of file sorter.cls.php.
Constructor & Destructor Documentation
Sorter::__construct | ( | PageData $ | page_data, | |
$ | columns, | |||
$ | default_column_key = false , |
|||
$ | adapter = false |
|||
) |
Constructor.
- Parameters:
-
PageData $page_data array|ISearchAdapter $columns Associative array of DBSortColumns or instance of ISearchAdapter. In later case get_sortable_columns() and get_sort_default_column() are called on search adapter. Value of $default_column_key is ignored. string $default_column Key for default sort column ISorterAdapter $adapter If integer is passed it is interpreted as policy for backward compatability
Definition at line 37 of file sorter.cls.php.
00037 { 00038 $this->adapter = ($adapter instanceof ISorterAdapter) ? $adapter : new SorterDefaultAdapter($page_data); 00039 if ($columns instanceof ISearchAdapter) { 00040 $default_column_key = $columns->get_sort_default_column(); 00041 $columns = $columns->get_sortable_columns(); 00042 } 00043 $this->sorter_data['policy'] = is_int($adapter) ? $adapter : 0; 00044 $this->sorter_data['page_data'] = $page_data; 00045 $this->sorter_data['column_objects'] = $columns; 00046 $this->sorter_data['columns_total'] = count($columns); 00047 $this->sorter_data['default_column_key'] = $default_column_key; 00048 00049 // Get sort column objects 00050 $column_key = $this->adapter->get_column(); 00051 if (empty($column_key)) { 00052 $column_key = $default_column_key; 00053 } 00054 $column_obj = Arr::get_item($columns, $column_key, false); 00055 if ($column_obj == false) { 00056 $column_obj = Arr::get_item($columns, 0, false); 00057 } 00058 $this->sorter_data['current_column_key'] = $column_key; 00059 $this->sorter_data['current_column_object'] = $column_obj; 00060 00061 // Set order 00062 $default_order = ($column_obj) ? $column_obj->get_direction() : DBSortColumn::ORDER_FORWARD; 00063 $order = $this->adapter->get_order(); 00064 if (empty($order)) { 00065 $order = $default_order; 00066 } 00067 else { 00068 if ($column_obj && $column_obj->get_is_single_direction()) { 00069 // Oops, we have a sort on a non-sortable column. Redirect 00070 $this->adapter->get_url_for_sort($column_key, '')->redirect(); 00071 exit; 00072 } 00073 } 00074 $this->sorter_data['order'] = $order; 00075 $this->sorter_data['default_order'] = $default_order; 00076 $this->sorter_data['is_default'] = (($order == $default_order) && ($column_key == $default_column_key)); 00077 }
Member Function Documentation
Sorter::apply | ( | $ | query | ) |
Do what should be done.
- Parameters:
-
DataObjectBase The current query to be modified
Implements IDBQueryModifier.
Definition at line 84 of file sorter.cls.php.
00084 { 00085 $column_obj = $this->sorter_data['current_column_object']; 00086 if ($column_obj instanceof DBSortColumn) { 00087 $column_obj->set_direction($this->sorter_data['order']); 00088 $column_obj->apply($query); 00089 } 00090 }
static Sorter::apply_to_url | ( | $ | url, | |
$ | column, | |||
$ | order | |||
) | [static] |
Prepare URL so filter gets applied.
- Returns:
- void
- Deprecated:
- Use function on Adapter instead
Definition at line 164 of file sorter.cls.php.
00164 { 00165 return SorterDefaultAdapter::apply_to_url($url, $column, $order); 00166 }
Sorter::prepare_view | ( | $ | view | ) |
Sets sorter_data on view, so WidgetSorter can be applied.
Definition at line 95 of file sorter.cls.php.
00095 { 00096 if ($this->sorter_data['columns_total'] < 2) { 00097 return; 00098 } 00099 00100 $order = $this->sorter_data['order']; 00101 $arr_colums = array(); 00102 foreach($this->sorter_data['column_objects'] as $column => $data) { 00103 $arr_colums[$column] = $this->create_column_array($data, $order, $column); 00104 } 00105 00106 $current_column_obj = $this->sorter_data['current_column_object']; 00107 if ($current_column_obj) { 00108 $current_column = $this->create_column_array($current_column_obj, $order, $this->sorter_data['current_column_key']); 00109 } 00110 00111 $this->sorter_data['columns'] = $arr_colums; 00112 $this->sorter_data['current_column'] = $current_column; 00113 $view->assign('sorter_data', $this->sorter_data); 00114 }
Member Data Documentation
Sorter::$adapter [protected] |
Definition at line 23 of file sorter.cls.php.
Sorter::$sorter_data = array()
[protected] |
Definition at line 24 of file sorter.cls.php.
const Sorter::DO_INDEX_SORTED = 0 |
- Deprecated:
- Use Widget Constants instead!
Definition at line 16 of file sorter.cls.php.
const Sorter::DONT_INDEX_SORTED = 1 |
- Deprecated:
- Use Widget Constants instead!
Definition at line 12 of file sorter.cls.php.
The documentation for this class was generated from the following file:
- gyro/core/controller/tools/sorter.cls.php