Index: branches/RC/core/units/categories/categories_tag_processor.php =================================================================== diff -u -r8993 -r9001 --- branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 8993) +++ branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 9001) @@ -14,7 +14,21 @@ } return $object->GetDBField('CachedDescendantCatsQty'); + } + /** + * Returns category count in system + * + * @param Array $params + * @return int + */ + function CategoryCount($params) + { + $count_helper =& $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + $today_only = isset($params['today']) && $params['today']; + return $count_helper->CategoryCount($today_only); } function IsNew($params) @@ -66,12 +80,10 @@ $cat_object =& $this->getObject($params); $ci_table = $this->Application->getUnitOption('l-ci', 'TableName'); - $sql = ' SELECT COUNT(*) - FROM '.$cat_object->TableName.' c - LEFT JOIN '.$ci_table.' ci - ON c.CategoryId=ci.CategoryId - WHERE c.ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%" - AND NOT (ci.CategoryId IS NULL)'; + $sql = 'SELECT COUNT(*) + FROM '.$cat_object->TableName.' c + LEFT JOIN '.$ci_table.' ci ON c.CategoryId=ci.CategoryId + WHERE c.ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%" AND NOT (ci.CategoryId IS NULL)'; return $this->Conn->GetOne($sql); } @@ -571,9 +583,7 @@ $object =& $this->getObject($params); /* @var $object kDBList */ - $params['_subcats'] = 1; - $params['_countcurrent'] = 1; - $params['_catid'] = $object->GetID(); + $params['cat_id'] = $object->GetID(); $count_helper =& $this->Application->recallObject('CountHelper'); /* @var $count_helper kCountHelper */ Index: branches/RC/core/units/general/helpers/count_helper.php =================================================================== diff -u -r8993 -r9001 --- branches/RC/core/units/general/helpers/count_helper.php (.../count_helper.php) (revision 8993) +++ branches/RC/core/units/general/helpers/count_helper.php (.../count_helper.php) (revision 9001) @@ -94,6 +94,14 @@ $this->Conn->Query($sql); } + /** + * Counts items (of specific type) in category & subcategories + * + * @param string $prefix + * @param Array $params + * @param mixed $count_sql + * @return int + */ function CategoryItemCount($prefix, $params, $count_sql = null) { if (!$this->Application->findModule('Var', $prefix)) { @@ -102,7 +110,7 @@ } // 1. get root category for counting - $category_id = isset($params['_catid']) ? $params['_catid'] : false; + $category_id = isset($params['cat_id']) ? $params['cat_id'] : false; if (!is_numeric($category_id)) { $category_id = $this->Application->GetVar('m_cat_id'); } @@ -114,33 +122,24 @@ $where_clauses = Array (); $table_name = $this->Application->getUnitOption($prefix, 'TableName'); + // 1. count category items $sql = 'SELECT '.$count_sql.' FROM '.$table_name.' item_table - INNER JOIN '.TABLE_PREFIX.'CategoryItems ci ON (ci.ItemResourceId = item_table.ResourceId)'; + INNER JOIN '.TABLE_PREFIX.'CategoryItems ci ON (ci.ItemResourceId = item_table.ResourceId) + INNER JOIN '.TABLE_PREFIX.'Category c ON (ci.CategoryId = c.CategoryId)'; - if (isset($params['_subcats']) && $params['_subcats']) { - $sql .= ' INNER JOIN '.TABLE_PREFIX.'Category c ON (ci.CategoryId = c.CategoryId)'; - - if ($category_id > 0) { - // get subcategories of required category - $tmp_sql = 'SELECT TreeLeft, TreeRight - FROM '.TABLE_PREFIX.'Category - WHERE CategoryId = '.$category_id; - $tree_info = $this->Conn->GetRow($tmp_sql); - $where_clauses[] = 'c.TreeLeft BETWEEN '.$tree_info['TreeLeft'].' AND '.$tree_info['TreeRight']; - } - - $count_current = isset($params['_countcurrent']) && $params['_countcurrent'] ? true : false; - if (!$count_current) { - $where_clauses[] = 'c.CategoryId <> '.$category_id.')'; - } + // 2. count items from subcategories + if ($category_id > 0) { + // get subcategories of required category + $tmp_sql = 'SELECT TreeLeft, TreeRight + FROM '.TABLE_PREFIX.'Category + WHERE CategoryId = '.$category_id; + $tree_info = $this->Conn->GetRow($tmp_sql); + $where_clauses[] = 'c.TreeLeft BETWEEN '.$tree_info['TreeLeft'].' AND '.$tree_info['TreeRight']; } - else { - $where_clauses[] = 'ci.CategoryId = '.$category_id; - } $where_clauses[] = 'item_table.Status = '.STATUS_ACTIVE; - if (isset($params['_today']) && $params['_today']) { + if (isset($params['today']) && $params['today']) { $today = adodb_mktime(0,0,0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); $where_clauses[] = 'item_table.CreatedOn >= '.$today; } @@ -150,6 +149,91 @@ return (int)$this->Conn->GetOne($sql); } + /** + * Counts items (of specific type) from all categories + * + * @param string $prefix + * @param bool $today + * @return int + */ + function ItemCount($prefix, $today = false) + { + $table_name = $this->Application->getUnitOption($prefix, 'TableName'); + + $sql = 'SELECT COUNT(*) + FROM '.$table_name.' item_table + INNER JOIN '.TABLE_PREFIX.'CategoryItems ci ON ci.ItemResourceId = item_table.ResourceId + INNER JOIN '.TABLE_PREFIX.'Category c ON c.CategoryId = ci.CategoryId + INNER JOIN '.TABLE_PREFIX.'PermCache perm_cache ON ci.CategoryId = perm_cache.CategoryId'; + + list ($view_perm, $view_filter) = $this->GetPermissionClause($prefix, 'perm_cache'); + $where_clauses = Array ( + $view_filter, 'perm_cache.PermId = '.$view_perm, 'ci.PrimaryCat = 1', 'c.Status = '.STATUS_ACTIVE, + ); + + if ($today) { + $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); + $where_clauses[] = 'item_table.CreatedOn >= '.$today_date; + } + + $sql .= ' WHERE ('.implode(') AND (', $where_clauses).')'; + + return $this->Conn->GetOne($sql); + } + + /** + * Returns categories count in system + * + * @param bool $today + * @return int + */ + function CategoryCount($today = false) + { + $table_name = $this->Application->getUnitOption('c', 'TableName'); + + $sql = 'SELECT COUNT(*) + FROM '.$table_name.' c + INNER JOIN '.TABLE_PREFIX.'PermCache perm_cache ON c.CategoryId = perm_cache.CategoryId'; + + list ($view_perm, $view_filter) = $this->GetPermissionClause('c', 'perm_cache'); + $where_clauses = Array ( + $view_filter, 'perm_cache.PermId = '.$view_perm, 'c.Status = '.STATUS_ACTIVE, + ); + + if ($today) { + $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); + $where_clauses[] = 'c.CreatedOn >= '.$today_date; + } + + $sql .= ' WHERE ('.implode(') AND (', $where_clauses).')'; + + return $this->Conn->GetOne($sql); + } + + /** + * Returns permission limitation clause for category item lists + * + * @param string $prefix + * @param string $table_alias + * @return Array + */ + function GetPermissionClause($prefix, $table_alias) + { + $sql = 'SELECT PermissionConfigId + FROM '.TABLE_PREFIX.'PermissionConfig + WHERE PermissionName = "'.$this->Application->getUnitOption($prefix, 'PermItemPrefix').'.VIEW"'; + $view_perm = $this->Conn->GetOne($sql); + + $groups = explode(',', $this->Application->RecallVar('UserGroups')); + foreach ($groups as $group) { + $view_filters[] = 'FIND_IN_SET('.$group.', '.$table_alias.'.acl)'; + } + + $view_filter = implode(' OR ', $view_filters); + + return Array ($view_perm, $view_filter); + } + } ?> \ No newline at end of file Index: branches/RC/core/units/general/cat_tag_processor.php =================================================================== diff -u -r8991 -r9001 --- branches/RC/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 8991) +++ branches/RC/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 9001) @@ -512,6 +512,21 @@ return adodb_date($format, $date); } + + /** + * Counts category item count in system (not category-dependent) + * + * @param Array $params + * @return int + */ + function ItemCount($params) + { + $count_helper =& $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ + + $today_only = isset($params['today']) && $params['today']; + return $count_helper->ItemCount($this->Prefix, $today_only); + } } ?> \ No newline at end of file Index: branches/RC/core/units/general/cat_event_handler.php =================================================================== diff -u -r8929 -r9001 --- branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8929) +++ branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 9001) @@ -388,17 +388,10 @@ } else { // for any real user itemlist view permission is checked instead of CATEGORY.VIEW - $sql = 'SELECT PermissionConfigId - FROM '.TABLE_PREFIX.'PermissionConfig - WHERE PermissionName = "'.$this->Application->getUnitOption($event->Prefix, 'PermItemPrefix').'.VIEW"'; - $view_perm = $this->Conn->GetOne($sql); + $count_helper =& $this->Application->recallObject('CountHelper'); + /* @var $count_helper kCountHelper */ - $groups = explode( ',', $this->Application->RecallVar('UserGroups') ); - foreach($groups as $group) - { - $view_filters[] = 'FIND_IN_SET('.$group.', perm.acl)'; - } - $view_filter = implode(' OR ', $view_filters); + list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($event->Prefix, 'perm'); $object->addFilter('perm_filter2', $view_filter); } Index: branches/RC/themes/default2007/platform/elements/content_boxes/sub_categories.tpl =================================================================== diff -u -r8991 -r9001 --- branches/RC/themes/default2007/platform/elements/content_boxes/sub_categories.tpl (.../sub_categories.tpl) (revision 8991) +++ branches/RC/themes/default2007/platform/elements/content_boxes/sub_categories.tpl (.../sub_categories.tpl) (revision 9001) @@ -3,13 +3,13 @@ - + ()
- :  |  : 0 + :  |  : :