Ejemplo n.º 1
0
 function buildSortSQL($sortArray)
 {
     $sortCount = 0;
     $sortList = false;
     if (isset($sortArray) and is_array($sortArray) and count($sortArray) > 0) {
         $sortList = $sortArray;
         if (count($sortList) > 1 and !is_array($sortList[0])) {
             $sortList = array($sortList);
         }
     }
     $attributeJoinCount = 0;
     $attributeFromSQL = "";
     $attributeWereSQL = "";
     $selectSQL = '';
     if ($sortList !== false) {
         $sortingFields = '';
         foreach ($sortList as $sortBy) {
             if (is_array($sortBy) and count($sortBy) > 0) {
                 if ($sortCount > 0) {
                     $sortingFields .= ', ';
                 }
                 $sortField = $sortBy[0];
                 switch ($sortField) {
                     case 'path':
                         $sortingFields .= 'path_string';
                         break;
                     case 'published':
                         $sortingFields .= 'ezcontentobject.published';
                         break;
                     case 'modified':
                         $sortingFields .= 'ezcontentobject.modified';
                         break;
                     case 'section':
                         $sortingFields .= 'ezcontentobject.section_id';
                         break;
                     case 'depth':
                         $sortingFields .= 'depth';
                         break;
                     case 'class_identifier':
                         $sortingFields .= 'ezcontentclass.identifier';
                         $selectSQL .= ', ezcontentclass.identifier';
                         break;
                     case 'class_name':
                         $classNameFilter = eZContentClassName::sqlFilter();
                         $selectSQL .= ", " . $classNameFilter['nameField'] . " AS class_name";
                         $sortingFields .= "class_name";
                         $attributeFromSQL .= " INNER JOIN {$classNameFilter['from']} ON ({$classNameFilter['where']})";
                         break;
                     case 'priority':
                         $sortingFields .= 'ezcontentobject_tree.priority';
                         break;
                     case 'name':
                         $sortingFields .= 'ezcontentobject_name.name';
                         break;
                     case 'attribute':
                         $sortClassID = $sortBy[2];
                         // Look up datatype for sorting
                         if (!is_numeric($sortClassID)) {
                             $sortClassID = eZContentObjectTreeNode::classAttributeIDByIdentifier($sortClassID);
                         }
                         $sortDataType = $sortClassID === false ? false : eZContentObjectTreeNode::sortKeyByClassAttributeID($sortClassID);
                         $sortKey = false;
                         if ($sortDataType == 'string') {
                             $sortKey = 'sort_key_string';
                         } else {
                             $sortKey = 'sort_key_int';
                         }
                         $sortingFields .= "a{$attributeJoinCount}.{$sortKey}";
                         $attributeFromSQL .= " INNER JOIN ezcontentobject_attribute as a{$attributeJoinCount} ON (a{$attributeJoinCount}.contentobject_id = ezcontentobject.id AND a{$attributeJoinCount}.version = ezcontentobject_name.content_version)";
                         $attributeWereSQL .= " AND a{$attributeJoinCount}.contentclassattribute_id = {$sortClassID}";
                         $selectSQL .= ", a{$attributeJoinCount}.{$sortKey}";
                         $attributeJoinCount++;
                         break;
                     default:
                         eZDebug::writeWarning('Unknown sort field: ' . $sortField, __METHOD__);
                         continue;
                 }
                 $sortOrder = true;
                 // true is ascending
                 if (isset($sortBy[1])) {
                     $sortOrder = $sortBy[1];
                 }
                 $sortingFields .= $sortOrder ? " ASC" : " DESC";
                 ++$sortCount;
             }
         }
     }
     // Should we sort?
     if ($sortCount == 0) {
         $sortingFields = " ezcontentobject.published ASC";
     }
     return array('sortingFields' => $sortingFields, 'selectSQL' => $selectSQL, 'fromSQL' => $attributeFromSQL, 'whereSQL' => $attributeWereSQL);
 }
