Index: trunk/core/units/categories/categories_tag_processor.php =================================================================== diff -u -N -r5326 -r6093 --- trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 5326) +++ trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 6093) @@ -2,33 +2,15 @@ class CategoriesTagProcessor extends kDBTagProcessor { - function &GetList($params) - { - $special = $this->BuildListSpecial($params); - - $prefix_special = $this->Prefix.'.'.$special; - $this->Special = $special; - - $params['skip_counting'] = true; - - $list =& $this->Application->recallObject( $prefix_special, $this->Prefix.'_List',$params); - -// $list->clearFilters(); -// $list->addFilter('parent_filter', 'ParentId = '.$parent_cat_id, WHERE_FILTER, FLT_SYSTEM); - - //unset($params['skip_counting']); -// $this->Application->HandleEvent($event, $prefix_special.':SetPagination', $params ); - - $list->Query(); - return $list; - } - function SubCatCount($params) { $cat_object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params); $sql = ' SELECT COUNT(*) - 1 FROM '.$cat_object->TableName.' WHERE ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%"'; + if (isset($params['today'])) { + $sql .= ' AND CreatedOn > '.(adodb_mktime()-86400); + } return $this->Conn->GetOne($sql); } @@ -82,9 +64,7 @@ function RootCategoryName($params) { - $root_phrase = $this->Application->ConfigValue('Root_Name'); - $ret = $this->Application->Phrase($root_phrase); - return $ret; + return $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params); } function CheckModuleRoot($params) @@ -111,63 +91,67 @@ function CategoryPath($params) { $module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce'; - $module =& $this->Application->recallObject('mod.'.$module_name); - $module_root_cat = $module->GetDBField('RootCat'); + $module_category_id = $this->Application->findModule('Name', $module_name, 'RootCat'); + $module_item_id = $this->Application->GetVar($this->Application->findModule('Name', $module_name, 'Var').'_id'); - $block_params['current'] = 0; $block_params['separator'] = $params['separator']; - if(!isset($params['cat_id'])) - { + if (!isset($params['cat_id'])) { $params['cat_id'] = getArrayValue($params, 'cat_id') ? $params['cat_id'] : $this->Application->GetVar('m_cat_id'); - $block_params['current'] = 1; } - $product_id = $this->Application->GetVar('p_id'); - if ($product_id) { - $block_params['current'] = 0; - } - $block_params['is_module_root'] = ($params['cat_id'] == $module_root_cat) ? 1 : 0; - - if($params['cat_id'] == 0) - { - $block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock'); + if ($params['cat_id'] == 0) { + $block_params['current'] = 1; + $block_params['cat_id'] = 0; + $block_params['cat_name'] = $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params); + $block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock,render_as'); return $this->Application->ParseBlock($block_params); } - else - { - $block_params['name'] = $this->SelectParam($params,'render_as,block'); - // $cat_object = &$this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix.'_List' ); - $sql = 'SELECT CategoryId, ParentId, '.$this->getTitleField().' AS Name - FROM '.$this->Application->getUnitOption($this->Prefix, 'TableName').' - WHERE CategoryId = '.$params['cat_id']; - $res = $this->Conn->GetRow($sql); - if ($res === false) { - // in case if category is deleted - return ''; - } + else { + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + $navbar_field = $ml_formatter->LangFieldName('CachedNavBar'); - $block_params['cat_name'] = $res['Name']; - $block_params['cat_id'] = $res['CategoryId']; + $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $sql = 'SELECT '.$navbar_field.', ParentPath + FROM '.$table_name.' + WHERE '.$id_field.' = '.$params['cat_id']; + $category_data = $this->Conn->GetRow($sql); + $ret = ''; + if ($category_data) { + $category_names = explode('&|&', $category_data[$navbar_field]); + $category_ids = explode('|', substr($category_data['ParentPath'], 1, -1)); - $parent_params = $params; - $parent_params['cat_id'] = $res['ParentId']; + // add "Home" category at beginning of path + array_unshift($category_names, $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params)); + array_unshift($category_ids, 0); - // which block to parse as current ? - if ($block_params['is_module_root'] == 1) { // module root - $block_params['name'] = $this->SelectParam($params, 'module_root_render_as,block_module_root,rootmoduleblock'); - } - if ($block_params['current'] == 1) { // current cat (label) - $block_params['name'] = $this->SelectParam($params, 'current_render_as,block_current,currentblock'); - } + foreach ($category_ids as $category_pos => $category_id) { + $block_params['cat_id'] = $category_id; + $block_params['cat_name'] = $category_names[$category_pos]; + $block_params['current'] = ($params['cat_id'] == $category_id) && !$module_item_id ? 1 : 0; + $block_params['is_module_root'] = $category_id == $module_category_id ? 1 : 0; + $block_params['name'] = $this->SelectParam($params, 'render_as,block'); - $this->Application->SetVar($this->Prefix.'_id', $res['CategoryId']); - $current_cat = $this->Application->ParseBlock($block_params, 1); + // which block to parse as current ? + if ($category_id == 0) { + $block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock,render_as,block'); + } - $this->Application->SetVar($this->Prefix.'_id', $res['ParentId']); - $parent_cat = $this->CategoryPath($parent_params); + if ($block_params['is_module_root'] == 1) { // module root + $block_params['name'] = $this->SelectParam($params, 'module_root_render_as,block_module_root,rootmoduleblock,render_as,block'); + } - return $parent_cat.$current_cat; + if ($block_params['current'] == 1) { // current cat (label) + $block_params['name'] = $this->SelectParam($params, 'current_render_as,block_current,currentblock,render_as,block'); + } + + $this->Application->SetVar($this->Prefix.'_id', $category_id); + $ret .= $this->Application->ParseBlock($block_params, 1); + } + } + + return $ret; } } @@ -185,15 +169,15 @@ $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); return $ml_formatter->LangFieldName('Name'); } - + function CategoryLink($params) { // 'p_id'=>'0', ?? $params = array_merge(array('pass'=>'m'), $params); $cat_id = getArrayValue($params,'cat_id'); if ($cat_id === false) { // $cat_id = $this->Application->Parser->GetParam('cat_id'); - $cat_id = $this->Application->GetVar($this->Prefix.'_id'); + $cat_id = $this->Application->GetVar($this->getPrefixSpecial().'_id'); } if($cat_id == 'Root') { @@ -235,7 +219,7 @@ if (isset($params['block_row_start'])) { $params['row_start_block'] = $params['block_row_start']; } - + if (isset($params['block_row_end'])) { $params['row_end_block'] = $params['block_row_end']; } @@ -282,7 +266,9 @@ $except = $this->SelectParam($params, 'except'); $no_special = isset($params['no_special']) && $params['no_special']; - if ($types.$except.$parent_cat_id == '' || $no_special) { + if ($no_special) return $this->Special; + + if ($types.$except.$parent_cat_id == '') { return parent::BuildListSpecial($params); } @@ -294,7 +280,7 @@ { return false; } - + /** * Substitutes category in last template base on current category * @@ -303,16 +289,16 @@ function UpdateLastTemplate($params) { $category_id = $this->Application->GetVar('m_cat_id'); - + list($index_file, $env) = explode('|', $this->Application->RecallVar('last_template'), 2); - $this->Application->SetVar(ENV_VAR_NAME, $env); + $this->Application->SetVar(ENV_VAR_NAME, str_replace('%5C', '\\', $env)); $this->Application->HttpQuery->processQueryString(); - + // update required fields $this->Application->SetVar('m_cat_id', $category_id); $this->Application->Session->SaveLastTemplate($params['template']); } - + function GetParentCategory($params) { $parent_id = 0; @@ -327,58 +313,58 @@ } return $parent_id; } - + function InitCacheUpdater($params) { safeDefine('CACHE_PERM_CHUNK_SIZE', 30); $continue = $this->Application->GetVar('continue'); $total_cats = (int) $this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Category'); - + if ($continue === false && $total_cats > CACHE_PERM_CHUNK_SIZE) { // first step, if category count > CACHE_PERM_CHUNK_SIZE, then ask for cache update return true; } - + if ($continue === false) { // if we don't have to ask, then assume user selected "Yes" in permcache update dialog $continue = 1; } - + $updater =& $this->Application->recallObject('kPermCacheUpdater', null, Array('continue' => $continue)); if ($continue === '0') { // No in dialog $updater->clearData(); $this->Application->Redirect($params['destination_template']); } - + $ret = false; // don't ask for update if ($continue == 1) { // Initial run $updater->setData(); } if ($continue == 2) { // Continuing // called from AJAX request => returns percent $needs_more = true; - while ($needs_more && $updater->iteration < CACHE_PERM_CHUNK_SIZE) { + while ($needs_more && $updater->iteration <= CACHE_PERM_CHUNK_SIZE) { // until proceeeded in this step category count exceeds category per step limit $needs_more = $updater->DoTheJob(); } - + if ($needs_more) { // still some categories are left for next step $updater->setData(); } else { // all done -> redirect $updater->clearData(); - $this->Application->StoreVar('PermCache_UpdateRequired', 0); + $this->Application->RemoveVar('PermCache_UpdateRequired'); $this->Application->Redirect($params['destination_template']); } - + $ret = $updater->getDonePercent(); } return $ret; } - + function SaveWarning($params) { $main_prefix = getArrayValue($params, 'main_prefix'); @@ -391,12 +377,12 @@ $temp_tables = $this->Application->GetVar($top_prefix.'_mode') == 't'; $modified = $this->Application->RecallVar($top_prefix.'_modified'); - + if (!$temp_tables) { $this->Application->RemoveVar($top_prefix.'_modified'); - return 'flag remoeved'; + return ''; } - + $block_name = $this->SelectParam($params, 'render_as,name'); if ($block_name) { $block_params = $this->prepareTagParams($params); @@ -410,6 +396,89 @@ } return ; } + + /** + * Allows to detect if this prefix has something in clipboard + * + * @param Array $params + * @return bool + */ + function HasClipboard($params) + { + $clipboard = $this->Application->RecallVar('clipboard'); + if ($clipboard) { + $clipboard = unserialize($clipboard); + foreach ($clipboard as $prefix => $clipboard_data) { + foreach ($clipboard_data as $mode => $ids) { + if (count($ids)) return 1; + } + } + } + return 0; + } + + /** + * Allows to detect if root category being edited + * + * @param Array $params + */ + function IsRootCategory($params) + { + $object =& $this->getObject($params); + return $object->IsRoot(); + } + + function CatalogItemCount($params) + { + $object =& $this->GetList($params); + if (!$object->Counted) { + $object->CountRecs(); + } + return $object->NoFilterCount != $object->RecordsCount ? $object->RecordsCount.' / '.$object->NoFilterCount : $object->RecordsCount; + } + + /** + * Print grid pagination using + * block names specified + * + * @param Array $params + * @return string + * @access public + */ + function PrintPages($params) + { + if ($this->Application->Parser->GetParam('no_special')) { + $params['no_special'] = $this->Application->Parser->GetParam('no_special'); + } + return parent::PrintPages($params); + } + + function InitCatalog($params) + { + $tab_prefixes = $this->Application->GetVar('tp'); // {all, , none} + if ($tab_prefixes === false) $tab_prefixes = 'all'; + $skip_prefixes = isset($params['skip_prefixes']) && $params['skip_prefixes'] ? explode(',', $params['skip_prefixes']) : Array(); + + // get all prefixes available + $prefixes = Array(); + foreach ($this->Application->ModuleInfo as $module_name => $module_data) { + if ($module_data['Var'] == 'm') continue; + $prefixes[] = $module_data['Var']; + } + + if ($tab_prefixes == 'none') { + $skip_prefixes = array_unique(array_merge($skip_prefixes, $prefixes)); + } + elseif ($tab_prefixes != 'all') { + // prefix list here + $tab_prefixes = explode(',', $tab_prefixes); // list of prefixes that should stay + $skip_prefixes = array_unique(array_merge($skip_prefixes, array_diff($prefixes, $tab_prefixes))); + } + + $params['name'] = $params['render_as']; + $params['skip_prefixes'] = implode(',', $skip_prefixes); + return $this->Application->ParseBlock($params, 1); + } }