ArticleTypeField::FetchFields PHP Method

FetchFields() public static method

Returns an array of fields from all article types that match the given conditions.
public static 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 ) : array
$p_name if specified returns fields with the given name
$p_articleType if specified returns fields of the given article type
$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;
        $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
        if (!$p_skipCache) {
            $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';
            $paramsArray['method'] = __METHOD__;
            $cacheKey = $cacheService->getCacheKey($paramsArray, 'article_type');
            if ($cacheService->contains($cacheKey)) {
                $articleTypeFieldsList = $cacheService->fetch($cacheKey);
                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) {
            $cacheService->save($cacheKey, $fields);
        }
        return $fields;
    }

Usage Example

Ejemplo n.º 1
0
    private static function ProcessCustomField(array $p_comparisonOperation, $p_languageId = null)
    {
        global $g_ado_db;

        $fieldName = $p_comparisonOperation['left'];
        $fieldParts = preg_split('/\./', $fieldName);
        if (count($fieldParts) > 1) {
            $fieldName = $fieldParts[1];
            $articleType = $fieldParts[0];
            $field = new ArticleTypeField($articleType, $fieldName);
            if (!$field->exists()) {
                return null;
            }
            $fields = array($field);
        } else {
            $articleType = null;
            $fields = ArticleTypeField::FetchFields($fieldName, $articleType,
            null, false, false, false, true, true);
            if (count($fields) == 0) {
                return null;
            }
        }
        $queries = array();
        foreach ($fields as $fieldObj) {
            $query .= '        SELECT NrArticle FROM `X' . $fieldObj->getArticleType()
                   . '` WHERE ' . $fieldObj->getName() . ' '
                   . $p_comparisonOperation['symbol']
                   . " '" . $g_ado_db->escape($p_comparisonOperation['right']) . "'";
            if (!is_null($p_languageId)) {
                $query .= " AND IdLanguage = '" . $g_ado_db->escape($p_languageId) . "'";
            }
            $query .= "\n";
            $queries[] = $query;
        }
        if (count($queries) == 0) {
            return null;
        }
        return implode("        union\n", $queries);
    }
All Usage Examples Of ArticleTypeField::FetchFields