setLimit() public method

Sets the LIMIT of the query.
public setLimit ( integer $p_start, integer $p_offset ) : void
$p_start integer The number where the query will start to fetch data
$p_offset integer The number of rows to be fetched
return void
示例#1
0
 /**
  * Returns an article topics 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 $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 = Topic::BuildSubtopicsQueryWithoutDepth($rootTopicIds);
         $whereCondition = 'TopicId IN (' . $subtopicsQuery->buildQuery() . ')';
         $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;
 }
示例#2
0
    /**
     * Performs a search against the given article field using the given
     * keywords. Returns the list of articles matching the given criteria.
     *
     * @param array $p_keywords
     * @param string $p_fieldName - may be 'title' or 'author'
     * @param bool $p_matchAll - true if all keyword have to match
     * @param array $p_constraints
     * @param array $p_order
     * @param int $p_start - return results starting from the given order number
     * @param int $p_limit - return at most $p_limit rows
     * @param int $p_count - sets $p_count to the total number of rows in the search
     * @param bool $p_countOnly - if true returns only the total number of rows
     * @return array
     */
    public static function SearchByField(array $p_keywords,
                                         $p_fieldName,
                                         $p_matchAll = false,
                                         array $p_constraints = array(),
                                         array $p_order = array(),
                                         $p_start = 0,
                                         $p_limit = 0,
                                         &$p_count,
                                         $p_countOnly = false)
    {
        global $g_ado_db;

        static $searchFields = array(
                'title'=>array('table_fields'=>array('Name'),
                               'table'=>'Articles'),
                'author'=>array('table_fields'=>array('first_name', 'last_name'),
                                'table'=>'ArticleAuthors',
                                'join_fields'=>array('Number'=>'fk_article_number')));

        $fieldName = strtolower($p_fieldName);
        if (!array_key_exists($fieldName, $searchFields)) {
            return false;
        }

        $selectClauseObj = new SQLSelectClause();

        // set tables and joins between tables
        $selectClauseObj->setTable('Articles');

        $joinTable = $searchFields[$fieldName]['table'];
        if ($joinTable != 'Articles') {
            $selectClauseObj->addTableFrom($joinTable);
            foreach ($searchFields[$fieldName]['join_fields'] as
                       $leftJoinField=>$rightJoinField) {
                $selectClauseObj->addWhere("`Articles`.`$leftJoinField` = "
                                           . "`$joinTable`.`$rightJoinField`");
            }
            if ($fieldName == 'author') {
                $joinTable = 'Authors';
                $selectClauseObj->addTableFrom($joinTable);
                $selectClauseObj->addWhere("`ArticleAuthors`.`fk_author_id` = "
                                           . "`$joinTable`.`id`");
            }
        }

        foreach ($searchFields[$fieldName]['table_fields'] as $matchField) {
            $matchFields[] = "`$joinTable`.`$matchField`";
        }
        $matchCond = 'MATCH (' . implode(', ', $matchFields) . ") AGAINST ('";
        foreach ($p_keywords as $keyword) {
            $matchCond .= ($p_matchAll ? '+' : '') . $g_ado_db->escape($keyword) . ' ';
        }
        $matchCond .= "' IN BOOLEAN MODE)";
        $selectClauseObj->addWhere($matchCond);

        $joinTables = array();
        // set other constraints
        foreach ($p_constraints as $constraint) {
            $leftOperand = $constraint->getLeftOperand();
            $operandAttributes = explode('.', $leftOperand);
            if (count($operandAttributes) == 2) {
                $table = trim($operandAttributes[0]);
                if (strtolower($table) != 'articles') {
                    $joinTables[] = $table;
                }
            }
            $symbol = $constraint->getOperator()->getSymbol('sql');
            $rightOperand = "'" . $g_ado_db->escape($constraint->getRightOperand()) . "'";
            $selectClauseObj->addWhere("$leftOperand $symbol $rightOperand");
        }
        foreach ($joinTables as $table) {
            $selectClauseObj->addJoin("LEFT JOIN $table ON Articles.Number = $table.NrArticle");
        }

        // create the count clause object
        $countClauseObj = clone $selectClauseObj;

        // set the columns for the select clause
        $selectClauseObj->addColumn('Articles.Number');
        $selectClauseObj->addColumn('Articles.IdLanguage');
        $selectClauseObj->addColumn($matchCond . ' AS score');

        // set the order for the select clause
        $p_order = count($p_order) > 0 ? $p_order : Article::$s_defaultOrder;
        $order = Article::ProcessListOrder($p_order);
        $selectClauseObj->addOrderBy('score DESC');
        foreach ($order as $orderDesc) {
            $orderField = $orderDesc['field'];
            $orderDirection = $orderDesc['dir'];
            $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
        }

        // sets the LIMIT start and offset values
        $selectClauseObj->setLimit($p_start, $p_limit);

        // set the column for the count clause
        $countClauseObj->addColumn('COUNT(*)');

        $articlesList = array();
        if (!$p_countOnly) {
            $selectQuery = $selectClauseObj->buildQuery();
            $articles = $g_ado_db->GetAll($selectQuery);
            foreach ($articles as $article) {
                $articlesList[] = new Article($article['IdLanguage'], $article['Number']);
            }
        }
        $countQuery = $countClauseObj->buildQuery();
        $p_count = $g_ado_db->GetOne($countQuery);
        return $articlesList;
    }
