0) AND (LastCounted < '.adodb_mktime().' - LifeTime)'; $this->Conn->Query($sql); } /** * Returns counter value * * @param string $name counter name * @param Array $params counter parameters * @param string $query_name specify query name directly (don't generate from parmeters) * @param bool $multiple_results * @return mixed */ function getCounter($name, $params = Array (), $query_name = null, $multiple_results = false) { $clone_counter = false; $query_name = isset($query_name) ? $query_name : rtrim($name.'-'.implode('-', array_values($params)), '-'); $sql = 'SELECT * FROM '.TABLE_PREFIX.'Counters WHERE Name = '.$this->Conn->qstr($query_name); $count_data = $this->Conn->GetRow($sql); if (!$count_data && ($query_name != $name)) { // cloned record not found -> search for origial one $sql = 'SELECT * FROM '.TABLE_PREFIX.'Counters WHERE Name = '.$this->Conn->qstr($name); $count_data = $this->Conn->GetRow($sql); $clone_counter = true; } if (is_null($count_data['CountValue'])) { $params['PREFIX'] = TABLE_PREFIX; $count_sql = $count_data['CountQuery']; foreach ($params as $replace_from => $replace_to) { $count_sql = str_replace('<%'.$replace_from.'%>', $replace_to, $count_sql); } if ($multiple_results) { $count_data['CountValue'] = serialize($this->Conn->GetCol($count_sql)); } else { $count_data['CountValue'] = $this->Conn->GetOne($count_sql); } if ($clone_counter && !$count_data['IsClone']) { // don't clone clones $count_data['CounterId'] = 0; $count_data['Name'] = $query_name; $count_data['IsClone'] = 1; } $count_data['LastCounted'] = adodb_mktime(); $this->Conn->doInsert($count_data, TABLE_PREFIX.'Counters', 'REPLACE'); } return $multiple_results ? unserialize($count_data['CountValue']) : $count_data['CountValue']; } /** * Resets counter, whitch are affected by one of specified tables * * @param string $tables comma separated tables list used in counting sqls */ function resetCounters($tables) { $tables = explode(',', $tables); $prefix_length = strlen(TABLE_PREFIX); foreach ($tables as $index => $table) { // remove prefixes if (substr($table, 0, $prefix_length) == TABLE_PREFIX) { $table = substr($table, $prefix_length); } $tables[$index] = '(TablesAffected LIKE "%|'.$table.'|%")'; } $sql = 'UPDATE '.TABLE_PREFIX.'Counters SET CountValue = NULL WHERE '.implode(' OR ', $tables); $this->Conn->Query($sql); } function CategoryItemCount($prefix, $params, $count_sql = null) { 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['_catid']) ? $params['_catid'] : false; if (!is_numeric($category_id)) { $category_id = $this->Application->GetVar('m_cat_id'); } if (!isset($count_sql)) { $count_sql = 'COUNT(*)'; } $where_clauses = Array (); $table_name = $this->Application->getUnitOption($prefix, 'TableName'); $sql = 'SELECT '.$count_sql.' FROM '.$table_name.' item_table INNER JOIN '.TABLE_PREFIX.'CategoryItems ci ON (ci.ItemResourceId = item_table.ResourceId)'; 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.')'; } } else { $where_clauses[] = 'ci.CategoryId = '.$category_id; } $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; } $sql .= ' WHERE ('.implode(') AND (', $where_clauses).')'; return (int)$this->Conn->GetOne($sql); } } ?>