/** * Gets an issues list based on the given parameters. * * @param array $p_parameters * An array of ComparisonOperation objects * @param string $p_order * An array of columns and directions to order by * @param integer $p_start * The record number to start the list * @param integer $p_limit * The offset. How many records from $p_start will be retrieved. * @param integer $p_count * The total count of the elements; this count is computed without * applying the start ($p_start) and limit parameters ($p_limit) * * @return array $issuesList * An array of Issue objects */ public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false) { global $g_ado_db; if (!$p_skipCache && CampCache::IsEnabled()) { $paramsArray['parameters'] = serialize($p_parameters); $paramsArray['order'] = (is_null($p_order)) ? 'null' : $p_order; $paramsArray['start'] = $p_start; $paramsArray['limit'] = $p_limit; $cacheListObj = new CampCacheList($paramsArray, __METHOD__); $issuesList = $cacheListObj->fetchFromCache(); if ($issuesList !== false && is_array($issuesList)) { return $issuesList; } } $hasPublicationId = false; $selectClauseObj = new SQLSelectClause(); $countClauseObj = new SQLSelectClause(); // sets the where conditions foreach ($p_parameters as $param) { $comparisonOperation = self::ProcessListParameters($param); if (empty($comparisonOperation)) { break; } if (strpos($comparisonOperation['left'], 'IdPublication') !== false) { $hasPublicationId = true; } $whereCondition = $comparisonOperation['left'] . ' ' . $comparisonOperation['symbol'] . " '" . $g_ado_db->escape($comparisonOperation['right']) . "' "; $selectClauseObj->addWhere($whereCondition); $countClauseObj->addWhere($whereCondition); } // validates whether publication identifier was given if ($hasPublicationId == false) { CampTemplate::singleton()->trigger_error('missed parameter Publication ' .'Identifier in statement list_topics'); return; } // sets the columns to be fetched $tmpIssue = new Issue(); $columnNames = $tmpIssue->getColumnNames(true); foreach ($columnNames as $columnName) { $selectClauseObj->addColumn($columnName); } $countClauseObj->addColumn('COUNT(*)'); // sets the main table for the query $selectClauseObj->setTable($tmpIssue->getDbTableName()); $countClauseObj->setTable($tmpIssue->getDbTableName()); unset($tmpIssue); if (is_array($p_order)) { $order = Issue::ProcessListOrder($p_order); // sets the order condition if any foreach ($order as $orderDesc) { $orderField = $orderDesc['field']; $orderDirection = $orderDesc['dir']; $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection); } } $selectClauseObj->addGroupField('Number'); $selectClauseObj->addGroupField('IdLanguage'); // sets the limit $selectClauseObj->setLimit($p_start, $p_limit); // builds the query and executes it $selectQuery = $selectClauseObj->buildQuery(); $countQuery = $countClauseObj->buildQuery(); $issues = $g_ado_db->GetAll($selectQuery); if (is_array($issues)) { $p_count = $g_ado_db->GetOne($countQuery); // builds the array of issue objects $issuesList = array(); foreach ($issues as $issue) { $issObj = new Issue($issue['IdPublication'], $issue['IdLanguage'], $issue['Number']); if ($issObj->exists()) { $issuesList[] = $issObj; } } } else { $issuesList = array(); $p_count = 0; } if (!$p_skipCache && CampCache::IsEnabled()) { $cacheListObj->storeInCache($issuesList); } return $issuesList; } // fn GetList
/** * Get all the topics in an array, where each element contains the entire * path for each topic. Each topic will be indexed by its ID. * For example, if we have the following topic structure (IDs are * in brackets): * * sports (1) * - baseball (2) * - soccer (3) * - player stats (4) * - matches (5) * politics (6) * - world (7) * - local (8) * * ...then the returned array would look like: * array(array(1 => "sports"), * array(1 => "sports", 2 => "baseball"), * array(1 => "sports", 3 => "soccer"), * array(1 => "sports", 3 => "soccer", 4 => "player stats"), * array(1 => "sports", 3 => "soccer", 5 => "matches"), * array(6 => "politics"), * array(6 => "politics", 7 => "world"), * array(6 => "politics", 8 => "local") * ); * * @param int $p_startingTopicId * @return array */ public static function GetTree($p_startingTopicId = 0) { global $g_ado_db; $topicObj = new Topic(); $query = new SQLSelectClause(); $query->addColumn('node.id'); $query->addColumn('(COUNT(parent.id) - 1) AS depth'); $query->setTable($topicObj->m_dbTableName . ' AS node'); $query->addTableFrom($topicObj->m_dbTableName . ' AS parent'); $query->addWhere('node.node_left BETWEEN parent.node_left AND parent.node_right'); if ($p_startingTopicId > 0) { $query->addTableFrom($topicObj->m_dbTableName . ' AS sub_parent'); $query->addWhere('node.node_left > sub_parent.node_left'); $query->addWhere('node.node_left < sub_parent.node_right'); $query->addWhere('sub_parent.id = ' . (int) $p_startingTopicId); } $query->addGroupField('node.id'); $query->addOrderBy('node.node_left'); $rows = $g_ado_db->GetAll($query->buildQuery()); if (empty($rows)) { // empty tree return array(); } $p_tree = array(); $startDepth = null; $currentPath = array(); foreach ($rows as $row) { $topicId = $row['id']; $depth = $row['depth'] - (int) $startDepth; $topic = new Topic($topicId); if (is_null($startDepth)) { $startDepth = $depth; $depth = 0; $currentPath[$topicId] = $topic; } elseif ($depth > count($currentPath)) { $currentPath[$topicId] = $topic; } elseif ($depth == 0) { $currentPath = array($topicId => $topic); } else { while ($depth < count($currentPath)) { array_pop($currentPath); } $currentPath[$topicId] = $topic; } $p_tree[] = $currentPath; } return $p_tree; }