示例#3
0
    /**
     * Returns an images list based on the given parameters.
     *
     * @param array $p_parameters
     *    An array of ComparionOperation 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.
     *
     * @return array $issueList
     *    An array of Issue 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 && 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__);
        	$imagesList = $cacheListObj->fetchFromCache();
        	if ($imagesList !== false && is_array($imagesList)) {
        		return $imagesList;
        	}
        }

        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();

        // sets the where conditions
        foreach ($p_parameters as $param) {
            $comparisonOperation = self::ProcessListParameters($param);
            if (sizeof($comparisonOperation) < 1) {
                break;
            }

            if ($comparisonOperation['symbol'] == 'match') {
            	$whereCondition = 'MATCH(' . $comparisonOperation['left'] . ") AGAINST('"
            	    . $g_ado_db->escape($comparisonOperation['right']) . "' IN BOOLEAN MODE)";
            } else {
            	$whereCondition = $comparisonOperation['left'] . ' '
            	    . $comparisonOperation['symbol'] . " '"
            	    . $g_ado_db->escape($comparisonOperation['right']) . "' ";
            }
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }

        // 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
        $selectClauseObj->setTable($tmpImage->getDbTableName());
        $countClauseObj->setTable($tmpImage->getDbTableName());
        unset($tmpImage);

        // 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 and 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
        	$imagesList = array();
        	foreach ($images as $image) {
        		$imgObj = new Image($image['Id']);
        		if ($imgObj->exists()) {
        			$imagesList[] = $imgObj;
        		}
        	}
        } else {
        	$imagesList = array();
        	$p_count = 0;
        }
        if (!$p_skipCache && CampCache::IsEnabled()) {
        	$cacheListObj->storeInCache($imagesList);
        }

        return $imagesList;
    } // fn GetList
示例#4
0
 /**
  * Returns an article images 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 $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 && 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__);
         $articleImagesList = $cacheListObj->fetchFromCache();
         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 && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($articleImagesList);
     }
     return $articleImagesList;
 }
示例#5
0
    /**
     * 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
示例#6
0
 /**
  * Returns an article authors 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 $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;
 }
 /**
  * Returns an article attachments 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 $articleAttachmentsList
  *    An array of Attachment 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__);
         $articleAttachmentsList = $cacheListObj->fetchFromCache();
         if ($articleAttachmentsList !== false && is_array($articleAttachmentsList)) {
             return $articleAttachmentsList;
         }
     }
     $hasArticleNr = false;
     $selectClauseObj = new SQLSelectClause();
     $countClauseObj = new SQLSelectClause();
     // sets the where conditions
     foreach ($p_parameters as $param) {
         $comparisonOperation = self::ProcessParameters($param);
         if (sizeof($comparisonOperation) < 1) {
             break;
         }
         if (strpos($comparisonOperation['left'], 'fk_article_number')) {
             $whereCondition = $g_ado_db->escapeOperation($comparisonOperation);
             $hasArticleNr = true;
         } elseif (strpos($comparisonOperation['left'], 'fk_language_id')) {
             $whereCondition = '(' . $comparisonOperation['left'] . ' IS NULL OR ' . $comparisonOperation['left'] . " = " . $g_ado_db->escape($comparisonOperation['right']) . ")";
         } else {
             $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_attachments');
         return;
     }
     // sets the columns to be fetched
     $tmpAttachment = new Attachment();
     $columnNames = $tmpAttachment->getColumnNames(true);
     foreach ($columnNames as $columnName) {
         $selectClauseObj->addColumn($columnName);
     }
     $countClauseObj->addColumn('COUNT(*)');
     // sets the main table for the query
     $selectClauseObj->setTable($tmpAttachment->getDbTableName());
     $countClauseObj->setTable($tmpAttachment->getDbTableName());
     unset($tmpAttachment);
     // adds the ArticleAttachments join and condition to the query
     $selectClauseObj->addTableFrom('ArticleAttachments');
     $selectClauseObj->addWhere('ArticleAttachments.fk_attachment_id = Attachments.id');
     $countClauseObj->addTableFrom('ArticleAttachments');
     $countClauseObj->addWhere('ArticleAttachments.fk_attachment_id = Attachments.id');
     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();
     $attachments = $g_ado_db->GetAll($selectQuery);
     if (is_array($attachments)) {
         $countQuery = $countClauseObj->buildQuery();
         $p_count = $g_ado_db->GetOne($countQuery);
         // builds the array of attachment objects
         $articleAttachmentsList = array();
         foreach ($attachments as $attachment) {
             $attchObj = new Attachment($attachment['id']);
             if ($attchObj->exists()) {
                 $articleAttachmentsList[] = $attchObj;
             }
         }
     } else {
         $articleAttachmentsList = array();
         $p_count = 0;
     }
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($articleAttachmentsList);
     }
     return $articleAttachmentsList;
 }
示例#8
0
        /**
     * Returns an blog topics 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 $blogTopicsList
     *    An array of Topic objects
     */
    public static function GetList(array $p_parameters, $p_order = null,
                                   $p_start = 0, $p_limit = 0, &$p_count)
    {
        global $g_ado_db;

        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();

        // processes the parameters
        foreach ($p_parameters as $parameter) {
            $comparisonOperation = self::ProcessListParameters($parameter);
            if (sizeof($comparisonOperation) < 1) {
                break;
            }

            if (strpos($comparisonOperation['left'], 'fk_entry_id') !== false) {
                $hasBlogentryId = true;
            }
            $whereCondition = $comparisonOperation['left'] . ' '
                . $comparisonOperation['symbol'] . " '"
                . $g_ado_db->escape($comparisonOperation['right']) . "' ";
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }

        // validates whether blog number was given
        if ($hasBlogentryId == false) {
            CampTemplate::singleton()->trigger_error("missed parameter Blogentry Number in statement list_blog_topics");
            return array();
        }

        // sets the main table and columns to be fetched
        $tmpBlogentryTopic = new BlogentryTopic();
        $selectClauseObj->setTable($tmpBlogentryTopic->getDbTableName());
        $selectClauseObj->addColumn('fk_topic_id');
        $countClauseObj->setTable($tmpBlogentryTopic->getDbTableName());
        $countClauseObj->addColumn('COUNT(*)');
        unset($tmpBlogTopic);

        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)) {
            return array();
        }
        $countQuery = $countClauseObj->buildQuery();
        $p_count = $g_ado_db->GetOne($countQuery);

        // builds the array of topic objects
        $blogentryTopicsList = array();
        foreach ($topics as $topic) {
            $topObj = new Topic($topic['fk_topic_id']);
            if ($topObj->exists()) {
                $blogentryTopicsList[] = $topObj;
            }
        }

        return $blogentryTopicsList;
    } // fn GetList
