ArticleImage::GetList PHP Method

GetList() public static method

Returns an article images list based on the given parameters.
public static GetList ( array $p_parameters, array $p_order = [], integer $p_start, integer $p_limit, integer &$p_count, $p_skipCache = false ) : array
$p_parameters array An array of ComparisonOperation objects
$p_order array 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 $articleImagesList An array of Image objects
    public static function GetList(array $p_parameters, array $p_order = array(), $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false)
    {
        global $g_ado_db;
        if (!$p_skipCache) {
            $paramsArray['parameters'] = serialize($p_parameters);
            $paramsArray['order'] = is_null($p_order) ? 'null' : serialize($p_order);
            $paramsArray['start'] = $p_start;
            $paramsArray['limit'] = $p_limit;
            $paramsArray['method'] = __METHOD__;
            $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
            $cacheKey = $cacheService->getCacheKey($paramsArray, 'article');
            if ($cacheService->contains($cacheKey)) {
                $articleImagesList = $cacheService->fetch($cacheKey);
                if ($articleImagesList !== false && is_array($articleImagesList)) {
                    return $articleImagesList;
                }
            }
        }
        $hasArticleNr = false;
        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();
        // sets the where conditions
        foreach ($p_parameters as $param) {
            $comparisonOperation = self::ProcessListParameters($param);
            if (sizeof($comparisonOperation) < 3) {
                break;
            }
            if (strpos($comparisonOperation['left'], 'NrArticle')) {
                $hasArticleNr = true;
            }
            $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('Missing parameter Article ' . 'Number in statement list_article_images');
            return;
        }
        // sets the columns to be fetched
        $tmpImage = new Image();
        $columnNames = $tmpImage->getColumnNames(true);
        foreach ($columnNames as $columnName) {
            $selectClauseObj->addColumn($columnName);
        }
        $countClauseObj->addColumn('COUNT(*)');
        // sets the base table Attachment
        $selectClauseObj->setTable($tmpImage->getDbTableName());
        $countClauseObj->setTable($tmpImage->getDbTableName());
        unset($tmpImage);
        // adds the ArticleImages join and condition to the query
        $selectClauseObj->addTableFrom('ArticleImages');
        $selectClauseObj->addWhere('ArticleImages.IdImage = Images.Id');
        $countClauseObj->addTableFrom('ArticleImages');
        $countClauseObj->addWhere('ArticleImages.IdImage = Images.Id');
        // sets the ORDER BY condition
        $p_order = array_merge($p_order, self::$s_defaultOrder);
        $order = self::ProcessListOrder($p_order);
        foreach ($order as $orderDesc) {
            $orderColumn = $orderDesc['field'];
            $orderDirection = $orderDesc['dir'];
            $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
        }
        // sets the limit
        $selectClauseObj->setLimit($p_start, $p_limit);
        // builds the query executes it
        $selectQuery = $selectClauseObj->buildQuery();
        $images = $g_ado_db->GetAll($selectQuery);
        if (is_array($images)) {
            $countQuery = $countClauseObj->buildQuery();
            $p_count = $g_ado_db->GetOne($countQuery);
            // builds the array of image objects
            $articleImagesList = array();
            foreach ($images as $image) {
                $imgObj = new Image($image['Id']);
                if ($imgObj->exists()) {
                    $articleImagesList[] = $imgObj;
                }
            }
        } else {
            $articleImagesList = array();
            $p_count = 0;
        }
        if (!$p_skipCache) {
            $cacheService->save($cacheKey, $articleImagesList);
        }
        return $articleImagesList;
    }

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)
	{
	    $articleImagesList = ArticleImage::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
	    $metaImagesList = array();
	    foreach ($articleImagesList as $image) {
	        $metaImagesList[] = new MetaImage($image->getImageId());
	    }
	    return $metaImagesList;
	}
All Usage Examples Of ArticleImage::GetList