/** * 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