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;
}