Index: branches/5.1.x/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r13086 -r13159 --- branches/5.1.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 13086) +++ branches/5.1.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 13159) @@ -1,6 +1,6 @@ Application->GetVar('NamesToSpecialMapping'); + // list with "list_name" parameter + $names_mapping = $this->Application->GetVar('NamesToSpecialMapping', Array ()); - $special = is_array($names_mapping) && isset($names_mapping[$this->Prefix]) && isset($names_mapping[$this->Prefix][$list_name]) ? $names_mapping[$this->Prefix][$list_name] : false; -// $special = getArrayValue($names_mapping, $this->Prefix, $list_name); - if (!$special) { - $special = $this->BuildListSpecial($params); + if (!array_key_exists($this->Prefix, $names_mapping)) { + // create prefix-based array to special mapping storage + $names_mapping[$this->Prefix] = Array (); } + + if (!array_key_exists($list_name, $names_mapping[$this->Prefix])) { + // special missing -> generate one + $special = $main_list ? $this->Special : $this->BuildListSpecial($params); + } + else { + // get special, formed during list initialization + $special = $names_mapping[$this->Prefix][$list_name]; + } } else { - $special = $this->BuildListSpecial($params); + // list without "list_name" parameter + $special = $main_list ? $this->Special : $this->BuildListSpecial($params); } $prefix_special = rtrim($this->Prefix.'.'.$special, '.'); @@ -445,6 +457,13 @@ return $ret; } + function CombinedSortingDropDownName($params) + { + $list =& $this->GetList($params); + + return $list->getPrefixSpecial() . '_CombinedSorting'; + } + /** * Prepares name for field with event in it (used only on front-end) * @@ -457,7 +476,7 @@ $prefix_special = $list->getPrefixSpecial(); - return 'events['.$prefix_special.']['.$params['event'].']'; + return 'events[' . $prefix_special . '][' . $params['event'] . ']'; } /** @@ -636,20 +655,81 @@ function PageLink($params) { - $t = isset($params['template']) ? $params['template'] : ''; - unset($params['template']); + static $default_per_page = Array (); - if (!$t) $t = $this->Application->GetVar('t'); + $object =& $this->GetList($params); + /* @var $object kDBList */ - if (isset($params['page'])) { - $this->Application->SetVar($this->getPrefixSpecial().'_Page', $params['page']); + // process sorting + if ($object->mainList) { + if (!array_key_exists('sort_by', $params)) { + $sort_by = $this->Application->GetVar('sort_by'); + + if ($sort_by !== false) { + $params['sort_by'] = $sort_by; + } + } + } + + $prefix_special = $this->getPrefixSpecial(); + + // process page + $page = array_key_exists('page', $params) ? $params['page'] : $this->Application->GetVar($prefix_special . '_Page'); + + if (!$page) { + // ensure, that page is always present + if ($object->mainList) { + $params[$prefix_special . '_Page'] = $this->Application->GetVar('page', 1); + } + else { + $params[$prefix_special . '_Page'] = 1; + } + } + + if (array_key_exists('page', $params)) { + $params[$prefix_special . '_Page'] = $params['page']; unset($params['page']); } - if (!isset($params['pass'])) { - $params['pass'] = 'm,'.$this->getPrefixSpecial(); + // process per-page + $per_page = array_key_exists('per_page', $params) ? $params['per_page'] : $this->Application->GetVar($prefix_special . '_PerPage'); + + if (!$per_page) { + // ensure, that per-page is always present + list ($prefix, ) = explode('.', $prefix_special); + + if (!array_key_exists($prefix, $default_per_page)) { + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + $default_per_page[$prefix] = $list_helper->getDefaultPerPage($prefix); + } + + if ($object->mainList) { + $params[$prefix_special . '_PerPage'] = $this->Application->GetVar('per_page', $default_per_page[$prefix]); + } + else { + $params[$prefix_special . '_PerPage'] = $default_per_page[$prefix]; + } } + if (array_key_exists('per_page', $params)) { + $params[$prefix_special . '_PerPage'] = $params['per_page']; + unset($params['per_page']); + } + + if (!array_key_exists('pass', $params)) { + $params['pass'] = 'm,' . $prefix_special; + } + + // process template + $t = array_key_exists('template', $params) ? $params['template'] : ''; + unset($params['template']); + + if (!$t) { + $t = $this->Application->GetVar('t'); + } + return $this->Application->HREF($t, '', $params); } @@ -1171,7 +1251,28 @@ return $this->PrintPages($params); } + function PerPageBar($params) + { + $object =& $this->GetList($params); + $ret = ''; + $per_pages = explode(';', $params['per_pages']); + $block_params = $this->prepareTagParams($params); + $block_params['name'] = $params['render_as']; + + foreach ($per_pages as $per_page) { + $block_params['per_page'] = $per_page; + $this->Application->SetVar($this->getPrefixSpecial() . '_PerPage', $per_page); + $block_params['selected'] = $per_page == $object->PerPage; + + $ret .= $this->Application->ParseBlock($block_params, 1); + } + + $this->Application->SetVar($this->getPrefixSpecial() . '_PerPage', $object->PerPage); + + return $ret; + } + /** * Returns field name (processed by kMultiLanguage formatter * if required) and item's id from it's IDField or field required @@ -1312,52 +1413,11 @@ function OrderChanged($params) { $list =& $this->GetList($params); - $user_sorting_start = $this->getUserSortIndex(); - $sorting_configs = $this->Application->getUnitOption($this->Prefix, 'ConfigMapping', Array ()); - $list_sortings = $this->Application->getUnitOption($this->Prefix, 'ListSortings', Array ()); - $sorting_prefix = getArrayValue($list_sortings, $this->Special) ? $this->Special : ''; + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ - if (array_key_exists('DefaultSorting1Field', $sorting_configs)) { - $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']), - ); - } - - $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting'); - $sort_fields = is_array($sorting) ? array_keys($sorting) : Array (); - - for ($order_number = 0; $order_number < 2; $order_number++) { - // currect sorting in list - $sorting_pos = $user_sorting_start + $order_number; - $current_order_field = $list->GetOrderField($sorting_pos, true); - $current_order_direction = $list->GetOrderDirection($sorting_pos, true); - - if (!$current_order_field || !$current_order_direction) { - // no sorting defined for this sorting position - continue; - } - - // user sorting found - if (array_key_exists($order_number, $sort_fields)) { - // default sorting found - $default_order_field = $sort_fields[$order_number]; - $default_order_direction = $sorting[$default_order_field]; - - if ($current_order_field != $default_order_field || $current_order_direction != $default_order_direction) { - // #1. user sorting differs from default sorting -> changed - return true; - } - } - else { - // #2. user sorting + no default sorting -> changed - return true; - } - } - - // #3. user sorting match default or not defined -> not changed - return false; + return $list_helper->hasUserSorting($list); } /** @@ -2317,6 +2377,7 @@ function PerPageSelected($params) { $list =& $this->GetList($params); + return $list->PerPage == $params['per_page'] ? $params['selected'] : ''; } @@ -2330,7 +2391,7 @@ { $list =& $this->GetList($params); - return $list->getPrefixSpecial().'_'.$params['type']; + return $list->getPrefixSpecial() . '_' . $params['type']; } /**