示例#9
0
    /**
     * Returns an article comments 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 $articleCommentsList
     *    An array of Comment 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, $PHORUM;

        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__, self::DEFAULT_TTL);
        	$articleCommentsList = $cacheListObj->fetchFromCache();
        	if ($articleCommentsList !== false && is_array($articleCommentsList)) {
        		return $articleCommentsList;
        	}
        }

        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();

        $messageTable = $PHORUM['message_table'];
        $selectClauseObj->setTable($messageTable);
        $countClauseObj->setTable($messageTable);

        $articleNumber = null;
        $languageId = null;
        // sets the where conditions
        foreach ($p_parameters as $param) {
            $comparisonOperation = self::ProcessListParameters($param);

            if (strtolower($comparisonOperation->getLeftOperand()) == 'fk_article_number') {
                $articleNumber = $comparisonOperation->getRightOperand();
            }
            if (strtolower($comparisonOperation->getLeftOperand()) == 'fk_language_id') {
                $languageId = $comparisonOperation->getRightOperand();
            }
            $parameters[] = $comparisonOperation;
        }

        if (!is_null($articleNumber) && !is_null($languageId)) {
        	// gets the thread id for the article
        	$threadId = ArticleComment::GetCommentThreadId($articleNumber, $languageId);
            $selectClauseObj->addWhere('thread = '.$threadId);
            $countClauseObj->addWhere('thread = '.$threadId);
        }

        $selectClauseObj->addWhere('message_id != thread');
        $selectClauseObj->addWhere('status = '.PHORUM_STATUS_APPROVED);
        $countClauseObj->addWhere('message_id != thread');
        $countClauseObj->addWhere('status = '.PHORUM_STATUS_APPROVED);

        if (!is_array($p_order) || count($p_order) == 0) {
            $p_order = array('default'=>'asc');
        }

        // sets the order condition if any
        if (is_array($p_order)) {
            $order = ArticleComment::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();
        $comments = $g_ado_db->GetAll($selectQuery);
        if (is_array($comments)) {
        	$countClauseObj->addColumn('COUNT(*)');
        	$countQuery = $countClauseObj->buildQuery();
        	$p_count = $g_ado_db->GetOne($countQuery);

        	// builds the array of comment objects
        	$articleCommentsList = array();
        	foreach ($comments as $comment) {
        		$pmObj = new Phorum_message($comment['message_id']);
        		if ($pmObj->exists()) {
        			$articleCommentsList[] = $pmObj;
        		}
        	}
        } else {
        	$articleCommentsList = array();
        	$p_count = 0;
        }
        if (!$p_skipCache && CampCache::IsEnabled()) {
        	$cacheListObj->storeInCache($articleCommentsList);
        }

        return $articleCommentsList;
    } // fn GetList
示例#10
0
    /**
     * Returns map locations list based on the given parameters.
     *
     * @param array $p_parameters
     *    An array of ComparionOperation 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.
     *
     * @return array of IGeoMapLocation
     */
    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;

        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();

        // set columns
        $tmpMapLoc = new self(NULL);
        $tmpLoc = new Geo_Location(NULL);
        $columnNames = array_merge($tmpMapLoc->getColumnNames(true),
            array_diff($tmpLoc->getColumnNames(true), array('Locations.id')));
        foreach ($columnNames as $columnName) {
            $selectClauseObj->addColumn($columnName);
        }
        $selectClauseObj->addColumn('X(poi_location) as latitude');
        $selectClauseObj->addColumn('Y(poi_location) as longitude');
        $countClauseObj->addColumn('COUNT(*)');

        // sets the base table
        $selectClauseObj->setTable($tmpMapLoc->getDbTableName());
        $selectClauseObj->addJoin(sprintf('INNER JOIN `%s` ON fk_location_id = %s.id',
            $tmpLoc->getDbTableName(),
            $tmpLoc->getDbTableName()));
        $countClauseObj->setTable($tmpMapLoc->getDbTableName());
        unset($tmpMapLoc);
        unset($tmpLoc);

        // process params
        foreach ($p_parameters as $param) {
            switch ($param->getLeftOperand()) {
                case 'article':
                    $searchQuery = sprintf('fk_map_id IN (SELECT id FROM %s WHERE fk_article_number = %d)',
                        Geo_Map::TABLE,
                        $param->getRightOperand());
                    $selectClauseObj->addWhere($searchQuery);
                    $countClauseObj->addWhere($searchQuery);
                    break;
            }
        }

        // set order by rank and id
        $selectClauseObj->addOrderBy(self::TABLE . '.rank');
        $selectClauseObj->addOrderBy(self::TABLE . '.id');

        // sets the limit
        $selectClauseObj->setLimit($p_start, $p_limit);

        // builds the query and executes it
        $selectQuery = $selectClauseObj->buildQuery();
        $rows = $g_ado_db->GetAll($selectQuery);

        $list = array();
        $p_count = 0;
        if (is_array($rows)) {
        	$countQuery = $countClauseObj->buildQuery();
        	$p_count = $g_ado_db->GetOne($countQuery);

        	// builds the array of image objects
        	foreach ($rows as $row) {
                $list[] = new self((array) $row);
        	}
        }

        return $list;
    }
