ArticleAuthor::GetList PHP Method

GetList() public static method

Returns an article authors 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)
return array $articleAuthorsList An array of Author 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) ? 'order' : $p_order;
            $paramsArray['start'] = $p_start;
            $paramsArray['limit'] = $p_limit;
            $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
            $articleAuthorsList = $cacheListObj->fetchFromCache();
            if ($articleAuthorsList !== false && is_array($articleAuthorsList)) {
                return $articleAuthorsList;
            }
        }
        $hasArticleNr = false;
        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();
        // sets the where conditions
        foreach ($p_parameters as $param) {
            if ($param->getLeftOperand() == 'type') {
                $whereCondition = 'fk_type_id ' . $param->getOperator()->getSymbol() . ' (SELECT id FROM ' . AuthorType::TABLE . ' WHERE type="' . str_replace("'", "", $param->getRightOperand()) . '")';
                $selectClauseObj->addWhere($whereCondition);
                $countClauseObj->addWhere($whereCondition);
            }
            if ($param->getLeftOperand() == 'id') {
                $whereCondition = 'fk_author_id ' . $param->getOperator()->getSymbol() . ' ' . $param->getRightOperand();
                $selectClauseObj->addWhere($whereCondition);
                $countClauseObj->addWhere($whereCondition);
            }
            $comparisonOperation = self::ProcessListParameters($param);
            if (sizeof($comparisonOperation) < 1) {
                break;
            }
            switch (key($comparisonOperation)) {
                case 'fk_article_number':
                    $whereCondition = 'fk_article_number = ' . $comparisonOperation['fk_article_number'];
                    $hasArticleNr = true;
                    break;
                case 'fk_language_id':
                    $whereCondition = '(fk_language_id IS NULL OR ' . 'fk_language_id = ' . $comparisonOperation['fk_language_id'] . ')';
                    break;
            }
            $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_authors");
        }
        // sets the base table ArticleAuthors and the column to be fetched
        $tmpArticleAuthor = new ArticleAuthor();
        $selectClauseObj->setTable($tmpArticleAuthor->getDbTableName());
        $selectClauseObj->addJoin('JOIN ' . Author::TABLE . ' ON fk_author_id = id');
        $selectClauseObj->addColumn('fk_author_id');
        $selectClauseObj->addColumn('fk_type_id');
        $countClauseObj->setTable($tmpArticleAuthor->getDbTableName());
        $countClauseObj->addColumn('COUNT(*)');
        unset($tmpArticleAuthor);
        if (!is_array($p_order)) {
            $p_order = array();
        }
        $order = self::ProcessListOrder($p_order);
        // sets the order condition if any
        foreach ($order as $orderDesc) {
            $orderField = $orderDesc['field'];
            $orderDirection = $orderDesc['dir'];
            $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
        }
        // sets the limit
        $selectClauseObj->setLimit($p_start, $p_limit);
        // builds the query and executes it
        $selectQuery = $selectClauseObj->buildQuery();
        $authors = $g_ado_db->GetAll($selectQuery);
        if (is_array($authors)) {
            $countQuery = $countClauseObj->buildQuery();
            $p_count = $g_ado_db->GetOne($countQuery);
            // builds the array of attachment objects
            $authorsList = array();
            foreach ($authors as $author) {
                $authorObj = new Author($author['fk_author_id'], $author['fk_type_id']);
                if ($authorObj->exists()) {
                    $authorsList[] = $authorObj;
                }
            }
        } else {
            $authorsList = array();
            $p_count = 0;
        }
        if (!$p_skipCache && CampCache::IsEnabled()) {
            $cacheListObj->storeInCache($authorsList);
        }
        return $authorsList;
    }

Usage Example

Beispiel #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)
 {
     $articleAuthorsList = ArticleAuthor::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
     $metaAuthorsList = array();
     foreach ($articleAuthorsList as $author) {
         $authorTypeId = NULL;
         if (!is_null($author->getAuthorType()) && $author->getAuthorType()->exists()) {
             $authorTypeId = $author->getAuthorType()->getId();
         }
         $metaAuthorsList[] = new MetaAuthor($author->getId(), $authorTypeId);
     }
     return $metaAuthorsList;
 }
All Usage Examples Of ArticleAuthor::GetList