| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZContentStructureTreeOperator class 4 // 5 // Created on: <14-Jul-2004 14:18:58 dl> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezcontentstructuretreeoperator.php 30 */ 31 32 /*! 33 \class eZContentStructureTreeOperator ezcontentstructuretreeoperator.php 34 \brief 35 */ 36 37 require_once ( 'kernel/classes/ezcontentlanguage.php' ); 38 include_once ( 'kernel/classes/ezcontentclassnamelist.php' ); 39 40 class eZContentStructureTreeOperator 41 { 42 function eZContentStructureTreeOperator( $name = 'content_structure_tree' ) 43 { 44 $this->Operators = array( $name ); 45 } 46 47 /*! 48 Returns the operators in this class. 49 */ 50 function &operatorList() 51 { 52 return $this->Operators; 53 } 54 55 /*! 56 See eZTemplateOperator::namedParameterList() 57 */ 58 function namedParameterList() 59 { 60 return array( 'root_node_id' => array( 'type' => 'int', 61 'required' => true, 62 'default' => 0 ), 63 'class_filter' => array( 'type' => 'array', 64 'required' => false, 65 'default' => false ), 66 'max_depth' => array( 'type' => 'int', 67 'required' => false, 68 'default' => 0 ), 69 'max_nodes' => array( 'type' => 'int', 70 'required' => false, 71 'default' => 0 ), 72 'sort_by' => array( 'type' => 'array', 73 'required' => false, 74 'default' => 'false' ), 75 'fetch_hidden' => array( 'type' => 'bool', 76 'required' => false, 77 'default' => 'false' ), 78 'unfold_node_id' => array( 'type' => 'int', 79 'required' => false, 80 'default' => 0 ) ); 81 } 82 83 /*! 84 \reimp 85 */ 86 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters ) 87 { 88 $sortArray = false; 89 $fetchHidden = false; 90 if ( $namedParameters[ 'sort_by' ] != 'false' ) 91 { 92 if( is_array($namedParameters[ 'sort_by' ])) 93 { 94 $sortArray = array(); 95 foreach( $namedParameters[ 'sort_by' ] as $parameter ) 96 { 97 $sortingMethod = explode("/", $parameter ); 98 $sortingMethod[1] = ($sortingMethod[1] == 'ascending') ? '1' : '0'; 99 $sortArray[] = $sortingMethod; 100 } 101 } 102 else 103 { 104 $sortingMethod = explode("/", $namedParameters[ 'sort_by' ]); 105 $sortingMethod[1] = ($sortingMethod[1] == 'ascending') ? '1' : '0'; 106 $sortArray = array(); 107 $sortArray[] =& $sortingMethod; 108 } 109 } 110 111 if ( $namedParameters[ 'fetch_hidden' ] != 'false' ) 112 { 113 $fetchHidden = true; 114 } 115 $operatorValue = eZContentStructureTreeOperator::contentStructureTree( $namedParameters['root_node_id'], 116 $namedParameters['class_filter'], 117 $namedParameters['max_depth'], 118 $namedParameters['max_nodes'], 119 $sortArray, 120 $fetchHidden, 121 $namedParameters['unfold_node_id'] ); 122 } 123 124 /*! 125 \static 126 Returns one-level children of node \a $nodeID if \a $countChildren = false, 127 othewise returns count of one-level children of node \a nodeID. 128 */ 129 function &subTree( $params, $nodeID, $countChildren = false ) 130 { 131 $nodeListArray = array(); 132 133 // sorting params 134 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $params['SortBy'] ); 135 136 // node params 137 $notEqParentString = eZContentObjectTreeNode::createNotEqParentSQLString( $nodeID, 1, false ); 138 $pathStringCond = eZContentObjectTreeNode::createPathConditionSQLString( $params['NodePath'], $params['NodeDepth'], 1, false ); 139 140 // class filter 141 $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString( $params['ClassFilterType'], $params['ClassFilterArray'] ); 142 if ( $classCondition === false ) 143 { 144 return $nodeListArray; 145 } 146 147 // permissions 148 $limitationParams = false; 149 $limitationList = eZContentObjectTreeNode::getLimitationList( $limitationParams ); 150 151 if ( $limitationList === false ) 152 { 153 return $nodeListArray; 154 } 155 156 $permissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList ); 157 158 // version 159 $useVersionName = true; 160 $versionNameTables = eZContentObjectTreeNode::createVersionNameTablesSQLString( $useVersionName ); 161 $versionNameTargets = eZContentObjectTreeNode::createVersionNameTargetsSQLString( $useVersionName ); 162 $versionNameJoins = eZContentObjectTreeNode::createVersionNameJoinsSQLString( $useVersionName ); 163 164 // invisible nodes. 165 $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( false, $params['FetchHidden'] ); 166 167 $query = ''; 168 if ( $countChildren ) 169 { 170 $query = "SELECT count(*) as count 171 FROM 172 ezcontentobject_tree, 173 ezcontentobject,ezcontentclass 174 $versionNameTables 175 $permissionChecking[from] 176 WHERE $pathStringCond 177 $classCondition 178 ezcontentclass.version=0 AND 179 $notEqParentString 180 ezcontentobject_tree.contentobject_id = ezcontentobject.id AND 181 ezcontentclass.id = ezcontentobject.contentclass_id 182 $versionNameJoins 183 $permissionChecking[where] "; 184 } 185 else 186 { 187 $query = "SELECT ezcontentobject.*, 188 ezcontentobject_tree.*, 189 ezcontentclass.serialized_name_list as class_serialized_name_list, 190 ezcontentclass.identifier as class_identifier, 191 ezcontentclass.is_container as is_container 192 $versionNameTargets 193 FROM 194 ezcontentobject_tree, 195 ezcontentobject,ezcontentclass 196 $versionNameTables 197 $sortingInfo[attributeFromSQL] 198 $permissionChecking[from] 199 WHERE 200 $pathStringCond 201 $sortingInfo[attributeWhereSQL] 202 ezcontentclass.version=0 AND 203 $notEqParentString 204 ezcontentobject_tree.contentobject_id = ezcontentobject.id AND 205 ezcontentclass.id = ezcontentobject.contentclass_id AND 206 $classCondition 207 ezcontentobject_tree.contentobject_is_published = 1 208 $versionNameJoins 209 $showInvisibleNodesCond 210 $permissionChecking[where] 211 ORDER BY $sortingInfo[sortingFields]"; 212 213 } 214 215 $db =& eZDB::instance(); 216 $nodeListArray = $db->arrayQuery( $query ); 217 218 if ( $countChildren ) 219 { 220 return $nodeListArray[0]['count']; 221 } 222 else 223 { 224 return $nodeListArray; 225 } 226 } 227 228 /*! 229 \static 230 \Returns a tree of content structure: 231 tree = array( tree_node, children ), where 232 'tree_node' is array( 'node' => info about node, 233 'object' => info about object ); 234 235 'children' is array( tree_node, children ); 236 */ 237 function &contentStructureTree( $rootNodeID, &$classFilter, $maxDepth, $maxNodes, &$sortArray, $fetchHidden, $unfoldNodeID ) 238 { 239 $contentTree =& eZContentStructureTreeOperator::initContentStructureTree( $rootNodeID, $fetchHidden, $classFilter ); 240 241 // if root node is invisible then no point to fetch children 242 //if ( count( $contentTree ) == 0 ) 243 // return $contentTree; 244 245 if ( $contentTree === false) 246 return $contentTree; 247 248 $nodesLeft = $maxNodes - 1; 249 $depthLeft = $maxDepth - 1; 250 251 eZContentStructureTreeOperator::children( $contentTree, $classFilter, $depthLeft, $nodesLeft, $sortArray, $fetchHidden, $unfoldNodeID ); 252 253 return $contentTree; 254 } 255 256 /*! 257 \static 258 \private 259 Parameters the same as in \a children. 260 \Returns one-level children. 261 */ 262 function oneLevelChildren( &$contentTree, &$classFilter, &$sortBy, &$nodesLeft, $fetchHidden ) 263 { 264 $parentNode =& $contentTree['parent_node']; 265 266 if ( !is_array( $parentNode ) || count( $parentNode['node'] ) == 0 ) 267 { 268 return false; 269 } 270 271 if ( !$parentNode['object']['is_container'] || $parentNode['node']['children_count'] == 0 ) 272 { 273 return true; 274 } 275 276 // fill parent node attributes 277 if ( $nodesLeft != 0) 278 { 279 // get children 280 $sortArray = ( $sortBy == false ) ? $parentNode['node']['sort_array'] : $sortBy; 281 282 $children =& eZContentStructureTreeOperator::subTree( array( 'SortBy' => $sortArray, 283 'ClassFilterType' => 'include', 284 'ClassFilterArray'=> $classFilter, 285 'NodePath' => $parentNode['node']['path_string'], 286 'NodeDepth' => $parentNode['node']['depth'], 287 'FetchHidden' => $fetchHidden ), 288 $parentNode['node']['node_id'] ); 289 if ( $children && count( $children ) > 0 ) 290 { 291 $childrenNodes =& $contentTree['children']; 292 // fill children attributes 293 foreach ( $children as $child ) 294 { 295 $childrenCount = 0; 296 297 if ( $child['is_container'] == '1' ) 298 { 299 $childrenCount = eZContentStructureTreeOperator::subTree( array( 'SortBy' => false, 300 'ClassFilterType' => 'include', 301 'ClassFilterArray'=> $classFilter, 302 'NodePath' => $child['path_string'], 303 'NodeDepth' => $child['depth'], 304 'FetchHidden' => $fetchHidden ), 305 $child['node_id'], 306 true ); 307 } 308 309 $childNode = eZContentStructureTreeOperator::createContentStructureNode( $child, $childrenCount ); 310 311 $childrenNodes[] = array( 'parent_node' => $childNode, 312 'children' => array() ); 313 314 --$nodesLeft; 315 if ( $nodesLeft == 0 ) 316 { 317 return false; 318 } 319 } 320 } 321 return true; 322 } 323 324 return false; 325 } 326 327 /*! 328 \static 329 \private 330 Creates a tree of content by recursive calls to \a children and \a oneLevelChildren. 331 \a $contentTree is a tree at previous call to \a children. 332 \a $classFilter is an array of class ids. Only nodes of these classes will be fetched from db. 333 \a $depthLeft determines a depth of recursion. 334 \a $nodesLeft determines a number of nodes which are left to fetch. 335 \a $sortBy is a method of sorting one-level children. 336 \a $fetchHidden - should or not fetch unpublished/hidden nodes 337 */ 338 function children( &$contentTree, &$classFilter, &$depthLeft, &$nodesLeft, &$sortBy, $fetchHidden, $unfoldNodeID ) 339 { 340 if ( $depthLeft == 0 ) 341 return false; 342 343 if ( eZContentStructureTreeOperator::oneLevelChildren( $contentTree, $classFilter, $sortBy, $nodesLeft, $fetchHidden ) ) 344 { 345 --$depthLeft; 346 if ( $depthLeft != 0 ) 347 { 348 $children =& $contentTree['children']; 349 $children_keys = array_keys( $children ); 350 351 foreach( $children_keys as $key ) 352 { 353 $child =& $children[$key]; 354 $currentDepth = $depthLeft; 355 356 if ( $unfoldNodeID != 0 and $unfoldNodeID != $child['parent_node']['node']['node_id'] ) 357 continue; 358 359 if ( !eZContentStructureTreeOperator::children( $child, $classFilter, $currentDepth, $nodesLeft, $sortBy, $fetchHidden, 0 ) ) 360 { 361 return false; 362 } 363 } 364 } 365 return true; 366 } 367 return false; 368 } 369 370 /*! 371 \static 372 \private 373 Creates a node of content structure tree and sets up attributes of node 374 using \a $treeNode to retrieve necessary data. 375 \return new content structure tree node. 376 */ 377 function createContentStructureNode( &$treeNode, $childrenCount ) 378 { 379 $node = array( 'node' => array( 'node_id' => $treeNode['node_id'], 380 'path_identification_string' => $treeNode['path_identification_string'], 381 'children_count' => $childrenCount, 382 'sort_array' => eZContentObjectTreeNode::sortArrayBySortFieldAndSortOrder( $treeNode['sort_field'], $treeNode['sort_order'] ), 383 'path_string' => $treeNode['path_string'], 384 'depth' => $treeNode['depth'], 385 'is_hidden' => $treeNode['is_hidden'], 386 'is_invisible' => $treeNode['is_invisible'] ), 387 'classes_js_array' => eZContentObjectTreeNode::availableClassListJsArray( array( 'path_string' => $treeNode['path_string'], 'is_container' => $treeNode['is_container'] ) ), 388 'object' => array( 'id' => $treeNode['id'], 389 'name' => $treeNode['name'], 390 'class_identifier' => $treeNode['class_identifier'], 391 'class_name' => eZContentClass::nameFromSerializedString( $treeNode['class_serialized_name_list'] ), 392 'published' => $treeNode['published'], 393 'is_container' => ( $treeNode['is_container'] == '1' ), 394 'language_js_array' => eZContentLanguage::jsArrayByMask( $treeNode['language_mask'] ) ) ); 395 return $node; 396 } 397 398 /*! 399 \static 400 \private 401 Initializes a tree: creates root node. 402 \return a tree with one node and empty children subtree. 403 */ 404 function &initContentStructureTree( $rootNodeID, $fetchHidden, $classFilter = false ) 405 { 406 // create initial subtree with root node and empty children. 407 $nodes = false; 408 $rootTreeNode = eZContentObjectTreeNode::fetch( $rootNodeID ); 409 if ( $rootTreeNode && $rootTreeNode->canRead() ) 410 { 411 if ( !$fetchHidden && ( $rootTreeNode->attribute( 'is_hidden' ) || $rootTreeNode->attribute( 'is_invisible' ) ) ) 412 { 413 $nodes = false; 414 } 415 else 416 { 417 $contentObject =& $rootTreeNode->attribute( 'object' ); 418 419 $viewNodeAllowed = true; 420 if ( is_array( $classFilter ) && count( $classFilter ) > 0 ) 421 { 422 $contentClassIdentifier =& $contentObject->attribute( 'class_identifier' ); 423 424 if ( !in_array( $contentClassIdentifier, $classFilter ) ) 425 $viewNodeAllowed = false; 426 } 427 428 if ( $viewNodeAllowed ) 429 { 430 $rootNode = array( 'node' => array( 'node_id' => $rootTreeNode->attribute( 'node_id' ), 431 'path_identification_string' => $rootTreeNode->attribute( 'path_identification_string' ), 432 'children_count' => $rootTreeNode->attribute( 'children_count' ), 433 'sort_array' => $rootTreeNode->attribute( 'sort_array' ), 434 'path_string' => $rootTreeNode->attribute( 'path_string' ), 435 'depth' => $rootTreeNode->attribute( 'depth' ), 436 'is_hidden' => $rootTreeNode->attribute( 'is_hidden' ), 437 'is_invisible' => $rootTreeNode->attribute( 'is_invisible' ) ), 438 'classes_js_array' => eZContentObjectTreeNode::availableClassListJsArray( array( 'node' => &$rootTreeNode ) ), 439 'object' => array( 'id' => $contentObject->attribute( 'id' ), 440 'name' => $contentObject->attribute( 'name' ), 441 'class_identifier' => $contentObject->attribute( 'class_identifier' ), 442 'class_name' => $contentObject->attribute('class_name'), 443 'published' => $contentObject->attribute( 'published' ), 444 'is_container' => true, 445 'language_js_array' => eZContentLanguage::jsArrayByMask( $contentObject->attribute( 'language_mask' ) ) ) ); 446 447 $nodes = array( 'parent_node' => &$rootNode, 448 'children' => array() ); 449 } 450 } 451 } 452 453 return $nodes; 454 } 455 456 /// \privatesection 457 var $Operators; 458 } 459 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |