Index: branches/5.3.x/core/units/helpers/count_helper.php =================================================================== diff -u -N -r15483 -r15698 --- branches/5.3.x/core/units/helpers/count_helper.php (.../count_helper.php) (revision 15483) +++ branches/5.3.x/core/units/helpers/count_helper.php (.../count_helper.php) (revision 15698) @@ -1,6 +1,6 @@ Application->findModule('Var', $prefix)) { + if ( !$this->Application->findModule('Var', $prefix) ) { // this is not module item return $this->Application->ProcessParsedTag($prefix, 'CategoryItemCount', $params); } // 1. get root category for counting $category_id = isset($params['cat_id']) ? $params['cat_id'] : false; - if (!is_numeric($category_id)) { + if ( !is_numeric($category_id) ) { $category_id = $this->Application->GetVar('m_cat_id'); } - if (!isset($count_sql)) { + if ( !isset($count_sql) ) { $count_sql = 'COUNT(*)'; } $where_clauses = Array (); - $table_name = $this->Application->getUnitOption($prefix, 'TableName'); + $table_name = $this->Application->getUnitConfig($prefix)->getTableName(); // 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.'Categories c ON (ci.CategoryId = c.CategoryId)'; + $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 . 'Categories c ON (ci.CategoryId = c.CategoryId)'; // 2. count items from subcategories - if ($category_id > 0) { + if ( $category_id > 0 ) { // get subcategories of required category $tmp_sql = 'SELECT TreeLeft, TreeRight - FROM '.TABLE_PREFIX.'Categories - WHERE CategoryId = '.$category_id; + FROM ' . TABLE_PREFIX . 'Categories + WHERE CategoryId = ' . $category_id; $tree_info = $this->Conn->GetRow($tmp_sql); - $where_clauses[] = 'c.TreeLeft BETWEEN '.$tree_info['TreeLeft'].' AND '.$tree_info['TreeRight']; + $where_clauses[] = 'c.TreeLeft BETWEEN ' . $tree_info['TreeLeft'] . ' AND ' . $tree_info['TreeRight']; } - $where_clauses[] = 'item_table.Status = '.STATUS_ACTIVE; + $where_clauses[] = 'item_table.Status = ' . STATUS_ACTIVE; - 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; + 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; } - $sql .= ' WHERE ('.implode(') AND (', $where_clauses).')'; + $sql .= ' WHERE (' . implode(') AND (', $where_clauses) . ')'; return (int)$this->Conn->GetOne($sql); } @@ -179,29 +179,32 @@ */ function ItemCount($prefix, $today = false, $count_sql = null) { - $table_name = $this->Application->getUnitOption($prefix, 'TableName'); + $table_name = $this->Application->getUnitConfig($prefix)->getTableName(); - if (!isset($count_sql)) { - $count_sql = 'COUNT(*)'; - } + if ( !isset($count_sql) ) { + $count_sql = 'COUNT(*)'; + } - $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.'Categories c ON c.CategoryId = ci.CategoryId - INNER JOIN '.TABLE_PREFIX.'CategoryPermissionsCache perm_cache ON ci.CategoryId = perm_cache.CategoryId'; + $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 . 'Categories c ON c.CategoryId = ci.CategoryId + INNER JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache 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, + 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; - } + 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).')'; + $sql .= ' WHERE (' . implode(') AND (', $where_clauses) . ')'; return (int)$this->Conn->GetOne($sql); } @@ -214,42 +217,42 @@ */ function CategoryCount($today = false) { - $cache_key = 'category_count[%CSerial%]'; + $cache_key = 'category_count[%CSerial%]'; - if ($today) { - $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); - $cache_key .= ':date=' . $today_date; - } + if ( $today ) { + $today_date = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), adodb_date('Y')); + $cache_key .= ':date=' . $today_date; + } - $count = $this->Application->getCache($cache_key); + $count = $this->Application->getCache($cache_key); - if ($count === false) { + if ( $count === false ) { $sql = 'SELECT COUNT(*) - FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' c + FROM ' . $this->Application->getUnitConfig('c')->getTableName() . ' c INNER JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm_cache ON c.CategoryId = perm_cache.CategoryId'; - list ($view_perm, $view_filter) = $this->GetPermissionClause('c', 'perm_cache'); + list ($view_perm, $view_filter) = $this->GetPermissionClause('c', 'perm_cache'); - $where_clauses = Array ( - $view_filter, - 'perm_cache.PermId = ' . $view_perm, - 'c.Status = ' . STATUS_ACTIVE, + $where_clauses = Array ( + $view_filter, + 'perm_cache.PermId = ' . $view_perm, + 'c.Status = ' . STATUS_ACTIVE, ); - if ($today) { - $where_clauses[] = 'c.CreatedOn >= ' . $today_date; - } + if ( $today ) { + $where_clauses[] = 'c.CreatedOn >= ' . $today_date; + } - $sql .= ' WHERE ('.implode(') AND (', $where_clauses).')'; + $sql .= ' WHERE (' . implode(') AND (', $where_clauses) . ')'; $count = $this->Conn->GetOne($sql); - if ($count !== false) { + if ( $count !== false ) { $this->Application->setCache($cache_key, $count); } - } + } - return $count; + return $count; } /** @@ -263,24 +266,24 @@ { $permissions_ids = $this->Application->getCache(__CLASS__ . '::' . __FUNCTION__); - if ($permissions_ids === false) { + if ( $permissions_ids === false ) { $this->Conn->nextQueryCachable = true; $sql = 'SELECT PermissionConfigId, PermissionName - FROM '.TABLE_PREFIX.'CategoryPermissionsConfig + FROM ' . TABLE_PREFIX . 'CategoryPermissionsConfig WHERE PermissionName LIKE "%.VIEW"'; $permissions_ids = $this->Conn->GetCol($sql, 'PermissionName'); $this->Application->setCache(__CLASS__ . '::' . __FUNCTION__, $permissions_ids); } - $permission_prefix = $this->Application->getUnitOption($prefix, 'PermItemPrefix'); + $permission_prefix = $this->Application->getUnitConfig($prefix)->getPermItemPrefix(); $view_perm = $permissions_ids[$permission_prefix . '.VIEW']; $groups = explode(',', $this->Application->RecallVar('UserGroups')); foreach ($groups as $group) { - $view_filters[] = 'FIND_IN_SET('.$group.', '.$table_alias.'.acl)'; + $view_filters[] = 'FIND_IN_SET(' . $group . ', ' . $table_alias . '.acl)'; } $view_filter = implode(' OR ', $view_filters);