ArticleTopic::GetList PHP Метод

GetList() публичный статический Метод

Returns an article topics list based on the given parameters.
public static GetList ( array $p_parameters, string $p_order = null, integer $p_start, integer $p_limit, integer &$p_count, $p_skipCache = false ) : array
$p_parameters array An array of ComparisonOperation objects
$p_order string An array of columns and directions to order by
$p_start integer The record number to start the list
$p_limit integer The offset. How many records from $p_start will be retrieved.
$p_count integer The total count of the elements; this count is computed without applying the start ($p_start) and limit parameters ($p_limit)
Результат array $articleTopicsList An array of Topic 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__);
            $articleTopicsList = $cacheListObj->fetchFromCache();
            if ($articleTopicsList !== false && is_array($articleTopicsList)) {
                return $articleTopicsList;
            }
        }
        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();
        $rootTopicIds = array();
        // processes the parameters
        $hasArticleNr = false;
        foreach ($p_parameters as $parameter) {
            $comparisonOperation = self::ProcessListParameters($parameter);
            if (sizeof($comparisonOperation) < 1) {
                break;
            }
            if (strpos($comparisonOperation['left'], 'NrArticle') !== false) {
                $hasArticleNr = true;
            }
            if (strpos($comparisonOperation['left'], 'RootTopic') !== false) {
                $rootTopicIds[] = (int) $comparisonOperation['right'];
                continue;
            }
            $whereCondition = $g_ado_db->escapeOperation($comparisonOperation);
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }
        // validates whether article number was given
        if ($hasArticleNr === false) {
            CampTemplate::singleton()->trigger_error("missed parameter Article Number in statement list_article_topics");
            return array();
        }
        if (count($rootTopicIds) > 0) {
            $subtopicsQuery = self::buildSubtopicsArray($rootTopicIds);
            if (!empty($subtopicsQuery)) {
                $whereCondition = 'TopicId IN (' . implode(',', $subtopicsQuery) . ')';
                $selectClauseObj->addWhere($whereCondition);
                $countClauseObj->addWhere($whereCondition);
            }
        }
        // sets the main table and columns to be fetched
        $tmpArticleTopic = new ArticleTopic();
        $selectClauseObj->setTable($tmpArticleTopic->getDbTableName());
        $selectClauseObj->addColumn('TopicId');
        $countClauseObj->setTable($tmpArticleTopic->getDbTableName());
        $countClauseObj->addColumn('COUNT(*)');
        unset($tmpArticleTopic);
        if (!is_array($p_order)) {
            $p_order = array();
        }
        // sets the order condition if any
        foreach ($p_order as $orderColumn => $orderDirection) {
            $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
        }
        // sets the limit
        $selectClauseObj->setLimit($p_start, $p_limit);
        // builds the query and executes it
        $selectQuery = $selectClauseObj->buildQuery();
        $topics = $g_ado_db->GetAll($selectQuery);
        if (is_array($topics)) {
            $countQuery = $countClauseObj->buildQuery();
            $p_count = $g_ado_db->GetOne($countQuery);
            // builds the array of topic objects
            $articleTopicsList = array();
            foreach ($topics as $topic) {
                $articleTopicsList[] = $topic['TopicId'];
            }
        } else {
            $articleTopicsList = array();
            $p_count = 0;
        }
        if (!$p_skipCache && CampCache::IsEnabled()) {
            $cacheListObj->storeInCache($articleTopicsList);
        }
        return $articleTopicsList;
    }

Usage Example

Пример #1
0
 /**
  * Creates the list of objects. Sets the parameter $p_hasNextElements to
  * true if this list is limited and elements still exist in the original
  * list (from which this was truncated) after the last element of this
  * list.
  *
  * @param int $p_start
  * @param int $p_limit
  * @param array $p_parameters
  * @param int &$p_count
  * @return array
  */
 protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
 {
     $articleTopicsList = ArticleTopic::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
     $metaTopicsList = array();
     foreach ($articleTopicsList as $topic) {
         $metaTopicsList[] = new MetaTopic($topic);
     }
     return $metaTopicsList;
 }
All Usage Examples Of ArticleTopic::GetList