示例#11
0
 /**
  * Returns map locations list based on the given parameters.
  *
  * @param array $p_parameters
  *    An array of ComparionOperation objects
  * @param array $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.
  *
  * @return array of IGeoMapLocation
  */
 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;
     $list_spec = array('params' => $p_parameters, 'order' => $p_order, 'start' => $p_start, 'limit' => $p_limit, 'skip_cache' => $p_skipCache);
     $list_spec_str = serialize($list_spec);
     if (!$p_skipCache && !empty(self::$s_found_maplocations_list) && isset(self::$s_found_maplocations_list[$list_spec_str])) {
         $list_res_data = self::$s_found_maplocations_list[$list_spec_str];
         $p_count = $list_res_data['count'];
         $list = $list_res_data['list'];
         return $list;
     }
     $selectClauseObj = new SQLSelectClause();
     $countClauseObj = new SQLSelectClause();
     // set columns
     $tmpMapLoc = new self(NULL);
     $tmpLoc = new Geo_Location(NULL);
     $columnNames = array_merge($tmpMapLoc->getColumnNames(true), array_diff($tmpLoc->getColumnNames(true), array('Locations.id')));
     foreach ($columnNames as $columnName) {
         $selectClauseObj->addColumn($columnName);
     }
     $selectClauseObj->addColumn('X(poi_location) as latitude');
     $selectClauseObj->addColumn('Y(poi_location) as longitude');
     $countClauseObj->addColumn('COUNT(*)');
     // sets the base table
     $selectClauseObj->setTable($tmpMapLoc->getDbTableName());
     $selectClauseObj->addJoin(sprintf('INNER JOIN `%s` ON fk_location_id = %s.id', $tmpLoc->getDbTableName(), $tmpLoc->getDbTableName()));
     $countClauseObj->setTable($tmpMapLoc->getDbTableName());
     unset($tmpMapLoc);
     unset($tmpLoc);
     // process params
     foreach ($p_parameters as $param) {
         switch ($param->getLeftOperand()) {
             case 'article':
                 $searchQuery = sprintf('fk_map_id IN (SELECT id FROM %s WHERE fk_article_number = %d)', Geo_Map::TABLE, $param->getRightOperand());
                 $selectClauseObj->addWhere($searchQuery);
                 $countClauseObj->addWhere($searchQuery);
                 break;
         }
     }
     // set order by rank and id
     $selectClauseObj->addOrderBy(self::TABLE . '.rank');
     $selectClauseObj->addOrderBy(self::TABLE . '.id');
     // sets the limit
     $selectClauseObj->setLimit($p_start, $p_limit);
     // builds the query and executes it
     $selectQuery = $selectClauseObj->buildQuery();
     $rows = $g_ado_db->GetAll($selectQuery);
     $list = array();
     $p_count = 0;
     if (is_array($rows)) {
         $countQuery = $countClauseObj->buildQuery();
         $p_count = $g_ado_db->GetOne($countQuery);
         foreach ($rows as $row) {
             $map_loc = new self((array) $row, true);
             $row['id'] = $row['fk_location_id'];
             $map_loc->location = new Geo_Location($row, true);
             $list[] = $map_loc;
         }
     }
     if (empty(self::$s_found_maplocations_list)) {
         self::$s_found_maplocations_list = array();
     }
     self::$s_found_maplocations_list[$list_spec_str] = array('count' => $p_count, 'list' => $list);
     return $list;
 }