Index: db_event_handler.php =================================================================== --- db_event_handler.php (revision 14670) +++ db_event_handler.php (working copy) @@ -997,10 +997,11 @@ } } 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'); + $sort_settings = $this->getSortSettings($event); + $cur_sort1 = getArrayValue($sort_settings, 'Sort1'); + $cur_sort1_dir = getArrayValue($sort_settings, 'Sort1_Dir'); + $cur_sort2 = getArrayValue($sort_settings, 'Sort2'); + $cur_sort2_dir = getArrayValue($sort_settings, 'Sort2_Dir'); } $tag_sort_by = $event->getEventParam('sort_by'); @@ -1072,6 +1073,44 @@ } /** + * Gets list sort settings (persistent or real session) + * + * @param kEvent $event + * @return array + */ + function getSortSettings(&$event) + { + $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); + $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->getPrefixSpecial(); + + // get sorting from pesistent session + $settings = $this->Application->RecallPersistentVar($storage_prefix . '_Sort.' . $view_name, ALLOW_DEFAULT_SETTINGS); + + return unserialize($settings); + } + + /** + * Sets list sort settings (persistent and real session) + * + * @param kEvent $event + * @param array $settings + */ + function setSortSettings(&$event, $settings) + { + $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); + + if ( isset($settings) ) { + $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_Sort.' . $view_name, serialize($settings), true); //true for optional + } + else { + $this->Application->RemovePersistentVar($event->getPrefixSpecial() . '_Sort.' . $view_name); + } + } + + + + + /** * Gets list setting by name (persistent or real session) * * @param kEvent $event @@ -1201,14 +1240,15 @@ */ function OnSetSorting(&$event) { - $cur_sort1 = $this->getListSetting($event, 'Sort1'); - $cur_sort1_dir = $this->getListSetting($event, 'Sort1_Dir'); + $sort_settings = $this->getSortSettings($event); + $cur_sort1 = getArrayValue($sort_settings, 'Sort1'); + $cur_sort1_dir = getArrayValue($sort_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'); + $cur_sort2 = getArrayValue($sort_settings, 'Sort2'); + $cur_sort2_dir = getArrayValue($sort_settings, 'Sort2_Dir'); } $passed_sort1 = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Sort1'); @@ -1224,13 +1264,17 @@ $cur_sort1_dir = 'asc'; } - $this->setListSetting($event, 'Sort1', $cur_sort1); - $this->setListSetting($event, 'Sort1_Dir', $cur_sort1_dir); + $sort_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); + $sort_settings['Sort2'] = $cur_sort2; + $sort_settings['Sort2_Dir'] = $cur_sort2_dir; } + + $this->setSortSettings($event, $sort_settings); } /** @@ -1248,8 +1292,10 @@ 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); + $this->setSortSettings($evwnt, Array( + 'Sort1' => $field, + 'Sort1_Dir' => $dir, + )); } else { $event->setPseudoClass('_List'); @@ -1286,10 +1332,7 @@ */ function OnResetSorting(&$event) { - $this->setListSetting($event, 'Sort1'); - $this->setListSetting($event, 'Sort1_Dir'); - $this->setListSetting($event, 'Sort2'); - $this->setListSetting($event, 'Sort2_Dir'); + $this->setSortSettings($event); } /** Index: install/upgrades.php =================================================================== --- install/upgrades.php (revision 14670) +++ install/upgrades.php (working copy) @@ -1814,4 +1814,72 @@ $this->Conn->Query($sql); } } + + /** + * Update to 5.2.0-B1; Transform list sortings storage + * + * @param string $mode when called mode {before, after) + */ + public function Upgrade_5_2_0_B1($mode) + { + if ($mode == 'after') { + + $sql = 'SELECT VariableName, PortalUserId FROM '.TABLE_PREFIX.'PersistantSessionData + WHERE + VariableName LIKE \'%_Sort1.%\' + '; + + $sortings = $this->Conn->Query($sql); + + foreach ($sortings AS $sorting) { + $user_id = $sorting['PortalUserId']; + $sort1_name = $sorting['VariableName']; + if (preg_match('#^(.*)_Sort1.(.*)$#', $sort1_name, $matches)) { + $prefix = $matches[1].'_'; + $suffix = '.'.$matches[2]; + $sql = 'SELECT VariableValue, VariableName FROM '.TABLE_PREFIX.'PersistantSessionData + WHERE + PortalUserId = '.$user_id.' + AND VariableName IN ( + '.$this->Conn->qstr($prefix . 'Sort1' . $suffix).', + '.$this->Conn->qstr($prefix . 'Sort2' . $suffix).', + '.$this->Conn->qstr($prefix . 'Sort1_Dir' . $suffix).', + '.$this->Conn->qstr($prefix . 'Sort2_Dir' . $suffix).' + )'; + $sort_data = $this->Conn->GetCol($sql, 'VariableName'); + + $new_sorting = Array( + 'Sort1' => $sort_data[$prefix . 'Sort1' . $suffix], + 'Sort1_Dir' => $sort_data[$prefix . 'Sort1_Dir' . $suffix], + ); + + if (isset($sort_data[$prefix . 'Sort2' . $suffix])) { + $new_sorting['Sort2'] = $sort_data[$prefix . 'Sort2' . $suffix]; + $new_sorting['Sort2_Dir'] = $sort_data[$prefix . 'Sort2_Dir' . $suffix]; } + + $sql = 'INSERT INTO '.TABLE_PREFIX.'PersistantSessionData ( + PortalUserId, + VariableName, + VariableValue + ) VALUES ( + '.$user_id.', + '.$this->Conn->qstr($prefix . 'Sort' . $suffix).', + '.$this->Conn->qstr(serialize($new_sorting)).' + )'; + $this->Conn->Query($sql); + } + $sql = 'DELETE FROM '.TABLE_PREFIX.'PersistantSessionData + WHERE + PortalUserId = '.$user_id.' + AND VariableName IN ( + '.$this->Conn->qstr($prefix . 'Sort1' . $suffix).', + '.$this->Conn->qstr($prefix . 'Sort2' . $suffix).', + '.$this->Conn->qstr($prefix . 'Sort1_Dir' . $suffix).', + '.$this->Conn->qstr($prefix . 'Sort2_Dir' . $suffix).' + )'; + $this->Conn->Query($sql); + } + + } + } } \ No newline at end of file Index: kernel/db/db_event_handler.php =================================================================== --- kernel/db/db_event_handler.php (revision 14670) +++ kernel/db/db_event_handler.php (working copy) @@ -997,10 +997,11 @@ } } 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'); + $sort_settings = $this->getListSetting($event, 'Sort'); + $cur_sort1 = getArrayValue($sort_settings, 'Sort1'); + $cur_sort1_dir = getArrayValue($sort_settings, 'Sort1_Dir'); + $cur_sort2 = getArrayValue($sort_settings, 'Sort2'); + $cur_sort2_dir = getArrayValue($sort_settings, 'Sort2_Dir'); } $tag_sort_by = $event->getEventParam('sort_by'); @@ -1078,7 +1079,7 @@ * @param string $variable_name * @return string */ - 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(); @@ -1091,6 +1092,10 @@ $variable_value = $this->Application->RecallVar($storage_prefix . '_' . $variable_name); }*/ + if ( kUtil::IsSerialized($variable_value) ) { + $variable_value = unserialize($variable_value); + } + return $variable_value; } @@ -1101,12 +1106,17 @@ * @param string $variable_name * @param string $variable_value */ - 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,14 +1211,15 @@ */ function OnSetSorting(&$event) { - $cur_sort1 = $this->getListSetting($event, 'Sort1'); - $cur_sort1_dir = $this->getListSetting($event, 'Sort1_Dir'); + $sort_settings = $this->getListSetting($event, 'Sort'); + $cur_sort1 = getArrayValue($sort_settings, 'Sort1'); + $cur_sort1_dir = getArrayValue($sort_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'); + $cur_sort2 = getArrayValue($sort_settings, 'Sort2'); + $cur_sort2_dir = getArrayValue($sort_settings, 'Sort2_Dir'); } $passed_sort1 = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Sort1'); @@ -1224,13 +1235,17 @@ $cur_sort1_dir = 'asc'; } - $this->setListSetting($event, 'Sort1', $cur_sort1); - $this->setListSetting($event, 'Sort1_Dir', $cur_sort1_dir); + $sort_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); + $sort_settings['Sort2'] = $cur_sort2; + $sort_settings['Sort2_Dir'] = $cur_sort2_dir; } + + $this->setListSetting($event, 'Sort', $sort_settings); } /** @@ -1248,8 +1263,10 @@ 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); + $this->setListSetting($event, 'Sort', Array( + 'Sort1' => $field, + 'Sort1_Dir' => $dir, + )); } else { $event->setPseudoClass('_List'); @@ -1286,10 +1303,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, 'Sort'); } /**