Index: branches/5.2.x/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r14681 -r14697 --- branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14681) +++ branches/5.2.x/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 14697) @@ -1,6 +1,6 @@ getObject(); /* @var $object kDBList */ - if ($object->isMainList()) { + if ( $object->isMainList() ) { $sort_by = $this->Application->GetVar('sort_by'); $cur_sort1 = $cur_sort1_dir = $cur_sort2 = $cur_sort2_dir = false; - if ($sort_by) { + if ( $sort_by ) { list ($cur_sort1, $cur_sort1_dir) = explode(',', $sort_by); } } else { - $cur_sort1 = $this->getListSetting($event, 'Sort1'); - $cur_sort1_dir = $this->getListSetting($event, 'Sort1_Dir'); - $cur_sort2 = $this->getListSetting($event, 'Sort2'); - $cur_sort2_dir = $this->getListSetting($event, 'Sort2_Dir'); + $sorting_settings = $this->getListSetting($event, 'Sortings'); + + $cur_sort1 = getArrayValue($sorting_settings, 'Sort1'); + $cur_sort1_dir = getArrayValue($sorting_settings, 'Sort1_Dir'); + $cur_sort2 = getArrayValue($sorting_settings, 'Sort2'); + $cur_sort2_dir = getArrayValue($sorting_settings, 'Sort2_Dir'); } $tag_sort_by = $event->getEventParam('sort_by'); @@ -1036,15 +1038,15 @@ } // use default if not specified in session - if (!$cur_sort1 || !$cur_sort1_dir) { + if ( !$cur_sort1 || !$cur_sort1_dir ) { $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting'); - if ($sorting) { + if ( $sorting ) { reset($sorting); $cur_sort1 = key($sorting); $cur_sort1_dir = current($sorting); - if (next($sorting)) { + if ( next($sorting) ) { $cur_sort2 = key($sorting); $cur_sort2_dir = current($sorting); } @@ -1055,18 +1057,18 @@ $forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting'); /* @var $forced_sorting Array */ - if ($forced_sorting) { + if ( $forced_sorting ) { foreach ($forced_sorting as $field => $dir) { $object->AddOrderField($field, $dir); } } // add user sorting fields - if ($cur_sort1 != '' && $cur_sort1_dir != '') { + if ( $cur_sort1 != '' && $cur_sort1_dir != '' ) { $object->AddOrderField($cur_sort1, $cur_sort1_dir); } - if ($cur_sort2 != '' && $cur_sort2_dir != '') { + if ( $cur_sort2 != '' && $cur_sort2_dir != '' ) { $object->AddOrderField($cur_sort2, $cur_sort2_dir); } } @@ -1076,21 +1078,26 @@ * * @param kEvent $event * @param string $variable_name - * @return string + * @return string|Array + * @access protected */ - function getListSetting(&$event, $variable_name) + protected function getListSetting(&$event, $variable_name) { $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->getPrefixSpecial(); - // get sorting from pesistent session + // get sorting from persistent session $variable_value = $this->Application->RecallPersistentVar($storage_prefix . '_' . $variable_name . '.' . $view_name, ALLOW_DEFAULT_SETTINGS); /*if (!$variable_value) { // get sorting from session $variable_value = $this->Application->RecallVar($storage_prefix . '_' . $variable_name); }*/ + if ( kUtil::IsSerialized($variable_value) ) { + $variable_value = unserialize($variable_value); + } + return $variable_value; } @@ -1099,14 +1106,20 @@ * * @param kEvent $event * @param string $variable_name - * @param string $variable_value + * @param string|Array $variable_value + * @return void + * @access protected */ - function setListSetting(&$event, $variable_name, $variable_value = null) + protected function setListSetting(&$event, $variable_name, $variable_value = null) { $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); // $this->Application->StoreVar($event->getPrefixSpecial() . '_' . $variable_name, $variable_value, true); //true for optional if ( isset($variable_value) ) { + if ( is_array($variable_value) ) { + $variable_value = serialize($variable_value); + } + $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_' . $variable_name . '.' . $view_name, $variable_value, true); //true for optional } else { @@ -1201,36 +1214,39 @@ */ function OnSetSorting(&$event) { - $cur_sort1 = $this->getListSetting($event, 'Sort1'); - $cur_sort1_dir = $this->getListSetting($event, 'Sort1_Dir'); + $sorting_settings = $this->getListSetting($event, 'Sortings'); + $cur_sort1 = getArrayValue($sorting_settings, 'Sort1'); + $cur_sort1_dir = getArrayValue($sorting_settings, 'Sort1_Dir'); $use_double_sorting = $this->Application->ConfigValue('UseDoubleSorting'); - if ($use_double_sorting) { - $cur_sort2 = $this->getListSetting($event, 'Sort2'); - $cur_sort2_dir = $this->getListSetting($event, 'Sort2_Dir'); + if ( $use_double_sorting ) { + $cur_sort2 = getArrayValue($sorting_settings, 'Sort2'); + $cur_sort2_dir = getArrayValue($sorting_settings, 'Sort2_Dir'); } $passed_sort1 = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Sort1'); - if ($cur_sort1 == $passed_sort1) { + if ( $cur_sort1 == $passed_sort1 ) { $cur_sort1_dir = $cur_sort1_dir == 'asc' ? 'desc' : 'asc'; } else { - if ($use_double_sorting) { + if ( $use_double_sorting ) { $cur_sort2 = $cur_sort1; $cur_sort2_dir = $cur_sort1_dir; } + $cur_sort1 = $passed_sort1; $cur_sort1_dir = 'asc'; } - $this->setListSetting($event, 'Sort1', $cur_sort1); - $this->setListSetting($event, 'Sort1_Dir', $cur_sort1_dir); + $sorting_settings = Array ('Sort1' => $cur_sort1, 'Sort1_Dir' => $cur_sort1_dir); - if ($use_double_sorting) { - $this->setListSetting($event, 'Sort2', $cur_sort2); - $this->setListSetting($event, 'Sort2_Dir', $cur_sort2_dir); + if ( $use_double_sorting ) { + $sorting_settings['Sort2'] = $cur_sort2; + $sorting_settings['Sort2_Dir'] = $cur_sort2_dir; } + + $this->setListSetting($event, 'Sortings', $sorting_settings); } /** @@ -1244,33 +1260,32 @@ $prefix_special = $event->getPrefixSpecial(); $combined = $this->Application->GetVar($event->getPrefixSpecial(true) . '_CombinedSorting'); - if ($combined) { + if ( $combined ) { list ($field, $dir) = explode('|', $combined); - if ($this->Application->isAdmin || !$this->Application->GetVar('main_list')) { - $this->setListSetting($event, 'Sort1', $field); - $this->setListSetting($event, 'Sort1_Dir', $dir); + if ( $this->Application->isAdmin || !$this->Application->GetVar('main_list') ) { + $this->setListSetting($event, 'Sortings', Array ('Sort1' => $field, 'Sort1_Dir' => $dir)); } else { $event->setPseudoClass('_List'); $this->Application->SetVar('sort_by', $field . ',' . $dir); - $object =& $event->getObject( Array ('main_list' => 1) ); + $object =& $event->getObject(Array ('main_list' => 1)); /* @var $object kDBList */ $list_helper =& $this->Application->recallObject('ListHelper'); /* @var $list_helper ListHelper */ $this->_passListParams($event, 'sort_by'); - if ($list_helper->hasUserSorting($object)) { + if ( $list_helper->hasUserSorting($object) ) { $event->SetRedirectParam('sort_by', $field . ',' . strtolower($dir)); } $event->SetRedirectParam('pass', 'm'); } - return ; + return; } // used in "View Menu -> Sort" menu in administrative console @@ -1286,10 +1301,7 @@ */ function OnResetSorting(&$event) { - $this->setListSetting($event, 'Sort1'); - $this->setListSetting($event, 'Sort1_Dir'); - $this->setListSetting($event, 'Sort2'); - $this->setListSetting($event, 'Sort2_Dir'); + $this->setListSetting($event, 'Sortings'); } /**