Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r15417 -r15427 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15417) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15427) @@ -1,6 +1,6 @@ Application->ConfigValue('RecycleBinFolder'); if ( $recycle_bin ) { - $rb = $this->Application->recallObject('c.recycle', null, array ('skip_autoload' => true)); + $rb = $this->Application->recallObject('c.recycle', NULL, array ('skip_autoload' => true)); /* @var $rb CategoriesItem */ $rb->Load($recycle_bin); - $object = $this->Application->recallObject($event->Prefix . '.recycleitem', null, Array ('skip_autoload' => true)); + $object = $this->Application->recallObject($event->Prefix . '.recycleitem', NULL, Array ('skip_autoload' => true)); /* @var $object kCatDBItem */ foreach ($ids as $id) { @@ -501,7 +501,7 @@ } } - $p_item = $this->Application->recallObject($related_prefix.'.current', null, Array('skip_autoload' => true)); + $p_item = $this->Application->recallObject($related_prefix.'.current', NULL, Array('skip_autoload' => true)); /* @var $p_item kCatDBItem */ $p_item->Load( (int)$id ); @@ -719,7 +719,7 @@ * @param kDBList $object * @param int $user_id */ - function applyPendingEditingFilter(&$object, $user_id = null) + function applyPendingEditingFilter(&$object, $user_id = NULL) { $sql = 'SELECT OrgId FROM '.$object->TableName.' @@ -781,7 +781,7 @@ // hot items (cache updated every hour) if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { - $serial_name = $this->Application->incrementCacheSerial($event->Prefix, null, false); + $serial_name = $this->Application->incrementCacheSerial($event->Prefix, NULL, false); $hot_limit = $this->Application->getCache($property_map['HotLimit'] . '[%' . $serial_name . '%]'); } else { @@ -834,7 +834,7 @@ $hot_limit = (double)array_shift($res); if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { - $serial_name = $this->Application->incrementCacheSerial($event->Prefix, null, false); + $serial_name = $this->Application->incrementCacheSerial($event->Prefix, NULL, false); $this->Application->setCache($property_map['HotLimit'] . '[%' . $serial_name . '%]', $hot_limit); } else { @@ -2010,7 +2010,7 @@ $image_data = $object->getPrimaryImageData(); - $image = $this->Application->recallObject('img', null, Array ('skip_autoload' => true)); + $image = $this->Application->recallObject('img', NULL, Array ('skip_autoload' => true)); /* @var $image kDBItem */ if ( $image_data ) { @@ -2227,7 +2227,7 @@ $temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); /* @var $temp_handler kTempTablesHandler */ - $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array ($object->GetID()), null, null, null, true); + $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array ($object->GetID()), NULL, NULL, NULL, true); $ci_table = $this->Application->GetTempName(TABLE_PREFIX . 'CategoryItems'); // 2. delete record from CategoryItems (about cloned item) that was automatically created during call of Create method of kCatDBItem @@ -2330,7 +2330,7 @@ $object->SetDBField('ResourceId', 0); // this will reset it if ( $this->Application->GetVar('ResetCatBeforeClone') ) { - $object->SetDBField('CategoryId', null); + $object->SetDBField('CategoryId', NULL); } } @@ -2508,7 +2508,7 @@ $object->Load($original_id, 'OrgId'); if (!$object->isLoaded()) { // 1. user has no pending copy of live item -> clone live item - $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array($original_id), null, null, null, true); + $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array($original_id), NULL, NULL, NULL, true); $object->Load($cloned_ids[0]); $object->SetFieldsFromHash($field_values, $this->getRequestProtectedFields($field_values)); @@ -2721,32 +2721,70 @@ /* @var $object kDBList */ // 1. no user sorting - sort by relevance + $default_sortings = parent::_getDefaultSorting($event); + $default_sorting = key($default_sortings['Sorting']) . ',' . current($default_sortings['Sorting']); + if ( $object->isMainList() ) { - if ( !$this->Application->GetVar('sort_by') ) { - $this->Application->SetVar('sort_by', 'Relevance,desc'); + $sort_by = $this->Application->GetVar('sort_by', ''); + + if ( !$sort_by ) { + $this->Application->SetVar('sort_by', 'Relevance,desc|' . $default_sorting); } + elseif ( strpos($sort_by, 'Relevance,') !== false ) { + $this->Application->SetVar('sort_by', $sort_by . '|' . $default_sorting); + } } else { $sorting_settings = $this->getListSetting($event, 'Sortings'); + $sort_by = trim(getArrayValue($sorting_settings, 'Sort1') . ',' . getArrayValue($sorting_settings, 'Sort1_Dir'), ','); - if ( !trim(getArrayValue($sorting_settings, 'Sort1') . ',' . getArrayValue($sorting_settings, 'Sort1_Dir'), ',') ) { - $event->setEventParam('sort_by', 'Relevance,desc'); + if ( !$sort_by ) { + $event->setEventParam('sort_by', 'Relevance,desc|' . $default_sorting); } + elseif ( strpos($sort_by, 'Relevance,') !== false ) { + $event->setEventParam('sort_by', $sort_by . '|' . $default_sorting); + } } - // 2. remove default sortings - $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); - unset($config_mapping['DefaultSorting1Field']); - $this->Application->setUnitOption($event->Prefix, 'ConfigMapping', $config_mapping); - - // 2. remove forced sortings - $this->Application->setUnitOption($event->Prefix, 'ListSortings', Array ()); + $this->_removeForcedSortings($event); } parent::SetSorting($event); } /** + * Removes forced sortings + * + * @param kEvent $event + */ + protected function _removeForcedSortings(kEvent $event) + { + $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); + /* @var $list_sortings Array */ + + foreach ($list_sortings as $special => $sortings) { + unset($list_sortings[$special]['ForcedSorting']); + } + + $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); + } + + /** + * Default sorting in search results only comes from relevance field + * + * @param kEvent $event + * @return Array + * @access protected + */ + protected function _getDefaultSorting(kEvent $event) + { + $types = $event->getEventParam('types'); + $types = $types ? explode(',', $types) : Array (); + + return in_array('search', $types) ? Array () : parent::_getDefaultSorting($event); + } + + /** * Returns current per-page setting for list * * @param kEvent $event