Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r8451 -r8460 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8451) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8460) @@ -2052,6 +2052,125 @@ return $status == STATUS_ACTIVE; } + + /** + * Set sorting directly to session + * + * @param kEvent $event + */ + function OnSetSortingDirect(&$event) + { + $combined = $this->Application->GetVar($event->Prefix.'_CombinedSorting'); + if ($combined) { + list($field, $dir) = explode('|', $combined); + $this->Application->StoreVar($event->Prefix.'_Sort1', $field); + $this->Application->StoreVar($event->Prefix.'_Sort1_Dir', $dir); + return ; + } + + $field_pos = $this->Application->GetVar($event->Prefix.'_SortPos'); + $this->Application->LinkVar($event->Prefix.'_Sort'.$field_pos, $event->Prefix.'_Sort'.$field_pos); + $this->Application->LinkVar($event->Prefix.'_Sort'.$field_pos.'_Dir', $event->Prefix.'_Sort'.$field_pos.'_Dir'); + } + + /** + * Set's correct sorting for list + * based on data provided with event + * + * @param kEvent $event + * @access private + * @see OnListBuild + */ + function SetSorting(&$event) + { + if ($this->Application->IsAdmin()) { + parent::SetSorting($event); + return ; + } + + $event->setPseudoClass('_List'); + $object =& $event->getObject(); + + $cur_sort1 = $this->Application->RecallVar($event->Prefix.'_Sort1'); + $cur_sort1_dir = $this->Application->RecallVar($event->Prefix.'_Sort1_Dir'); + $cur_sort2 = $this->Application->RecallVar($event->Prefix.'_Sort2'); + $cur_sort2_dir = $this->Application->RecallVar($event->Prefix.'_Sort2_Dir'); + + + $sorting_configs = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings'); + $sorting_prefix = getArrayValue($list_sortings, $event->Special) ? $event->Special : ''; + + $tag_sort_by = $event->getEventParam('sort_by'); + if ($tag_sort_by) { + if ($tag_sort_by == 'random') { + $by = 'RAND()'; + $dir = ''; + } + else { + list($by, $dir) = explode(',', $tag_sort_by); + } + $object->AddOrderField($by, $dir); + } + + if ($sorting_configs && isset ($sorting_configs['DefaultSorting1Field'])){ + $list_sortings[$sorting_prefix]['Sorting'] = Array( + $this->Application->ConfigValue($sorting_configs['DefaultSorting1Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting1Dir']), + $this->Application->ConfigValue($sorting_configs['DefaultSorting2Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting2Dir']), + ); + } + + // Use default if not specified + if ( !$cur_sort1 || !$cur_sort1_dir) + { + if ( $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting') ) { + reset($sorting); + $cur_sort1 = key($sorting); + $cur_sort1_dir = current($sorting); + if (next($sorting)) { + $cur_sort2 = key($sorting); + $cur_sort2_dir = current($sorting); + } + } + } + + if ( $forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting') ) { + foreach ($forced_sorting as $field => $dir) { + $object->AddOrderField($field, $dir); + } + } + + if($cur_sort1 != '' && $cur_sort1_dir != '') + { + $object->AddOrderField($cur_sort1, $cur_sort1_dir); + } + + if($cur_sort2 != '' && $cur_sort2_dir != '') + { + $object->AddOrderField($cur_sort2, $cur_sort2_dir); + } + } + + /** + * Returns current per-page setting for list + * + * @param kEvent $event + * @return int + */ + function getPerPage(&$event) + { + if ($this->Application->IsAdmin()) { + return parent::getPerPage($event); + } + + $special = $event->Special; + $event->Init($event->Prefix); + $per_page = parent::getPerPage($event); + $event->Init($event->Prefix, $special); + + return $per_page; + } + } ?> \ No newline at end of file