static function subTreeCountByNodeID($params = array(), $nodeID) { if (!is_numeric($nodeID) and !is_array($nodeID)) { return null; } $language = isset($params['Language']) ? $params['Language'] : false; if ($language) { if (!is_array($language)) { $language = array($language); } eZContentLanguage::setPrioritizedLanguages($language); } $depth = isset($params['Depth']) && is_numeric($params['Depth']) ? $params['Depth'] : false; $depthOperator = isset($params['DepthOperator']) ? $params['DepthOperator'] : false; $pathStringCond = ''; $notEqParentString = ''; // If the node(s) doesn't exist we return null. if (!eZContentObjectTreeNodeNoLanguage::createPathConditionAndNotEqParentSQLStrings($pathStringCond, $notEqParentString, $nodeID, $depth, $depthOperator)) { return null; } $db = eZDB::instance(); $ini = eZINI::instance(); // Check for class filtering $classCondition = ''; if (isset($params['ClassFilterType']) and isset($params['ClassFilterArray']) and ($params['ClassFilterType'] == 'include' or $params['ClassFilterType'] == 'exclude') and count($params['ClassFilterArray']) > 0) { $classCondition = ' '; $i = 0; $classCount = count($params['ClassFilterArray']); $classIDArray = array(); foreach ($params['ClassFilterArray'] as $classID) { $originalClassID = $classID; // Check if classes are recerenced by identifier if (is_string($classID) && !is_numeric($classID)) { $classID = eZContentClass::classIDByIdentifier($classID); } if (is_numeric($classID)) { $classIDArray[] = $classID; } else { eZDebugSetting::writeWarning('kernel-content-class', "Invalid class identifier in subTree() classfilterarray, classID : " . $originalClassID); } } if (count($classIDArray) > 0) { $classCondition .= " ezcontentobject.contentclass_id "; if ($params['ClassFilterType'] == 'include') { $classCondition .= " IN "; } else { $classCondition .= " NOT IN "; } $classIDString = implode(', ', $classIDArray); $classCondition .= ' ( ' . $classIDString . ' ) AND'; } } // Main node check $mainNodeOnlyCond = ''; if (isset($params['MainNodeOnly']) && $params['MainNodeOnly'] === true) { $mainNodeOnlyCond = 'ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id AND'; } $languageFilter = ' AND ' . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $objectNameLanguageFilter = eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); if ($language) { eZContentLanguage::clearPrioritizedLanguages(); } $objectNameFilter = isset($params['ObjectNameFilter']) ? $params['ObjectNameFilter'] : false; $attributeFilterParam = isset($params['AttributeFilter']) ? $params['AttributeFilter'] : false; $sortingInfo = array('sortCount' => 0, 'attributeJoinCount' => 0); $attributeFilter = eZContentObjectTreeNodeNoLanguage::createAttributeFilterSQLStrings($attributeFilterParam, $sortingInfo, $language); if ($attributeFilter === false) { return null; } $objectNameFilterSQL = eZContentObjectTreeNodeNoLanguage::createObjectNameFilterConditionSQLString($objectNameFilter); $extendedAttributeFilter = eZContentObjectTreeNodeNoLanguage::createExtendedAttributeFilterSQLStrings($params['ExtendedAttributeFilter']); // Determine whether we should show invisible nodes. $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false; $showInvisibleNodesCond = eZContentObjectTreeNodeNoLanguage::createShowInvisibleSQLString(!$ignoreVisibility); $limitation = isset($params['Limitation']) && is_array($params['Limitation']) ? $params['Limitation'] : false; $limitationList = eZContentObjectTreeNodeNoLanguage::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNodeNoLanguage::createPermissionCheckingSQL($limitationList); $query = "SELECT\n count( DISTINCT ezcontentobject_tree.node_id ) as count\n FROM\n ezcontentobject_tree\n INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)\n INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n INNER JOIN ezcontentobject_name ON (\n ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n )\n {$attributeFilter['from']}\n {$extendedAttributeFilter['tables']}\n {$sqlPermissionChecking['from']}\n WHERE {$pathStringCond}\n {$extendedAttributeFilter['joins']}\n {$mainNodeOnlyCond}\n {$classCondition}\n {$attributeFilter['where']}\n ezcontentclass.version=0 AND\n {$notEqParentString}\n {$objectNameLanguageFilter}\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$objectNameFilterSQL}\n {$languageFilter} "; $server = count($sqlPermissionChecking['temp_tables']) > 0 ? eZDBInterface::SERVER_SLAVE : false; $nodeListArray = $db->arrayQuery($query, array(), $server); // cleanup temp tables $db->dropTempTableList($sqlPermissionChecking['temp_tables']); return $nodeListArray[0]['count']; }