/** * @param array|bool $params * @param int $nodeID * @return array|null */ static function subTreeByNodeID($params = false, $nodeID = 0) { if (!is_numeric($nodeID) and !is_array($nodeID)) { return null; } if ($params === false) { $params = array('Depth' => false, 'Offset' => false, 'Language' => false, 'Limit' => false, 'SortBy' => false, 'AttributeFilter' => false, 'ExtendedAttributeFilter' => false, 'ClassFilterType' => false, 'ClassFilterArray' => false, 'GroupBy' => false); } $offset = isset($params['Offset']) && is_numeric($params['Offset']) ? $params['Offset'] : false; //$onlyTranslated = ( isset( $params['OnlyTranslated'] ) ) ? $params['OnlyTranslated'] : false; $language = isset($params['Language']) ? $params['Language'] : false; $limit = isset($params['Limit']) && is_numeric($params['Limit']) ? $params['Limit'] : false; $depth = isset($params['Depth']) && is_numeric($params['Depth']) ? $params['Depth'] : false; $depthOperator = isset($params['DepthOperator']) ? $params['DepthOperator'] : false; $asObject = isset($params['AsObject']) ? $params['AsObject'] : true; $loadDataMap = isset($params['LoadDataMap']) ? $params['LoadDataMap'] : false; $groupBy = isset($params['GroupBy']) ? $params['GroupBy'] : false; $mainNodeOnly = isset($params['MainNodeOnly']) ? $params['MainNodeOnly'] : false; $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false; $objectNameFilter = isset($params['ObjectNameFilter']) ? $params['ObjectNameFilter'] : false; if ($offset < 0) { $offset = abs($offset); } if (!isset($params['SortBy'])) { $params['SortBy'] = false; } if (!isset($params['ClassFilterType'])) { $params['ClassFilterType'] = false; } $allowCustomSorting = false; if (isset($params['ExtendedAttributeFilter']) && is_array($params['ExtendedAttributeFilter'])) { $allowCustomSorting = true; } $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($params['SortBy'], 'ezcontentobject_tree', $allowCustomSorting); $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($params['ClassFilterType'], $params['ClassFilterArray']); if ($classCondition === false) { eZDebug::writeNotice("Class filter returned false"); return null; } $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings($params['AttributeFilter'], $sortingInfo, $language); if ($attributeFilter === false) { return null; } $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['ExtendedAttributeFilter']); $mainNodeOnlyCond = eZContentObjectTreeNode::createMainNodeConditionSQLString($mainNodeOnly); $pathStringCond = ''; $notEqParentString = ''; // If the node(s) doesn't exist we return null. if (!eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator)) { return null; } if ($language) { if (!is_array($language)) { $language = array($language); } // This call must occur after eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings, // because the parent node may not exist in Language eZContentLanguage::setPrioritizedLanguages($language); } $groupBySelectText = ''; $groupBySQL = $extendedAttributeFilter['group_by']; if (!$groupBySQL) { eZContentObjectTreeNode::createGroupBySQLStrings($groupBySelectText, $groupBySQL, $groupBy); } else { if ($groupBy) { eZDebug::writeError("Cannot use group_by parameter together with extended attribute filter which sets group_by!", __METHOD__); } } $languageFilter = eZContentLanguage::languagesSQLFilter('ezcontentobject'); $objectNameLanguageFilter = eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); if ($language) { eZContentLanguage::clearPrioritizedLanguages(); } $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString($objectNameFilter); $limitation = isset($params['Limitation']) && is_array($params['Limitation']) ? $params['Limitation'] : false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); // Determine whether we should show invisible nodes. $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility); $query = "SELECT DISTINCT " . "ezcontentobject.contentclass_id, ezcontentobject.current_version, ezcontentobject.id, ezcontentobject.initial_language_id, ezcontentobject.language_mask, " . "ezcontentobject.modified, ezcontentobject.owner_id, ezcontentobject.published, ezcontentobject.remote_id AS object_remote_id, ezcontentobject.section_id, ezcontentobject.status, " . "ezcontentobject_tree.contentobject_is_published, ezcontentobject_tree.contentobject_version, ezcontentobject_tree.depth, " . "ezcontentobject_tree.is_hidden, ezcontentobject_tree.is_invisible, ezcontentobject_tree.main_node_id, ezcontentobject_tree.modified_subnode, ezcontentobject_tree.node_id, " . "ezcontentobject_tree.parent_node_id, ezcontentobject_tree.path_identification_string, ezcontentobject_tree.path_string, ezcontentobject_tree.priority, " . "ezcontentobject_tree.remote_id, ezcontentobject_tree.sort_field, ezcontentobject_tree.sort_order, ezcontentclass.serialized_name_list as class_serialized_name_list, " . "ezcontentclass.identifier as class_identifier, ezcontentclass.is_container as is_container {$groupBySelectText}, ezcontentobject_name.name, ezcontentobject_name.real_translation " . $sortingInfo["attributeTargetSQL"] . " " . $extendedAttributeFilter["columns"] . " " . "FROM " . "ezcontentobject_tree " . "INNER JOIN ezcontentobject ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id) " . "INNER JOIN ezcontentclass ON (ezcontentclass.version = 0 AND ezcontentclass.id = ezcontentobject.contentclass_id) " . "INNER JOIN ezcontentobject_name ON ( " . " ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id AND " . " ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version " . ") " . "{$sortingInfo['attributeFromSQL']} {$attributeFilter['from']} {$extendedAttributeFilter['tables']} {$sqlPermissionChecking['from']} " . "WHERE " . "{$pathStringCond} " . "{$extendedAttributeFilter['joins']} " . "{$sortingInfo['attributeWhereSQL']} " . "{$attributeFilter['where']} " . "{$notEqParentString} " . "{$mainNodeOnlyCond} " . "{$classCondition} " . "{$objectNameLanguageFilter} " . "{$showInvisibleNodesCond} " . "{$sqlPermissionChecking['where']} " . "{$objectNameFilterSQL} AND " . "{$languageFilter} " . $groupBySQL; if ($sortingInfo['sortingFields']) { $query .= " ORDER BY {$sortingInfo['sortingFields']}"; } $db = eZDB::instance(); $server = count($sqlPermissionChecking['temp_tables']) > 0 ? eZDBInterface::SERVER_SLAVE : false; $nodeListArray = $db->arrayQuery($query, array('offset' => $offset, 'limit' => $limit), $server); if ($asObject) { $retNodeList = eZContentObjectTreeNode::makeObjectsArray($nodeListArray); if ($loadDataMap === true) { eZContentObject::fillNodeListAttributes($retNodeList); } else { if ($loadDataMap && is_numeric($loadDataMap) && $loadDataMap >= count($retNodeList)) { eZContentObject::fillNodeListAttributes($retNodeList); } } } else { $retNodeList = $nodeListArray; } // cleanup temp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); return $retNodeList; }
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters ) { $level = 0; $done = false; $i = 0; $pathArray = array(); $tmpModulePath = $namedParameters['path']; $classFilter = $namedParameters['class_filter']; $language = $namedParameters['language']; $loadDataMap = $namedParameters['load_data_map']; // node_id is not used anymore if ( !empty( $namedParameters['node_id'] ) ) { eZDebug::writeNotice( 'Deprecated parameter "node_id" in treemenu template operator' ); } if ( $classFilter === false ) { $classFilter = array(); } else if ( count( $classFilter ) == 0 ) { $classFilter = array( 1 ); } $classFilter = ( count( $classFilter ) == 1 and !isset( $classFilter[0] ) ) ? array( 1 ) : $classFilter; $tmpModulePathCount = count( $tmpModulePath ); if ( !$tmpModulePath[ $tmpModulePathCount -1 ]['url'] and isset( $tmpModulePath[ $tmpModulePathCount -1 ]['node_id'] ) ) $tmpModulePath[ $tmpModulePathCount -1 ]['url'] = '/content/view/full/' . $tmpModulePath[ $tmpModulePathCount -1 ]['node_id']; $depthSkip = $namedParameters['depth_skip']; $indentationLevel = $namedParameters['indentation_level']; $maxLevel = $namedParameters['max_level']; $isSelectedMethod = $namedParameters['is_selected_method']; if ( $maxLevel === false ) $maxLevel = 2; while ( !$done && isset( $tmpModulePath[$i+$depthSkip] ) ) { // get node id $elements = explode( '/', $tmpModulePath[$i+$depthSkip]['url'] ); $nodeID = false; if ( isset( $elements[4] ) ) $nodeID = $elements[4]; $excludeNode = false; if ( isset( $elements[1] ) && isset( $elements[2] ) && $elements[1] == 'content' && $elements[2] == 'view' && is_numeric( $nodeID ) && $excludeNode == false && $level < $maxLevel ) { $node = eZContentObjectTreeNode::fetch( $nodeID ); if ( !isset( $node ) ) { $operatorValue = $pathArray; return; } if ( isset( $tmpModulePath[$i+$depthSkip+1] ) ) { $nextElements = explode( '/', $tmpModulePath[$i+$depthSkip+1]['url'] ); if ( isset( $nextElements[4] ) ) { $nextNodeID = $nextElements[4]; } else { $nextNodeID = false; } } else $nextNodeID = false; $menuChildren = eZContentObjectTreeNode::subTreeByNodeID( array( 'Depth' => 1, 'Offset' => 0, 'SortBy' => $node->sortArray(), 'Language' => $language, 'ClassFilterType' => 'include', 'ClassFilterArray' => $classFilter ), $nodeID ); /// Fill objects with attributes, speed boost, only use if load_data_map is true // or if less then 16 nodes and param is not set (null) if ( $loadDataMap || ( $loadDataMap === null && count( $menuChildren ) <= 15 ) ) eZContentObject::fillNodeListAttributes( $menuChildren ); $tmpPathArray = array(); foreach ( $menuChildren as $child ) { $name = $child->attribute( 'name' ); $tmpNodeID = $child->attribute( 'node_id' ); $url = "/content/view/full/$tmpNodeID/"; $urlAlias = '/' . $child->attribute( 'url_alias' ); $hasChildren = $child->attribute( 'is_container' ) && $child->attribute( 'children_count' ) > 0; $contentObject = $child->attribute( 'object' ); $indent = ($i - 1) * $indentationLevel; $isSelected = false; $nextNextElements = ( $isSelectedMethod == 'node' and isset( $tmpModulePath[$i+$depthSkip+2]['url'] ) ) ? explode( '/', $tmpModulePath[$i+$depthSkip+2]['url'] ) : null; if ( $nextNodeID === $tmpNodeID and !isset( $nextNextElements[4] ) ) { $isSelected = true; } $tmpPathArray[] = array( 'id' => $tmpNodeID, 'level' => $i, 'class_name' => $contentObject->classname(), 'is_main_node' => $child->attribute( 'is_main' ), 'has_children' => $hasChildren, 'indent' => $indent, 'url_alias' => $urlAlias, 'url' => $url, 'text' => $name, 'is_selected' => $isSelected, 'node' => $child ); } // find insert pos $j = 0; $insertPos = 0; foreach ( $pathArray as $path ) { if ( $path['id'] == $nodeID ) $insertPos = $j; $j++; } $restArray = array_splice( $pathArray, $insertPos + 1 ); $pathArray = array_merge( $pathArray, $tmpPathArray ); $pathArray = array_merge( $pathArray, $restArray ); } else { if ( $level == 0 ) { $node = eZContentObjectTreeNode::fetch( 2 ); if ( !$node instanceof eZContentObjectTreeNode ) { $operatorValue = $pathArray; return; } $menuChildren = eZContentObjectTreeNode::subTreeByNodeID( array( 'Depth' => 1, 'Offset' => 0, 'SortBy' => $node->sortArray(), 'Language' => $language, 'ClassFilterType' => 'include', 'ClassFilterArray' => $classFilter ), 2 ); /// Fill objects with attributes, speed boost, only use if load_data_map is true // or if less then 16 nodes and param is not set (null) if ( $loadDataMap || ( $loadDataMap === null && count( $menuChildren ) < 16 ) ) eZContentObject::fillNodeListAttributes( $menuChildren ); $pathArray = array(); foreach ( $menuChildren as $child ) { $name = $child->attribute( 'name' ); $tmpNodeID = $child->attribute( 'node_id' ); $url = "/content/view/full/$tmpNodeID/"; $urlAlias = '/' . $child->attribute( 'url_alias' ); $pathArray[] = array( 'id' => $tmpNodeID, 'level' => $i, 'is_main_node' => $child->attribute( 'is_main' ), 'url_alias' => $urlAlias, 'url' => $url, 'text' => $name, 'is_selected' => false, 'node' => $child ); } } $done = true; } ++$level; ++$i; } $operatorValue = $pathArray; }
/** * Returns related or reverse related objects * * @param int|bool $fromObjectVersion If omitted, the current version will be used * @param int|bool $objectID If omitted, the current object will be used * @param int|bool $attributeID makes sense only when $params['AllRelations'] not set or eZContentObject::RELATION_ATTRIBUTE * $attributeID = 0|false ( $params['AllRelations'] is eZContentObject::RELATION_ATTRIBUTE ) * - return relations made with any attributes * $attributeID > 0 * - return relations made with attribute ID ( "related object(s)" datatype ) * $attributeID = false ( $params['AllRelations'] not set ) * - return ALL relations (deprecated, use "$params['AllRelations'] = true" instead) * @param bool $groupByAttribute This parameter makes sense only when $attributeID == false or $params['AllRelations'] = true * $groupByAttribute = false * - return all relations as an array of content objects * $groupByAttribute = true * - return all relations groupped by attribute ID * @param array|bool $params Other parameters from template fetch function * $params['AllRelations'] = true * - return ALL relations, including attribute-level * $params['AllRelations'] = false * - return objec level relations only * $params['AllRelations'] = int > 0 * - bit mask of EZ_CONTENT_OBJECT_RELATION_* values * $params['SortBy'] * - Possible values: * "class_identifier", "class_name", "modified", * "name", "published", "section" * $params['IgnoreVisibility'] = true * - Include related objects with a 'hidden' state * $params['IgnoreVisibility'] = false * - Exclude related objects with a 'hidden' state * $params['RelatedClassIdentifiers'] = array * - limit returned relations to objects of the specified class identifiers * @param bool $reverseRelatedObjects true -> returns reverse related objects * false -> returns related objects * @return eZContentObject[]|array eZContentObject[], if $params['AsObject'] is set to true (default), array otherwise */ function relatedObjects( $fromObjectVersion = false, $objectID = false, $attributeID = 0, $groupByAttribute = false, $params = false, $reverseRelatedObjects = false ) { if ( $fromObjectVersion == false ) $fromObjectVersion = isset( $this->CurrentVersion ) ? $this->CurrentVersion : false; $fromObjectVersion =(int) $fromObjectVersion; if( !$objectID ) $objectID = $this->ID; $objectID =(int) $objectID; $limit = ( isset( $params['Limit'] ) && is_numeric( $params['Limit'] ) ) ? $params['Limit'] : false; $offset = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset'] : false; $asObject = ( isset( $params['AsObject'] ) ) ? $params['AsObject'] : true; $loadDataMap = ( isset( $params['LoadDataMap'] ) ) ? $params['LoadDataMap'] : false; $db = eZDB::instance(); $sortingString = ''; $sortingInfo = array( 'attributeFromSQL' => '', 'attributeWhereSQL' => '', 'attributeTargetSQL' => '' ); $relatedClassIdentifiersSQL = ''; $showInvisibleNodesCond = ''; // process params (only SortBy and IgnoreVisibility currently supported): // Supported sort_by modes: // class_identifier, class_name, modified, name, published, section if ( is_array( $params ) ) { if ( isset( $params['SortBy'] ) ) { $validSortBy = array( 'class_identifier', 'class_name', 'modified', 'name', 'published', 'section' ); $sortByParam = array(); if ( is_array( $params['SortBy'] ) ) { // only one SortBy, as a simple array if ( !is_array( $params['SortBy'][0] ) ) { if ( !in_array( $params['SortBy'][0], $validSortBy ) ) eZDebug::writeWarning( "Unsupported sort_by parameter {$params['SortBy'][0]}; check the online documentation for the list of supported sort types", __METHOD__ ); else $sortByParam[] = $params['SortBy']; } // multiple SortBy, check each of them one by one, and keep valid ones else { $invalidSortBy = array(); foreach( $params['SortBy'] as $sortByTuple ) { if ( !in_array( $sortByTuple[0], $validSortBy ) ) $invalidSortBy[] = $sortByTuple[0]; else $sortByParam[] = $sortByTuple; } if ( count( $invalidSortBy ) > 0 ) { eZDebug::writeWarning( "Unsupported sort_by parameter(s) " . implode( ', ', $invalidSortBy ) . "; check the online documentation for the list of supported sort types", __METHOD__ ); } } } if ( count( $sortByParam ) > 0 ) { $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $sortByParam ); $sortingString = ' ORDER BY ' . $sortingInfo['sortingFields']; } } if ( isset( $params['IgnoreVisibility'] ) ) { $showInvisibleNodesCond = self::createFilterByVisibilitySQLString( $params['IgnoreVisibility'] ); } // related class identifier filter $relatedClassIdentifiersSQL = ''; if ( isset( $params['RelatedClassIdentifiers'] ) && is_array( $params['RelatedClassIdentifiers'] ) ) { $relatedClassIdentifiers = array(); foreach( $params['RelatedClassIdentifiers'] as $classIdentifier ) { $relatedClassIdentifiers[] = "'" . $db->escapeString( $classIdentifier ) . "'"; } $relatedClassIdentifiersSQL = $db->generateSQLINStatement( $relatedClassIdentifiers, 'ezcontentclass.identifier', false, true, 'string' ). " AND"; unset( $classIdentifier, $relatedClassIdentifiers ); } } $relationTypeMasking = ''; $relationTypeMask = isset( $params['AllRelations'] ) ? $params['AllRelations'] : ( $attributeID === false ); if ( $attributeID && ( $relationTypeMask === false || $relationTypeMask === eZContentObject::RELATION_ATTRIBUTE ) ) { $attributeID =(int) $attributeID; $relationTypeMasking .= " contentclassattribute_id=$attributeID AND "; $relationTypeMask = eZContentObject::RELATION_ATTRIBUTE; } elseif ( is_bool( $relationTypeMask ) ) { $relationTypeMask = eZContentObject::relationTypeMask( $relationTypeMask ); } if ( $db->databaseName() == 'oracle' ) { $relationTypeMasking .= " bitand( relation_type, $relationTypeMask ) <> 0 "; } else { $relationTypeMasking .= " ( relation_type & $relationTypeMask ) <> 0 "; } // Create SQL $fromOrToContentObjectID = $reverseRelatedObjects == false ? " AND ezcontentobject.id=ezcontentobject_link.to_contentobject_id AND ezcontentobject_link.from_contentobject_id='$objectID' AND ezcontentobject_link.from_contentobject_version='$fromObjectVersion' " : " AND ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND ezcontentobject_link.to_contentobject_id=$objectID AND ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version "; $query = "SELECT "; if ( $groupByAttribute ) { $query .= "ezcontentobject_link.contentclassattribute_id, "; } $query .= " ezcontentclass.serialized_name_list AS class_serialized_name_list, ezcontentclass.identifier as contentclass_identifier, ezcontentclass.is_container as is_container, ezcontentobject.*, ezcontentobject_name.name as name, ezcontentobject_name.real_translation $sortingInfo[attributeTargetSQL] FROM ezcontentclass, ezcontentobject, ezcontentobject_link, ezcontentobject_name $sortingInfo[attributeFromSQL] WHERE ezcontentclass.id=ezcontentobject.contentclass_id AND ezcontentclass.version=0 AND ezcontentobject.status=" . eZContentObject::STATUS_PUBLISHED . " AND $sortingInfo[attributeWhereSQL] $relatedClassIdentifiersSQL $relationTypeMasking $fromOrToContentObjectID $showInvisibleNodesCond AND ezcontentobject.id = ezcontentobject_name.contentobject_id AND ezcontentobject.current_version = ezcontentobject_name.content_version AND " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) . " $sortingString"; if ( !$offset && !$limit ) { $relatedObjects = $db->arrayQuery( $query ); } else { $relatedObjects = $db->arrayQuery( $query, array( 'offset' => $offset, 'limit' => $limit ) ); } $ret = array(); $tmp = array(); foreach ( $relatedObjects as $object ) { if ( $asObject ) { $obj = new eZContentObject( $object ); $obj->ClassName = eZContentClass::nameFromSerializedString( $object['class_serialized_name_list'] ); } else { $obj = $object; } $tmp[] = $obj; if ( !$groupByAttribute ) { $ret[] = $obj; } else { $classAttrID = $object['contentclassattribute_id']; if ( !isset( $ret[$classAttrID] ) ) $ret[$classAttrID] = array(); $ret[$classAttrID][] = $obj; } } if ( $loadDataMap && $asObject ) eZContentObject::fillNodeListAttributes( $tmp ); return $ret; }
/** * Fetch top/bottom content (nodes) by rating++ * * @param array $params (see inline doc for details) * @return array Returs array of nodes (either objects or raw db output based on as_object param) */ static function fetchNodeByRating($params) { /** * Works like fetch list/tree, except: * 1. Attribute filter is not supported (because of dependency on normal sort_by param) * 2. Supported sorting: rating, rating_count, object_count, published, modified and view_count. * 3. parent_node_id only works for list fetch, if you want tree fetch use * parent_node_path (format is like $node.path_string, as in '/1/2/144/256/'). * 4. depth and depth_operator are not supported (so parent_node_path gives you unlimited depth). * 5. There are additional advance params to see rating, rating_count, object_count pr user / group * see group_by_owner, owner_parent_node_id, owner_parent_node_path and owner_id. * 6. param 'include_not_rated' when set to true will use left join to also include unrated content */ $ret = array(); $whereSql = array(); $offset = false; $limit = false; $fromSql = ''; $asObject = isset($params['as_object']) ? $params['as_object'] : true; $loadDataMap = isset($params['load_data_map']) ? $params['load_data_map'] : false; $mainNodeOnly = isset($params['main_node_only']) ? $params['main_node_only'] : false; $ignoreVisibility = isset($params['ignore_visibility']) ? $params['ignore_visibility'] : false; $classFilterType = isset($params['class_filter_type']) ? $params['class_filter_type'] : false; $classFilterArray = isset($params['class_filter_array']) ? $params['class_filter_array'] : false; $includeNotRated = isset($params['include_not_rated']) ? $params['include_not_rated'] : false; $selectSql = 'ezcontentobject.*, ezcontentobject_tree.*,'; $groupBySql = 'GROUP BY ezcontentobject_tree.node_id'; $orderBySql = 'ORDER BY rating DESC, rating_count DESC'; // default sorting // WARNING: group_by_owner only works as intended if user is owner of him self.. if (isset($params['group_by_owner']) && $params['group_by_owner']) { // group by owner instead of content object and fetch users instead of content objects $selectSql = 'ezcontentobject.*, owner_tree.*,'; $groupBySql = 'GROUP BY owner_tree.node_id'; } if (isset($params['owner_parent_node_id']) and is_numeric($params['owner_parent_node_id'])) { // filter by parent node of owner (main user group) $parentNodeId = $params['owner_parent_node_id']; $whereSql[] = 'owner_tree.parent_node_id = ' . $parentNodeId; } else { if (isset($params['owner_parent_node_path']) and is_string($params['owner_parent_node_path'])) { // filter recursivly by parent node id // supported format is /1/2/144/256/ ( $node.path_string ) $parentNodePath = $params['owner_parent_node_path']; $whereSql[] = "owner_tree.path_string != '{$parentNodePath}'"; $whereSql[] = "owner_tree.path_string like '{$parentNodePath}%'"; } else { if (isset($params['owner_id']) and is_numeric($params['owner_id'])) { // filter by owner_id ( user / contentobject id) $ownerId = $params['owner_id']; $whereSql[] = 'ezcontentobject.owner_id = ' . $ownerId; } } } if (isset($params['parent_node_id']) and is_numeric($params['parent_node_id'])) { // filter by main parent node id $parentNodeId = $params['parent_node_id']; $whereSql[] = 'ezcontentobject_tree.parent_node_id = ' . $parentNodeId; } else { if (isset($params['parent_node_path'])) { if (is_string($params['parent_node_path'])) { // filter recursivly by main parent node id // supported format is /1/2/144/256/ ( $node.path_string ) $parentNodePath = $params['parent_node_path']; $whereSql[] = "ezcontentobject_tree.path_string != '{$parentNodePath}'"; $whereSql[] = "ezcontentobject_tree.path_string like '{$parentNodePath}%'"; } else { eZDebug::writeError("Parameter 'parent_node_path' needs to be node path_string, was '{$params['parent_node_path']}'.", __METHOD__); } } } $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString($classFilterType, $classFilterArray); if ($classCondition === false) { eZDebug::writeNotice("Class filter returned false", __MEHOD__); return null; } if (isset($params['limit'])) { $limit = (int) $params['limit']; } if (isset($params['offset'])) { $offset = (int) $params['offset']; } if ($includeNotRated) { $ratingFromSql = 'LEFT JOIN ezstarrating ON ezstarrating.contentobject_id = ezcontentobject.id'; $ratingWhereSql = ''; } else { $ratingFromSql = ', ezstarrating'; $ratingWhereSql = 'ezstarrating.contentobject_id = ezcontentobject.id AND'; } if (isset($params['sort_by']) && is_array($params['sort_by'])) { $orderBySql = 'ORDER BY '; $orderArr = is_string($params['sort_by'][0]) ? array($params['sort_by']) : $params['sort_by']; foreach ($orderArr as $key => $order) { $orderBySqlPart = false; $direction = isset($order[1]) ? $order[1] : false; switch ($order[0]) { case 'rating': $orderBySqlPart = 'rating ' . ($direction ? 'ASC' : 'DESC'); break; case 'rating_count': $orderBySqlPart = 'rating_count ' . ($direction ? 'ASC' : 'DESC'); break; case 'object_count': $selectSql .= 'COUNT( ezcontentobject.id ) as object_count,'; $orderBySqlPart = 'object_count ' . ($direction ? 'ASC' : 'DESC'); break; case 'published': $orderBySqlPart = 'ezcontentobject.published ' . ($direction ? 'ASC' : 'DESC'); break; case 'modified': $orderBySqlPart = 'ezcontentobject.modified ' . ($direction ? 'ASC' : 'DESC'); break; case 'view_count': // notice: will only fetch nodes that HAVE a entry in the ezview_counter table!!! $selectSql .= 'ezview_counter.count as view_count,'; $fromSql .= ', ezview_counter'; $whereSql[] = 'ezcontentobject_tree.node_id = ezview_counter.node_id'; $orderBySqlPart = 'view_count ' . ($direction ? 'ASC' : 'DESC'); break; default: if (isset($params['extended_attribute_filter'])) { $orderBySqlPart = $order[0] . ' ' . ($direction ? 'ASC' : 'DESC'); } else { eZDebug::writeError("Unsuported sort type '{$order['0']}', for fetch_by_starrating().", __METHOD__); } break; } if ($orderBySqlPart) { if ($key !== 0) { $orderBySql .= ','; } $orderBySql .= $orderBySqlPart; } } } $whereSql = $whereSql ? implode($whereSql, ' AND ') . ' AND ' : ''; $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings($params['extended_attribute_filter']); $limitation = isset($params['limitation']) && is_array($params['limitation']) ? $params['limitation'] : false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $useVersionName = true; $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString($useVersionName); $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString($useVersionName); $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString($useVersionName, false); $mainNodeOnlyCond = eZContentObjectTreeNode::createMainNodeConditionSQLString($mainNodeOnly); $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility); $db = eZDB::instance(); $sql = "SELECT\n {$selectSql}\n AVG( ezstarrating.rating_average ) as rating,\n SUM( ezstarrating.rating_count ) as rating_count,\n ezcontentclass.serialized_name_list as class_serialized_name_list,\n ezcontentclass.identifier as class_identifier,\n ezcontentclass.is_container as is_container\n {$versionNameTargets}\n {$extendedAttributeFilter['columns']}\n FROM\n ezcontentobject_tree,\n ezcontentobject_tree owner_tree,\n ezcontentclass\n {$fromSql}\n {$versionNameTables}\n {$extendedAttributeFilter['tables']}\n {$sqlPermissionChecking['from']}\n ,ezcontentobject\n {$ratingFromSql}\n WHERE\n {$extendedAttributeFilter['joins']}\n {$ratingWhereSql}\n ezcontentobject.id = ezcontentobject_tree.contentobject_id AND\n ezcontentobject.owner_id = owner_tree.contentobject_id AND\n owner_tree.node_id = owner_tree.main_node_id AND\n ezcontentclass.version=0 AND\n ezcontentclass.id = ezcontentobject.contentclass_id AND\n {$mainNodeOnlyCond}\n {$classCondition}\n {$whereSql}\n\t {$versionNameJoins}\n\t {$showInvisibleNodesCond}\n\t {$sqlPermissionChecking['where']}\n\t {$languageFilter}\n {$groupBySql}\n {$orderBySql}"; $server = isset($sqlPermissionChecking['temp_tables'][0]) ? eZDBInterface::SERVER_SLAVE : false; if ($offset !== false || $limit !== false) { $rows = $db->arrayQuery($sql, array('offset' => $offset, 'limit' => $limit), $server); } else { $rows = $db->arrayQuery($sql, null, $server); } $db->dropTempTableList($sqlPermissionChecking['temp_tables']); unset($db); if (isset($rows[0]) && is_array($rows)) { if ($asObject) { $ret = ezsrRatingObjectTreeNode::makeObjectsArray($rows); if ($loadDataMap) { eZContentObject::fillNodeListAttributes($ret); } } else { $ret = $rows; } } else { if ($rows === false) { eZDebug::writeError('The ezstarrating table seems to be missing, contact your administrator', __METHOD__); $ret = array(); } else { $ret = array(); } } return $ret; }
function relatedObjects($fromObjectVersion = false, $objectID = false, $attributeID = 0, $groupByAttribute = false, $params = false, $reverseRelatedObjects = false) { if ($fromObjectVersion == false) { $fromObjectVersion = isset($this->CurrentVersion) ? $this->CurrentVersion : false; } $fromObjectVersion = (int) $fromObjectVersion; if (!$objectID) { $objectID = $this->ID; } $objectID = (int) $objectID; $limit = isset($params['Limit']) && is_numeric($params['Limit']) ? $params['Limit'] : false; $offset = isset($params['Offset']) && is_numeric($params['Offset']) ? $params['Offset'] : false; $asObject = isset($params['AsObject']) ? $params['AsObject'] : true; $loadDataMap = isset($params['LoadDataMap']) ? $params['LoadDataMap'] : false; $db = eZDB::instance(); $sortingString = ''; $sortingInfo = array('attributeFromSQL' => '', 'attributeWhereSQL' => ''); $showInvisibleNodesCond = ''; // process params (only SortBy and IgnoreVisibility currently supported): // Supported sort_by modes: // class_identifier, class_name, modified, name, published, section if (is_array($params)) { if (isset($params['SortBy'])) { if (!in_array($params['SortBy'], array('class_identifier', 'class_name', 'modified', 'name', 'published', 'section'))) { eZDebug::writeWarning("Unsupported sort_by parameter {$params['SortBy']}; check the online documentation for the list of supported sort types", __METHOD__); } else { $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings($params['SortBy']); $sortingString = ' ORDER BY ' . $sortingInfo['sortingFields']; } } if (isset($params['IgnoreVisibility'])) { $showInvisibleNodesCond = self::createFilterByVisibilitySQLString($params['IgnoreVisibility']); } } $relationTypeMasking = ''; $relationTypeMask = isset($params['AllRelations']) ? $params['AllRelations'] : $attributeID === false; if ($attributeID && ($relationTypeMask === false || $relationTypeMask === eZContentObject::RELATION_ATTRIBUTE)) { $attributeID = (int) $attributeID; $relationTypeMasking .= " AND contentclassattribute_id={$attributeID} "; $relationTypeMask = eZContentObject::RELATION_ATTRIBUTE; } elseif (is_bool($relationTypeMask)) { $relationTypeMask = eZContentObject::relationTypeMask($relationTypeMask); } if ($db->databaseName() == 'oracle') { $relationTypeMasking .= " AND bitand( relation_type, {$relationTypeMask} ) <> 0 "; } else { $relationTypeMasking .= " AND ( relation_type & {$relationTypeMask} ) <> 0 "; } // Create SQL $versionNameTables = ', ezcontentobject_name '; $versionNameTargets = ', ezcontentobject_name.name as name, ezcontentobject_name.real_translation '; $versionNameJoins = " AND ezcontentobject.id = ezcontentobject_name.contentobject_id AND\n ezcontentobject.current_version = ezcontentobject_name.content_version AND "; $versionNameJoins .= eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); $fromOrToContentObjectID = $reverseRelatedObjects == false ? " AND ezcontentobject.id=ezcontentobject_link.to_contentobject_id AND\n ezcontentobject_link.from_contentobject_id='{$objectID}' AND\n ezcontentobject_link.from_contentobject_version='{$fromObjectVersion}' " : " AND ezcontentobject.id=ezcontentobject_link.from_contentobject_id AND\n ezcontentobject_link.to_contentobject_id={$objectID} AND\n ezcontentobject_link.from_contentobject_version=ezcontentobject.current_version "; $query = "SELECT "; if ($groupByAttribute) { $query .= "ezcontentobject_link.contentclassattribute_id, "; } $query .= "\n ezcontentclass.serialized_name_list AS class_serialized_name_list,\n ezcontentclass.identifier as contentclass_identifier,\n ezcontentclass.is_container as is_container,\n ezcontentobject.* {$versionNameTargets}\n FROM\n ezcontentclass,\n ezcontentobject,\n ezcontentobject_link\n {$versionNameTables}\n {$sortingInfo['attributeFromSQL']}\n WHERE\n ezcontentclass.id=ezcontentobject.contentclass_id AND\n ezcontentclass.version=0 AND\n ezcontentobject.status=" . eZContentObject::STATUS_PUBLISHED . " AND\n {$sortingInfo['attributeWhereSQL']}\n ezcontentobject_link.op_code='0'\n {$relationTypeMasking}\n {$fromOrToContentObjectID}\n {$showInvisibleNodesCond}\n {$versionNameJoins}\n {$sortingString}"; if (!$offset && !$limit) { $relatedObjects = $db->arrayQuery($query); } else { $relatedObjects = $db->arrayQuery($query, array('offset' => $offset, 'limit' => $limit)); } $ret = array(); $tmp = array(); foreach ($relatedObjects as $object) { if ($asObject) { $obj = new eZContentObject($object); $obj->ClassName = eZContentClass::nameFromSerializedString($object['class_serialized_name_list']); } else { $obj = $object; } $tmp[] = $obj; if (!$groupByAttribute) { $ret[] = $obj; } else { $classAttrID = $object['contentclassattribute_id']; if (!isset($ret[$classAttrID])) { $ret[$classAttrID] = array(); } $ret[$classAttrID][] = $obj; } } if ($loadDataMap && $asObject) { eZContentObject::fillNodeListAttributes($tmp); } return $ret; }
static function subTreeByNodeID( $params = false, $nodeID = 0 ) { if ( !is_numeric( $nodeID ) and !is_array( $nodeID ) ) { return null; } if ( $params === false ) { $params = array( 'Depth' => false, 'Offset' => false, //'OnlyTranslated' => false, 'Language' => false, 'Limit' => false, 'SortBy' => false, 'AttributeFilter' => false, 'ExtendedAttributeFilter' => false, 'ClassFilterType' => false, 'ClassFilterArray' => false, 'GroupBy' => false ); } $offset = ( isset( $params['Offset'] ) && is_numeric( $params['Offset'] ) ) ? $params['Offset'] : false; //$onlyTranslated = ( isset( $params['OnlyTranslated'] ) ) ? $params['OnlyTranslated'] : false; $language = ( isset( $params['Language'] ) ) ? $params['Language'] : false; $limit = ( isset( $params['Limit'] ) && is_numeric( $params['Limit'] ) ) ? $params['Limit'] : false; $depth = ( isset( $params['Depth'] ) && is_numeric( $params['Depth'] ) ) ? $params['Depth'] : false; $depthOperator = ( isset( $params['DepthOperator'] ) ) ? $params['DepthOperator'] : false; $asObject = ( isset( $params['AsObject'] ) ) ? $params['AsObject'] : true; $loadDataMap = ( isset( $params['LoadDataMap'] ) ) ? $params['LoadDataMap'] : false; $groupBy = ( isset( $params['GroupBy'] ) ) ? $params['GroupBy'] : false; $mainNodeOnly = ( isset( $params['MainNodeOnly'] ) ) ? $params['MainNodeOnly'] : false; $ignoreVisibility = ( isset( $params['IgnoreVisibility'] ) ) ? $params['IgnoreVisibility'] : false; $objectNameFilter = ( isset( $params['ObjectNameFilter'] ) ) ? $params['ObjectNameFilter'] : false; if ( $offset < 0 ) { $offset = abs( $offset ); } if ( !isset( $params['SortBy'] ) ) $params['SortBy'] = false; if ( !isset( $params['ClassFilterType'] ) ) $params['ClassFilterType'] = false; $allowCustomSorting = false; if ( isset( $params['ExtendedAttributeFilter'] ) && is_array ( $params['ExtendedAttributeFilter'] ) ) { $allowCustomSorting = true; } $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $params['SortBy'], 'ezcontentobject_tree', $allowCustomSorting ); $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString( $params['ClassFilterType'], $params['ClassFilterArray'] ); if ( $classCondition === false ) { eZDebug::writeNotice( "Class filter returned false" ); return null; } $attributeFilter = eZContentObjectTreeNode::createAttributeFilterSQLStrings( $params['AttributeFilter'], $sortingInfo ); if ( $attributeFilter === false ) { return null; } $extendedAttributeFilter = eZContentObjectTreeNode::createExtendedAttributeFilterSQLStrings( $params['ExtendedAttributeFilter'] ); $mainNodeOnlyCond = eZContentObjectTreeNode::createMainNodeConditionSQLString( $mainNodeOnly ); $pathStringCond = ''; $notEqParentString = ''; // If the node(s) doesn't exist we return null. if ( !eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings( $pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator ) ) { return null; } if ( $language ) { if ( !is_array( $language ) ) { $language = array( $language ); } // This call must occur after eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings, // because the parent node may not exist in Language eZContentLanguage::setPrioritizedLanguages( $language ); } $groupBySelectText = ''; $groupBySQL = $extendedAttributeFilter['group_by']; if ( !$groupBySQL ) { eZContentObjectTreeNode::createGroupBySQLStrings( $groupBySelectText, $groupBySQL, $groupBy ); } else if ( $groupBy ) { eZDebug::writeError( "Cannot use group_by parameter together with extended attribute filter which sets group_by!", __METHOD__ ); } $useVersionName = true; $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString ( $useVersionName ); $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString( $useVersionName ); $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString ( $useVersionName, false ); $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' ); if ( $language ) { eZContentLanguage::clearPrioritizedLanguages(); } $objectNameFilterSQL = eZContentObjectTreeNode::createObjectNameFilterConditionSQLString( $objectNameFilter ); $limitation = ( isset( $params['Limitation'] ) && is_array( $params['Limitation'] ) ) ? $params['Limitation']: false; $limitationList = eZContentObjectTreeNode::getLimitationList( $limitation ); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList ); // Determine whether we should show invisible nodes. $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( !$ignoreVisibility ); $query = "SELECT DISTINCT ezcontentobject.*, ezcontentobject_tree.*, ezcontentclass.serialized_name_list as class_serialized_name_list, ezcontentclass.identifier as class_identifier, ezcontentclass.is_container as is_container $groupBySelectText $versionNameTargets $sortingInfo[attributeTargetSQL] $extendedAttributeFilter[columns] FROM ezcontentobject_tree, ezcontentobject,ezcontentclass $versionNameTables $sortingInfo[attributeFromSQL] $attributeFilter[from] $extendedAttributeFilter[tables] $sqlPermissionChecking[from] WHERE $pathStringCond $extendedAttributeFilter[joins] $sortingInfo[attributeWhereSQL] $attributeFilter[where] ezcontentclass.version=0 AND $notEqParentString ezcontentobject_tree.contentobject_id = ezcontentobject.id AND ezcontentclass.id = ezcontentobject.contentclass_id AND $mainNodeOnlyCond $classCondition $versionNameJoins $showInvisibleNodesCond $sqlPermissionChecking[where] $objectNameFilterSQL $languageFilter $groupBySQL"; if ( $sortingInfo['sortingFields'] ) $query .= " ORDER BY $sortingInfo[sortingFields]"; $db = eZDB::instance(); $server = count( $sqlPermissionChecking['temp_tables'] ) > 0 ? eZDBInterface::SERVER_SLAVE : false; $nodeListArray = $db->arrayQuery( $query, array( 'offset' => $offset, 'limit' => $limit ), $server ); if ( $asObject ) { $retNodeList = eZContentObjectTreeNode::makeObjectsArray( $nodeListArray ); if ( $loadDataMap === true ) eZContentObject::fillNodeListAttributes( $retNodeList ); else if ( $loadDataMap && is_numeric( $loadDataMap ) && $loadDataMap >= count( $retNodeList ) ) eZContentObject::fillNodeListAttributes( $retNodeList ); } else { $retNodeList = $nodeListArray; } // cleanup temp tables $db->dropTempTableList( $sqlPermissionChecking['temp_tables'] ); return $retNodeList; }