/**
* Returns an array of fields from all article types that match
* the given conditions.
*
* @param $p_name
* if specified returns fields with the given name
* @param $p_articleType
* if specified returns fields of the given article type
* @param $p_dataType
* if specified returns the fields having the given data type
*
* @return array
*/
public static function FetchFields($p_name = null, $p_articleType = null, $p_dataType = null, $p_negateName = false, $p_negateArticleType = false, $p_negateDataType = false, $p_selectHidden = true, $p_skipCache = false)
{
global $g_ado_db;
if (!$p_skipCache && CampCache::IsEnabled()) {
$paramsArray['name'] = is_null($p_name) ? 'null' : $p_name;
$paramsArray['article_type'] = is_null($p_articleType) ? 'null' : $p_articleType;
$paramsArray['data_type'] = is_null($p_dataType) ? 'null' : $p_dataType;
$paramsArray['negate_name'] = $p_negateName == false ? 'false' : 'true';
$paramsArray['negate_article_type'] = $p_negateArticleType == false ? 'false' : 'true';
$paramsArray['negate_data_type'] = $p_negateDataType == false ? 'false' : 'true';
$paramsArray['select_hidden'] = $p_selectHidden == false ? 'false' : 'true';
$cacheListObj = new CampCacheList($paramsArray, __METHOD__);
$articleTypeFieldsList = $cacheListObj->fetchFromCache();
if ($articleTypeFieldsList !== false && is_array($articleTypeFieldsList)) {
return $articleTypeFieldsList;
}
}
$whereClauses = array();
if (isset($p_name)) {
$operator = $p_negateName ? '<>' : '=';
$whereClauses[] = "field_name {$operator} " . $g_ado_db->escape($p_name);
}
if (isset($p_articleType)) {
$operator = $p_negateArticleType ? '<>' : '=';
$whereClauses[] = "type_name {$operator} " . $g_ado_db->escape($p_articleType);
}
if (isset($p_dataType)) {
$operator = $p_negateDataType ? '<>' : '=';
$whereClauses[] = "field_type {$operator} " . $g_ado_db->escape($p_dataType);
}
if (!$p_selectHidden) {
$whereClauses[] = 'is_hidden = false';
}
$where = count($whereClauses) > 0 ? ' WHERE ' . implode(' and ', $whereClauses) : null;
$query = "SELECT * FROM `ArticleTypeMetadata` {$where} ORDER BY type_name ASC, field_weight ASC";
$rows = $g_ado_db->GetAll($query);
$fields = array();
foreach ($rows as $row) {
$field = new ArticleTypeField($row['type_name'], $row['field_name']);
if ($field->getPrintName() == '') {
$field->delete();
continue;
}
$fields[] = $field;
}
if (!$p_skipCache && CampCache::IsEnabled()) {
$cacheListObj->storeInCache($fields);
}
return $fields;
}