$script = eZScript::instance($scriptSettings);
$script->startup();
$config = '[preview]';
$argumentConfig = '[ATTRIBUTE_ID]';
$optionHelp = array('preview' => 'show a preview, do not really make changes');
$arguments = false;
$useStandardOptions = true;
$options = $script->getOptions($config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions);
$script->initialize();
if (count($options['arguments']) != 1) {
    $script->shutdown(1, 'wrong argument count');
}
$preview = $options['preview'] !== null;
$attributeID = $options['arguments'][0];
if (!is_numeric($attributeID)) {
    $attributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier($attributeID);
    if ($attributeID === false) {
        $script->shutdown(2, 'unknown attribute identifier');
    }
}
$classAttribute = eZContentClassAttribute::fetch($attributeID);
if (!is_object($classAttribute)) {
    $script->shutdown(3, 'could not find a class attribute with the specified ID');
}
$enum = $classAttribute->attribute('content');
// both datatypes use data_int1 for the multiple flag, so the following code is not necessary
/*
$isMultiple = $enum->attribute( 'enum_ismultiple' );
$classAttribute->setAttribute( 'data_int1', $isMultiple );
*/
//var_dump( $enum );
 /**
  * Returns an array to filter a query by the given attributes in $attributeFilter
  *
  * @param array|bool $attributeFilter
  * @param array $sortingInfo
  * @param array|bool $language
  * @return array|bool
  */
 static function createAttributeFilterSQLStrings(&$attributeFilter, &$sortingInfo = array('sortCount' => 0, 'attributeJoinCount' => 0), $language = false)
 {
     // Check for attribute filtering
     $filterSQL = array('from' => '', 'where' => '');
     if ($language !== false && !is_array($language)) {
         $language = array($language);
     }
     $totalAttributesFiltersCount = 0;
     $invalidAttributesFiltersCount = 0;
     if (isset($attributeFilter) && $attributeFilter !== false) {
         if (!is_array($attributeFilter)) {
             eZDebug::writeError("\$attributeFilter needs to be an array", __METHOD__);
             return $filterSQL;
         }
         $filterArray = $attributeFilter;
         // Check if first value of array is a string.
         // To check for and/or filtering
         $filterJoinType = 'AND';
         if (is_string($filterArray[0])) {
             if (strtolower($filterArray[0]) == 'or') {
                 $filterJoinType = 'OR';
             } else {
                 if (strtolower($filterArray[0]) == 'and') {
                     $filterJoinType = 'AND';
                 }
             }
             unset($filterArray[0]);
         }
         $attibuteFilterJoinSQL = "";
         $filterCount = $sortingInfo['sortCount'];
         $justFilterCount = 0;
         $db = eZDB::instance();
         if (is_array($filterArray)) {
             // Handle attribute filters and generate SQL
             $totalAttributesFiltersCount = count($filterArray);
             foreach ($filterArray as $filter) {
                 $isFilterValid = true;
                 // by default assumes that filter is valid
                 $filterAttributeID = $filter[0];
                 $filterType = $filter[1];
                 $filterValue = is_array($filter[2]) ? '' : $db->escapeString($filter[2]);
                 $useAttributeFilter = false;
                 switch ($filterAttributeID) {
                     case 'path':
                         $filterField = 'path_string';
                         break;
                     case 'published':
                         $filterField = 'ezcontentobject.published';
                         break;
                     case 'modified':
                         $filterField = 'ezcontentobject.modified';
                         break;
                     case 'modified_subnode':
                         $filterField = 'modified_subnode';
                         break;
                     case 'node_id':
                         $filterField = 'ezcontentobject_tree.node_id';
                         break;
                     case 'contentobject_id':
                         $filterField = 'ezcontentobject_tree.contentobject_id';
                         break;
                     case 'section':
                         $filterField = 'ezcontentobject.section_id';
                         break;
                     case 'state':
                         // state only supports =, !=, in, and not_in
                         // other operators do not make any sense in this context
                         $hasFilterOperator = true;
                         switch ($filterType) {
                             case '=':
                             case '!=':
                                 $subQueryCondition = 'contentobject_state_id = ' . (int) $filter[2];
                                 $filterOperator = $filterType == '=' ? 'IN' : 'NOT IN';
                                 break;
                             case 'in':
                             case 'not_in':
                                 if (is_array($filter[2])) {
                                     $subQueryCondition = $db->generateSQLINStatement($filter[2], 'contentobject_state_id', false, false, 'int');
                                     $filterOperator = $filterType == 'in' ? 'IN' : 'NOT IN';
                                 } else {
                                     $hasFilterOperator = false;
                                 }
                                 break;
                             default:
                                 $hasFilterOperator = false;
                                 eZDebug::writeError("Unknown attribute filter type for state: {$filterType}", __METHOD__);
                                 break;
                         }
                         if ($hasFilterOperator) {
                             if ($filterCount - $sortingInfo['sortCount'] > 0) {
                                 $attibuteFilterJoinSQL .= " {$filterJoinType} ";
                             }
                             $attibuteFilterJoinSQL .= "ezcontentobject.id {$filterOperator} (SELECT contentobject_id FROM ezcobj_state_link WHERE {$subQueryCondition})";
                             $filterCount++;
                             $justFilterCount++;
                         }
                         continue 2;
                         break;
                     case 'depth':
                         $filterField = 'depth';
                         break;
                     case 'class_identifier':
                         $filterField = 'ezcontentclass.identifier';
                         break;
                     case 'class_name':
                         $classNameFilter = eZContentClassName::sqlFilter();
                         $filterField = $classNameFilter['nameField'];
                         $filterSQL['from'] .= " INNER JOIN {$classNameFilter['from']} ON ({$classNameFilter['where']})";
                         break;
                     case 'priority':
                         $filterField = 'ezcontentobject_tree.priority';
                         break;
                     case 'name':
                         $filterField = 'ezcontentobject_name.name';
                         break;
                     case 'owner':
                         $filterField = 'ezcontentobject.owner_id';
                         break;
                     case 'visibility':
                         $filterValue = $filterValue == '1' ? 0 : 1;
                         $filterField = 'ezcontentobject_tree.is_invisible';
                         break;
                     default:
                         $useAttributeFilter = true;
                         break;
                 }
                 if ($useAttributeFilter) {
                     if (!is_numeric($filterAttributeID)) {
                         $filterAttributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier($filterAttributeID);
                     }
                     if ($filterAttributeID === false) {
                         $isFilterValid = false;
                         if ($filterJoinType === 'AND') {
                             // go out
                             $invalidAttributesFiltersCount = $totalAttributesFiltersCount;
                             break;
                         }
                         ++$invalidAttributesFiltersCount;
                     } else {
                         // Check datatype for filtering
                         $filterDataType = eZContentObjectTreeNode::sortKeyByClassAttributeID($filterAttributeID);
                         if ($filterDataType === false) {
                             $isFilterValid = false;
                             if ($filterJoinType === 'AND') {
                                 // go out
                                 $invalidAttributesFiltersCount = $totalAttributesFiltersCount;
                                 break;
                             }
                             // check next filter
                             ++$invalidAttributesFiltersCount;
                         } else {
                             $sortKey = false;
                             if ($filterDataType == 'string') {
                                 $sortKey = 'sort_key_string';
                             } else {
                                 $sortKey = 'sort_key_int';
                             }
                             $filterField = "a{$filterCount}.{$sortKey}";
                             // Use the same joins as we do when sorting,
                             // if more attributes are filtered by we will append them
                             if ($filterCount >= $sortingInfo['attributeJoinCount']) {
                                 $filterSQL['from'] .= " INNER JOIN ezcontentobject_attribute a{$filterCount} ON (a{$filterCount}.contentobject_id = ezcontentobject.id) ";
                             }
                             // Ref http://issues.ez.no/19190
                             // If language param is set, we must take it into account.
                             if ($language) {
                                 eZContentLanguage::setPrioritizedLanguages($language);
                             }
                             $filterSQL['where'] .= "\n                                  a{$filterCount}.contentobject_id = ezcontentobject.id AND\n                                  a{$filterCount}.contentclassattribute_id = {$filterAttributeID} AND\n                                  a{$filterCount}.version = ezcontentobject_name.content_version AND ";
                             $filterSQL['where'] .= eZContentLanguage::sqlFilter("a{$filterCount}", 'ezcontentobject') . ' AND ';
                             if ($language) {
                                 eZContentLanguage::clearPrioritizedLanguages();
                             }
                         }
                     }
                 }
                 if ($isFilterValid) {
                     $hasFilterOperator = true;
                     // Controls quotes around filter value, some filters do this manually
                     $noQuotes = false;
                     // Controls if $filterValue or $filter[2] is used, $filterValue is already escaped
                     $unEscape = false;
                     switch ($filterType) {
                         case '=':
                             $filterOperator = '=';
                             break;
                         case '!=':
                             $filterOperator = '<>';
                             break;
                         case '>':
                             $filterOperator = '>';
                             break;
                         case '<':
                             $filterOperator = '<';
                             break;
                         case '<=':
                             $filterOperator = '<=';
                             break;
                         case '>=':
                             $filterOperator = '>=';
                             break;
                         case 'like':
                         case 'not_like':
                             $filterOperator = $filterType == 'like' ? 'LIKE' : 'NOT LIKE';
                             // We escape the string ourselves, this MUST be done before wildcard replace
                             $filter[2] = $db->escapeString($filter[2]);
                             $unEscape = true;
                             // Since * is used as wildcard we need to transform the string to
                             // use % as wildcard. The following rules apply:
                             // - % -> \%
                             // - * -> %
                             // - \* -> *
                             // - \\ -> \
                             $filter[2] = preg_replace(array('#%#m', '#(?<!\\\\)\\*#m', '#(?<!\\\\)\\\\\\*#m', '#\\\\\\\\#m'), array('\\%', '%', '*', '\\\\'), $filter[2]);
                             break;
                         case 'in':
                         case 'not_in':
                             $filterOperator = $filterType == 'in' ? 'IN' : 'NOT IN';
                             // Turn off quotes for value, we do this ourselves
                             $noQuotes = true;
                             if (is_array($filter[2])) {
                                 reset($filter[2]);
                                 while (list($key, $value) = each($filter[2])) {
                                     // Non-numerics must be escaped to avoid SQL injection
                                     $filter[2][$key] = is_numeric($value) ? $value : "'" . $db->escapeString($value) . "'";
                                 }
                                 $filterValue = '(' . implode(",", $filter[2]) . ')';
                             } else {
                                 $hasFilterOperator = false;
                             }
                             break;
                         case 'between':
                         case 'not_between':
                             $filterOperator = $filterType == 'between' ? 'BETWEEN' : 'NOT BETWEEN';
                             // Turn off quotes for value, we do this ourselves
                             $noQuotes = true;
                             if (is_array($filter[2])) {
                                 // Check for non-numerics to avoid SQL injection
                                 if (!is_numeric($filter[2][0])) {
                                     $filter[2][0] = "'" . $db->escapeString($filter[2][0]) . "'";
                                 }
                                 if (!is_numeric($filter[2][1])) {
                                     $filter[2][1] = "'" . $db->escapeString($filter[2][1]) . "'";
                                 }
                                 $filterValue = $filter[2][0] . ' AND ' . $filter[2][1];
                             }
                             break;
                         default:
                             $hasFilterOperator = false;
                             eZDebug::writeError("Unknown attribute filter type: {$filterType}", __METHOD__);
                             break;
                     }
                     if ($hasFilterOperator) {
                         if ($filterCount - $sortingInfo['sortCount'] > 0) {
                             $attibuteFilterJoinSQL .= " {$filterJoinType} ";
                         }
                         // If $unEscape is true we get the filter value from the 2nd element instead
                         // which must have been escaped by filter type
                         $filterValue = $unEscape ? $filter[2] : $filterValue;
                         $attibuteFilterJoinSQL .= "{$filterField} {$filterOperator} ";
                         $attibuteFilterJoinSQL .= $noQuotes ? "{$filterValue} " : "'{$filterValue}' ";
                         $filterCount++;
                         $justFilterCount++;
                     }
                 }
             }
             // end of 'foreach ( $filterArray as $filter )'
             if ($totalAttributesFiltersCount == $invalidAttributesFiltersCount) {
                 eZDebug::writeNotice("Attribute filter returned false");
                 $filterSQL = false;
             } else {
                 if ($justFilterCount > 0) {
                     $filterSQL['where'] .= "                            ( " . $attibuteFilterJoinSQL . " ) AND ";
                 }
             }
         }
         // end of 'if ( is_array( $filterArray ) )'
     }
     return $filterSQL;
 }
 public static function fetchReverseRelatedObjectsCount($objectID, $attributeID, $allRelations, $ignoreVisibility)
 {
     if (!is_numeric($objectID)) {
         eZDebug::writeError("\$objectID is missing or invalid", __METHOD__);
         return false;
     }
     $object = eZContentObject::fetch($objectID);
     if (!$object instanceof eZContentObject) {
         eZDebug::writeError("An error occured fetching object #{$objectID}", __METHOD__);
         return false;
     }
     $params = array();
     if (isset($ignoreVisibility)) {
         $params['IgnoreVisibility'] = $ignoreVisibility;
     }
     if (!$attributeID) {
         $attributeID = 0;
     }
     if (isset($allRelations)) {
         if ($attributeID && !$allRelations) {
             $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask(array('attribute'));
         } elseif ($allRelations === true) {
             $attributeID = false;
         } else {
             $params['AllRelations'] = eZContentFunctionCollection::contentobjectRelationTypeMask($allRelations);
         }
     }
     if ($attributeID && !is_numeric($attributeID) && !is_bool($attributeID)) {
         $attributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier($attributeID);
         if (!$attributeID) {
             eZDebug::writeError("Can't get class attribute ID by identifier");
             return false;
         }
     }
     return array('result' => $object->reverseRelatedObjectCount(false, $attributeID, $params));
 }
