Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcontentstructuretreeoperator.php
Go to the documentation of this file.
1 <?php
16 class eZContentStructureTreeOperator
17 {
23 public function __construct( $name = 'content_structure_tree' )
24 {
25 $this->Operators = array( $name );
26 }
27
31 function operatorList()
32 {
33 return $this->Operators;
34 }
35
39 function namedParameterList()
40 {
41 return array( 'root_node_id' => array( 'type' => 'int',
42 'required' => true,
43 'default' => 0 ),
44 'class_filter' => array( 'type' => 'array',
45 'required' => false,
46 'default' => false ),
47 'max_depth' => array( 'type' => 'int',
48 'required' => false,
49 'default' => 0 ),
50 'max_nodes' => array( 'type' => 'int',
51 'required' => false,
52 'default' => 0 ),
53 'sort_by' => array( 'type' => 'array',
54 'required' => false,
55 'default' => 'false' ),
56 'fetch_hidden' => array( 'type' => 'bool',
57 'required' => false,
58 'default' => 'false' ),
59 'unfold_node_id' => array( 'type' => 'int',
60 'required' => false,
61 'default' => 0 ) );
62 }
63
64 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
65 {
66 $sortArray = false;
67 $fetchHidden = false;
68 if ( $namedParameters[ 'sort_by' ] != 'false' )
69 {
70 if( is_array($namedParameters[ 'sort_by' ]))
71 {
72 $sortArray = array();
73 foreach( $namedParameters[ 'sort_by' ] as $parameter )
74 {
75 $sortingMethod = explode("/", $parameter );
76 $sortingMethod[1] = ($sortingMethod[1] == 'ascending') ? '1' : '0';
77 $sortArray[] = $sortingMethod;
78 }
79 }
80 else
81 {
82 $sortingMethod = explode("/", $namedParameters[ 'sort_by' ]);
83 $sortingMethod[1] = ($sortingMethod[1] == 'ascending') ? '1' : '0';
84 $sortArray = array();
85 $sortArray[] = $sortingMethod;
86 }
87 }
88
89 if ( $namedParameters[ 'fetch_hidden' ] != 'false' )
90 {
91 $fetchHidden = true;
92 }
93 $operatorValue = eZContentStructureTreeOperator::contentStructureTree( $namedParameters['root_node_id'],
94 $namedParameters['class_filter'],
95 $namedParameters['max_depth'],
96 $namedParameters['max_nodes'],
97 $sortArray,
98 $fetchHidden,
99 $namedParameters['unfold_node_id'] );
100 }
101
107 function subTree( $params, $nodeID, $countChildren = false )
108 {
109 $nodeListArray = array();
110
111 // sorting params
112 $sortingInfo = eZContentObjectTreeNode::createSortingSQLStrings( $params['SortBy'] );
113
114 // node params
115 $notEqParentString = '';
116 $pathStringCond = '';
117 eZContentObjectTreeNode::createPathConditionAndNotEqParentSQLStrings( $pathStringCond, $notEqParentString, $nodeID, 1, false );
118
119 // class filter
120 $classCondition = eZContentObjectTreeNode::createClassFilteringSQLString( $params['ClassFilterType'], $params['ClassFilterArray'] );
121 if ( $classCondition === false )
122 {
123 return $nodeListArray;
124 }
125
126 // permissions
127 $limitationParams = false;
128 $limitationList = eZContentObjectTreeNode::getLimitationList( $limitationParams );
129
130 if ( $limitationList === false )
131 {
132 return $nodeListArray;
133 }
134
135 $permissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( $limitationList );
136
137 // invisible nodes.
138 $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString( false, $params['FetchHidden'] );
139
140 $query = '';
141 if ( $countChildren )
142 {
143 $query = "SELECT count(*) as count
144 FROM
145 ezcontentobject_tree
146 INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)
147 INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)
148 INNER JOIN ezcontentobject_name ON (
149 ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND
150 ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version
151 )
152 $permissionChecking[from]
153 WHERE $pathStringCond
154 $classCondition
155 ezcontentclass.version=0 AND
156 $notEqParentString
157 " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) . "
158 $permissionChecking[where] ";
159 }
160 else
161 {
162 $query = "SELECT ezcontentobject.*,
163 ezcontentobject_tree.*,
164 ezcontentclass.serialized_name_list as class_serialized_name_list,
165 ezcontentclass.identifier as class_identifier,
166 ezcontentclass.is_container as is_container,
167 ezcontentobject_name.name as name,
168 ezcontentobject_name.real_translation
169 FROM
170 ezcontentobject_tree
171 INNER JOIN ezcontentobject ON (ezcontentobject.id = ezcontentobject_tree.contentobject_id)
172 INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)
173 INNER JOIN ezcontentobject_name ON (
174 ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND
175 ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version
176 )
177 $sortingInfo[attributeFromSQL]
178 $permissionChecking[from]
179 WHERE
180 $pathStringCond
181 $sortingInfo[attributeWhereSQL]
182 ezcontentclass.version=0 AND
183 $notEqParentString
184 $classCondition
185 ezcontentobject_tree.contentobject_is_published = 1 AND
186 " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) . "
187 $showInvisibleNodesCond
188 $permissionChecking[where]
189 ORDER BY $sortingInfo[sortingFields]";
190
191 }
192
193 $db = eZDB::instance();
194 $nodeListArray = $db->arrayQuery( $query );
195
196 // cleanup temp tables
197 $db->dropTempTableList( $permissionChecking['temp_tables'] );
198
199 if ( $countChildren )
200 {
201 return $nodeListArray[0]['count'];
202 }
203 else
204 {
205 foreach ( $nodeListArray as $key => $row )
206 {
207 $nodeListArray[$key]['path_identification_string'] = eZContentObjectTreeNode::fetch( $row['node_id'] )->pathWithNames();
208 }
209 return $nodeListArray;
210 }
211 }
212
222 function contentStructureTree( $rootNodeID, $classFilter, $maxDepth, $maxNodes, $sortArray, $fetchHidden, $unfoldNodeID )
223 {
224 $contentTree = eZContentStructureTreeOperator::initContentStructureTree( $rootNodeID, $fetchHidden, $classFilter );
225
226 // if root node is invisible then no point to fetch children
227 //if ( count( $contentTree ) == 0 )
228 // return $contentTree;
229
230 if ( $contentTree === false)
231 return $contentTree;
232
233 $nodesLeft = $maxNodes - 1;
234 $depthLeft = $maxDepth - 1;
235
236 eZContentStructureTreeOperator::children( $contentTree, $classFilter, $depthLeft, $nodesLeft, $sortArray, $fetchHidden, $unfoldNodeID );
237
238 return $contentTree;
239 }
240
247 function oneLevelChildren( &$contentTree, &$classFilter, &$sortBy, &$nodesLeft, $fetchHidden )
248 {
249 $parentNode = $contentTree['parent_node'];
250
251 if ( !is_array( $parentNode ) || count( $parentNode['node'] ) == 0 )
252 {
253 return false;
254 }
255
256 if ( !$parentNode['object']['is_container'] || $parentNode['node']['children_count'] == 0 )
257 {
258 return true;
259 }
260
261 // fill parent node attributes
262 if ( $nodesLeft != 0)
263 {
264 // get children
265 $sortArray = ( $sortBy == false ) ? $parentNode['node']['sort_array'] : $sortBy;
266
267 $children = eZContentStructureTreeOperator::subTree( array( 'SortBy' => $sortArray,
268 'ClassFilterType' => 'include',
269 'ClassFilterArray'=> $classFilter,
270 'NodePath' => $parentNode['node']['path_string'],
271 'NodeDepth' => $parentNode['node']['depth'],
272 'FetchHidden' => $fetchHidden ),
273 $parentNode['node']['node_id'] );
274 if ( $children && count( $children ) > 0 )
275 {
276 $childrenNodes =& $contentTree['children'];
277 // fill children attributes
278 foreach ( $children as $child )
279 {
280 $childrenCount = 0;
281
282 if ( $child['is_container'] == '1' )
283 {
284 $childrenCount = eZContentStructureTreeOperator::subTree( array( 'SortBy' => false,
285 'ClassFilterType' => 'include',
286 'ClassFilterArray'=> $classFilter,
287 'NodePath' => $child['path_string'],
288 'NodeDepth' => $child['depth'],
289 'FetchHidden' => $fetchHidden ),
290 $child['node_id'],
291 true );
292 }
293
294 $childNode = eZContentStructureTreeOperator::createContentStructureNode( $child, $childrenCount );
295
296 $childrenNodes[] = array( 'parent_node' => $childNode,
297 'children' => array() );
298
299 --$nodesLeft;
300 if ( $nodesLeft == 0 )
301 {
302 return false;
303 }
304 }
305 }
306 return true;
307 }
308
309 return false;
310 }
311
323 function children( &$contentTree, &$classFilter, &$depthLeft, &$nodesLeft, &$sortBy, $fetchHidden, $unfoldNodeID )
324 {
325 if ( $depthLeft == 0 )
326 return false;
327
328 if ( eZContentStructureTreeOperator::oneLevelChildren( $contentTree, $classFilter, $sortBy, $nodesLeft, $fetchHidden ) )
329 {
330 --$depthLeft;
331 if ( $depthLeft != 0 )
332 {
333 $children =& $contentTree['children'];
334
335 foreach( $children as &$child )
336 {
337 $currentDepth = $depthLeft;
338
339 if ( $unfoldNodeID != 0 and $unfoldNodeID != $child['parent_node']['node']['node_id'] )
340 continue;
341
342 if ( !eZContentStructureTreeOperator::children( $child, $classFilter, $currentDepth, $nodesLeft, $sortBy, $fetchHidden, 0 ) )
343 {
344 return false;
345 }
346 }
347 }
348 return true;
349 }
350 return false;
351 }
352
360 function createContentStructureNode( &$treeNode, $childrenCount )
361 {
362 $node = array( 'node' => array( 'node_id' => $treeNode['node_id'],
363 'path_identification_string' => $treeNode['path_identification_string'],
364 'children_count' => $childrenCount,
365 'sort_array' => eZContentObjectTreeNode::sortArrayBySortFieldAndSortOrder( $treeNode['sort_field'], $treeNode['sort_order'] ),
366 'path_string' => $treeNode['path_string'],
367 'depth' => $treeNode['depth'],
368 'is_hidden' => $treeNode['is_hidden'],
369 'is_invisible' => $treeNode['is_invisible'] ),
370 'classes_js_array' => eZContentObjectTreeNode::availableClassListJsArray( array( 'path_string' => $treeNode['path_string'], 'is_container' => $treeNode['is_container'], 'node_id' => $treeNode['node_id'] ) ),
371 'object' => array( 'id' => $treeNode['id'],
372 'name' => $treeNode['name'],
373 'class_identifier' => $treeNode['class_identifier'],
374 'class_name' => eZContentClass::nameFromSerializedString( $treeNode['class_serialized_name_list'] ),
375 'published' => $treeNode['published'],
376 'is_container' => ( $treeNode['is_container'] == '1' ),
377 'language_js_array' => eZContentLanguage::jsArrayByMask( $treeNode['language_mask'] ) ) );
378 return $node;
379 }
380
387 function initContentStructureTree( $rootNodeID, $fetchHidden, $classFilter = false )
388 {
389 // create initial subtree with root node and empty children.
390 $nodes = false;
391 $rootTreeNode = eZContentObjectTreeNode::fetch( $rootNodeID );
392 if ( $rootTreeNode && $rootTreeNode->canRead() )
393 {
394 if ( !$fetchHidden && ( $rootTreeNode->attribute( 'is_hidden' ) || $rootTreeNode->attribute( 'is_invisible' ) ) )
395 {
396 return false;
397 }
398 else
399 {
400 $contentObject = $rootTreeNode->attribute( 'object' );
401
402 $viewNodeAllowed = true;
403 if ( is_array( $classFilter ) && count( $classFilter ) > 0 )
404 {
405 $contentClassIdentifier = $contentObject->attribute( 'class_identifier' );
406
407 if ( !in_array( $contentClassIdentifier, $classFilter ) )
408 $viewNodeAllowed = false;
409 }
410
411 if ( $viewNodeAllowed )
412 {
413 $rootNode = array( 'node' => array( 'node_id' => $rootTreeNode->attribute( 'node_id' ),
414 'path_identification_string' => $rootTreeNode->pathWithNames(),
415 'children_count' => $rootTreeNode->attribute( 'children_count' ),
416 'sort_array' => $rootTreeNode->attribute( 'sort_array' ),
417 'path_string' => $rootTreeNode->attribute( 'path_string' ),
418 'depth' => $rootTreeNode->attribute( 'depth' ),
419 'is_hidden' => $rootTreeNode->attribute( 'is_hidden' ),
420 'is_invisible' => $rootTreeNode->attribute( 'is_invisible' ) ),
421 'classes_js_array' => eZContentObjectTreeNode::availableClassListJsArray( array( 'node' => &$rootTreeNode ) ),
422 'object' => array( 'id' => $contentObject->attribute( 'id' ),
423 'name' => $contentObject->attribute( 'name' ),
424 'class_identifier' => $contentObject->attribute( 'class_identifier' ),
425 'class_name' => $contentObject->attribute('class_name'),
426 'published' => $contentObject->attribute( 'published' ),
427 'is_container' => true,
428 'language_js_array' => eZContentLanguage::jsArrayByMask( $contentObject->attribute( 'language_mask' ) ) ) );
429
430 $nodes = array( 'parent_node' => &$rootNode,
431 'children' => array() );
432 }
433 }
434 }
435
436 return $nodes;
437 }
438
440 public $Operators;
441 }
442 ?>
eZContentClass\nameFromSerializedString
static nameFromSerializedString( $serializedNameList)
Definition: ezcontentclass.php:1529
eZContentLanguage\sqlFilter
static sqlFilter( $languageTable, $languageListTable=null, $languageAttributeName='language_id', $languageListAttributeName='language_mask', $lang=false)
Definition: ezcontentlanguage.php:692
eZContentLanguage\jsArrayByMask
static jsArrayByMask( $mask)
Definition: ezcontentlanguage.php:878
eZContentObjectTreeNode\createSortingSQLStrings
static createSortingSQLStrings( $sortList, $treeTableName='ezcontentobject_tree', $allowCustomColumns=false)
Definition: ezcontentobjecttreenode.php:560
eZContentObjectTreeNode\createShowInvisibleSQLString
static createShowInvisibleSQLString( $useSettings, $fetchHidden=true)
Definition: ezcontentobjecttreenode.php:1859
eZContentObjectTreeNode\sortArrayBySortFieldAndSortOrder
static sortArrayBySortFieldAndSortOrder( $sortField, $sortOrder)
Definition: ezcontentobjecttreenode.php:2816
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZContentObjectTreeNode\createPathConditionAndNotEqParentSQLStrings
static createPathConditionAndNotEqParentSQLStrings(&$outPathConditionStr, &$outNotEqParentStr, $nodeID, $depth=false, $depthOperator='le')
Definition: ezcontentobjecttreenode.php:1462
eZContentObjectTreeNode\getLimitationList
static getLimitationList(&$limitation)
Definition: ezcontentobjecttreenode.php:1895
eZContentObjectTreeNode\createClassFilteringSQLString
static createClassFilteringSQLString( $classFilterType, &$classFilterArray)
Definition: ezcontentobjecttreenode.php:795
eZContentObjectTreeNode\createPermissionCheckingSQL
static createPermissionCheckingSQL( $limitationList, $treeTableName='ezcontentobject_tree', $tableAliasName='ezcontentobject_tree')
Definition: ezcontentobjecttreenode.php:1662
eZContentObjectTreeNode\availableClassListJsArray
static availableClassListJsArray( $parameters=false)
Definition: ezcontentobjecttreenode.php:6273
eZContentStructureTreeOperator
Definition: ezcontentstructuretreeoperator.php:17
eZContentStructureTreeOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: ezcontentstructuretreeoperator.php:64
eZContentStructureTreeOperator\contentStructureTree
contentStructureTree( $rootNodeID, $classFilter, $maxDepth, $maxNodes, $sortArray, $fetchHidden, $unfoldNodeID)
Definition: ezcontentstructuretreeoperator.php:222
eZContentStructureTreeOperator\$Operators
$Operators
Definition: ezcontentstructuretreeoperator.php:440
eZContentStructureTreeOperator\__construct
__construct( $name='content_structure_tree')
Definition: ezcontentstructuretreeoperator.php:23
eZContentStructureTreeOperator\subTree
subTree( $params, $nodeID, $countChildren=false)
Definition: ezcontentstructuretreeoperator.php:107
eZContentStructureTreeOperator\operatorList
operatorList()
Definition: ezcontentstructuretreeoperator.php:31
eZContentStructureTreeOperator\createContentStructureNode
createContentStructureNode(&$treeNode, $childrenCount)
Definition: ezcontentstructuretreeoperator.php:360
eZContentStructureTreeOperator\children
children(&$contentTree, &$classFilter, &$depthLeft, &$nodesLeft, &$sortBy, $fetchHidden, $unfoldNodeID)
Definition: ezcontentstructuretreeoperator.php:323
eZContentStructureTreeOperator\initContentStructureTree
initContentStructureTree( $rootNodeID, $fetchHidden, $classFilter=false)
Definition: ezcontentstructuretreeoperator.php:387
eZContentStructureTreeOperator\oneLevelChildren
oneLevelChildren(&$contentTree, &$classFilter, &$sortBy, &$nodesLeft, $fetchHidden)
Definition: ezcontentstructuretreeoperator.php:247
eZContentStructureTreeOperator\namedParameterList
namedParameterList()
Definition: ezcontentstructuretreeoperator.php:39
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.