Ejemplo n.º 5
0
    /**
     * Get solr field name, from base name. The base name may either be a
     * meta-data name, or an eZ Publish content class attribute, specified by
     * <class identifier>/<attribute identifier>[/<option>]
     *
     * @param string $baseName Base field name.
     * @param boolean $includingClassID conditions the structure of the answer. See return value explanation.
     * @param $context is introduced in ez find 2.2 to allow for more optimal sorting, faceting, filtering
     *
     * @return mixed Internal base name. Returns null if no valid base name was provided.
     *               If $includingClassID is true, an associative array will be returned, as shown below :
     *               <code>
     *               array( 'fieldName'      => 'attr_title_t',
     *                      'contentClassId' => 16 );
     *               </code>
     */
    static function getFieldName( $baseName, $includingClassID = false, $context = 'search' )
    {
        // If the base name is a meta field, get the correct field name.
        if ( eZSolr::hasMetaAttributeType( $baseName, $context ) )
        {
            return eZSolr::getMetaFieldName( $baseName, $context );
        }
        else
        {
            // Get class and attribute identifiers + optional option.
            $subattribute = null;
            $fieldDef = explode( '/', $baseName );
            // Check if content class attribute ID is provided.
            if ( is_numeric( $fieldDef[0] ) )
            {
                if ( count( $fieldDef ) == 1 )
                {
                    $contentClassAttributeID = $fieldDef[0];
                }
                else if ( count( $fieldDef ) == 2 )
                {
                    list( $contentClassAttributeID, $subattribute ) = $fieldDef;
                }
            }
            else
            {
                switch( count( $fieldDef ) )
                {
                    case 1:
                    {
                        // Return fieldname as is.
                        return $baseName;
                    } break;

                    case 2:
                    {
                        // Field def contains class indentifier and class attribute identifier.
                        list( $classIdentifier, $attributeIdentifier ) = $fieldDef;
                    } break;

                    case 3:
                    {
                        // Field def contains class indentifier, class attribute identifier and optional specification.
                        list( $classIdentifier, $attributeIdentifier, $subattribute ) = $fieldDef;
                    } break;
                }
                $contentClassAttributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier( $classIdentifier . '/' . $attributeIdentifier );
            }
            if ( !$contentClassAttributeID )
            {
                eZDebug::writeNotice( 'Could not get content class from base name: ' . $baseName, __METHOD__ );
                return null;
            }
            $contentClassAttribute = eZContentClassAttribute::fetch( $contentClassAttributeID );
            $fieldName = ezfSolrDocumentFieldBase::getFieldName( $contentClassAttribute, $subattribute, $context );

            if ( $includingClassID )
            {
                return array( 'fieldName'      => $fieldName,
                              'contentClassId' => $contentClassAttribute->attribute( 'contentclass_id' ) );
            }
            else
                return $fieldName;
        }
    }
    public static function geoLocation($params)
    {
        $return = array();
        $latAttributeID = is_numeric($params['attributes']['lat']) === false ? eZContentObjectTreeNode::classAttributeIDByIdentifier($params['attributes']['lat']) : $params['attributes']['lat'];
        $lngAttributeID = is_numeric($params['attributes']['lon']) === false ? eZContentObjectTreeNode::classAttributeIDByIdentifier($params['attributes']['lon']) : $params['attributes']['lon'];
        if ($latAttributeID !== false && $lngAttributeID !== false) {
            $params['lat'] = (double) $params['lat'];
            $params['lon'] = (double) $params['lon'];
            $latTable = 'lat' . $params['index'];
            $lngTable = 'lng' . $params['index'];
            $tables = ', ezcontentobject_attribute as ' . $latTable . ', ezcontentobject_attribute as ' . $lngTable;
            $locationField = 'data_float';
            if (isset($params['location_db_field'])) {
                $locationField = $params['location_db_field'];
            }
            $distanceField = '( ( ACOS( SIN( ' . $latTable . '.' . $locationField . ' * PI() / 180 ) * SIN( ' . $params['lat'] . ' * PI() / 180 ) + COS( ' . $latTable . '.' . $locationField . ' * PI() / 180 ) * COS( ' . $params['lat'] . ' * PI() / 180 ) * COS( ( ' . $lngTable . '.' . $locationField . ' - ' . $params['lon'] . ' ) * PI() / 180 ) ) * 180 / PI() ) * 60 * 1.1515 )';
            if (isset($params['distance_measure']) === false || $params['distance_measure'] == 'km') {
                $distanceField .= ' * 1.609344';
            }
            $joins = $latTable . '.contentobject_id = ezcontentobject.id
				AND ' . $latTable . '.version = ezcontentobject.current_version
				AND ' . $latTable . '.contentclassattribute_id = ' . $latAttributeID . '
				AND ' . $lngTable . '.contentobject_id = ezcontentobject.id
				AND ' . $lngTable . '.version = ezcontentobject.current_version
				AND ' . $lngTable . '.contentclassattribute_id = ' . $lngAttributeID . '
				AND ';
            if (isset($params['distance'])) {
                $joins .= $distanceField . ' < ' . $params['distance'] . ' AND ';
            }
            $columns = false;
            if (isset($params['sort_field'])) {
                $columns = ', ' . $distanceField . ' AS ' . $params['sort_field'];
            }
            $return = array('tables' => $tables, 'joins' => $joins, 'columns' => $columns);
        }
        return $return;
    }
Ejemplo n.º 7
0
                $filepath = $bc->getFullPath();
                $filesize = null;
                $tracking = false;
            break;
            case 'file':
            case 'pdf':
                // we need to check if the pdf is valid
                if( isset($dataMap['expiration_duration'])
                    && $dataMap['expiration_duration']->hasContent()
                    && $dataMap['expiration_duration']->content() > 0 )
                {
                    // we've got an expirable PDF,
                    // we need to get the parent article(s)
                    $expirationDuration = $dataMap['expiration_duration']->content();
                    $relatedArticles    = array();
                    $relatedObjects     = $node->object()->reverseRelatedObjectList(false, eZContentObjectTreeNode::classAttributeIDByIdentifier('download_ressource') );

                    if(!isset($articleId) && count($relatedObjects) > 1)
                    {
                        /* @var $Module eZModule */
                        header('HTTP/1.1 403 Forbidden');
                        echo "<h1>Forbidden access</h1>\n";
                        eZExecution::cleanExit();
                    }

                    if(isset($articleId))
                    {
                        $article = eZContentObjectTreenode::fetch($articleId);
                        if($article)
                        {
                            $dataMap = $article->dataMap();
Ejemplo n.º 8
0
    /**
     * @param $node eZContentObjectTreeNode
     * @return bool
     */
    public static function getFileApplicationCanRead(&$node)
    {
        $relatedObjects = $node->object()->reverseRelatedObjectList(false, eZContentObjectTreeNode::classAttributeIDByIdentifier('download_ressource') );
        try
        {
            if(count($relatedObjects) == 0)
                throw new Exception('No article related to this object');

            /** @var eZContentObject $articleObject */
            /** @var eZContentObjectTreeNode $articleNode */
            $articleObject = $relatedObjects[0];
            $articleNode = $articleObject->mainNode();

            $applicationIdentifier = NodeTool::getApplicationFromNode($articleNode);

            /** @var ApplicationDefault $application */
            $application = ApplicationFactory::fetchByUri($applicationIdentifier);

            if(!$application->canRead())
            {
                throw new Exception('Can\'t read');
            }

            return true;
        }
        catch (Exception $e)
        {
            return false;
        }
    }
Ejemplo n.º 9
0
 function CreateSqlParts($params)
 {
     $db =& eZDB::instance();
     $tables = array();
     $joins = array();
     // foreach filtered attribute, we add a join the relation table and filter
     // on the attribute ID + object ID
     foreach ($params as $param) {
         if (!is_array($param)) {
             continue;
         }
         if (!is_numeric($param[0])) {
             $classAttributeId = eZContentObjectTreeNode::classAttributeIDByIdentifier($param[0]);
         } else {
             $classAttributeId = $param[0];
         }
         // multiple objects ids
         if (is_array($param[1])) {
             // Patch from Grégory BECUE
             // http://ez.no/developer/forum/developer/fetch_and_filter_on_object_relations/re_fetch_and_filter_on_object_relations__2
             // Handle 'or' parameters
             if ($param[2] == 'or') {
                 $cpt = 0;
                 $chaineCritere = "(";
                 foreach ($param[1] as $objectId) {
                     if (is_numeric($objectId)) {
                         if ($cpt == 0) {
                             $tableName = 'eor_link_' . $objectId;
                             $tables[] = 'ezcontentobject_link ' . $tableName;
                             $joins[] = $tableName . '.from_contentobject_id = ezcontentobject.id';
                             $joins[] = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
                             $joins[] = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
                             $chaineCritere .= $tableName . '.to_contentobject_id = ' . $objectId;
                         } else {
                             $chaineCritere .= ' or ' . $tableName . '.to_contentobject_id = ' . $objectId;
                         }
                     }
                     $cpt++;
                 }
                 $joins[] = $chaineCritere . ")";
             } else {
                 foreach ($param[1] as $objectId) {
                     if (is_numeric($objectId)) {
                         $tableName = 'eor_link_' . $objectId;
                         $tables[] = 'ezcontentobject_link ' . $tableName;
                         $joins[] = $tableName . '.from_contentobject_id = ezcontentobject.id';
                         $joins[] = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
                         $joins[] = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
                         $joins[] = $tableName . '.to_contentobject_id = ' . $objectId;
                     }
                 }
             }
         } else {
             $objectId = $param[1];
             $tableName = 'eor_link_' . $objectId;
             $tables[] = 'ezcontentobject_link ' . $tableName;
             $joins[] = $tableName . '.from_contentobject_id = ezcontentobject.id';
             $joins[] = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
             $joins[] = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
             $joins[] = $tableName . '.to_contentobject_id = ' . $objectId;
         }
     }
     if (!count($tables) or !count($joins)) {
         $tables = $joins = '';
     } else {
         $tables = "\n, " . implode("\n, ", $tables);
         $joins = implode(" AND\n ", $joins) . " AND\n ";
     }
     return array('tables' => $tables, 'joins' => $joins);
 }