Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztreemenuoperator.php
Go to the documentation of this file.
1 <?php
11 class eZTreeMenuOperator
12 {
18 public function __construct( $name = 'treemenu' )
19 {
20 $this->Operators = array( $name );
21 }
22
26 function operatorList()
27 {
28 return $this->Operators;
29 }
30
34 function namedParameterList()
35 {
36 return array( 'path' => array( 'type' => 'array',
37 'required' => true,
38 'default' => false ),
39 'node_id' => array( 'type' => 'int',
40 'required' => false,
41 'default' => false ),
42 'class_filter' => array( 'type' => 'array',
43 'required' => false,
44 'default' => false ),
45 'depth_skip' => array( 'type' => 'int',
46 'required' => false,
47 'default' => false ),
48 'max_level' => array( 'type' => 'int',
49 'required' => false,
50 'default' => false ),
51 'is_selected_method' => array( 'type' => 'string',
52 'required' => false,
53 'default' => 'tree' ),
54 'indentation_level' => array( 'type' => 'int',
55 'required' => false,
56 'default' => 15 ),
57 'language' => array( 'type' => 'string|array',
58 'required' => false,
59 'default' => false ),
60 'load_data_map' => array( 'type' => 'boolean',
61 'required' => false,
62 'default' => null ) );
63 }
64
65 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
66 {
67 $level = 0;
68 $done = false;
69 $i = 0;
70 $pathArray = array();
71 $tmpModulePath = $namedParameters['path'];
72 $classFilter = $namedParameters['class_filter'];
73 $language = $namedParameters['language'];
74 $loadDataMap = $namedParameters['load_data_map'];
75 // node_id is not used anymore
76 if ( !empty( $namedParameters['node_id'] ) )
77 {
78 eZDebug::writeNotice( 'Deprecated parameter "node_id" in treemenu template operator' );
79 }
80
81 if ( $classFilter === false )
82 {
83 $classFilter = array();
84 }
85 else if ( count( $classFilter ) == 0 )
86 {
87 $classFilter = array( 1 );
88 }
89 $classFilter = ( count( $classFilter ) == 1 and !isset( $classFilter[0] ) ) ? array( 1 ) : $classFilter;
90 $tmpModulePathCount = count( $tmpModulePath );
91 if ( !$tmpModulePath[ $tmpModulePathCount -1 ]['url'] and isset( $tmpModulePath[ $tmpModulePathCount -1 ]['node_id'] ) )
92 $tmpModulePath[ $tmpModulePathCount -1 ]['url'] = '/content/view/full/' . $tmpModulePath[ $tmpModulePathCount -1 ]['node_id'];
93
94 $depthSkip = $namedParameters['depth_skip'];
95 $indentationLevel = $namedParameters['indentation_level'];
96
97 $maxLevel = $namedParameters['max_level'];
98 $isSelectedMethod = $namedParameters['is_selected_method'];
99 if ( $maxLevel === false )
100 $maxLevel = 2;
101
102 while ( !$done && isset( $tmpModulePath[$i+$depthSkip] ) )
103 {
104 // get node id
105 $elements = explode( '/', $tmpModulePath[$i+$depthSkip]['url'] );
106 $nodeID = false;
107 if ( isset( $elements[4] ) )
108 $nodeID = $elements[4];
109
110 $excludeNode = false;
111
112 if ( isset( $elements[1] ) &&
113 isset( $elements[2] ) &&
114 $elements[1] == 'content' &&
115 $elements[2] == 'view' &&
116 is_numeric( $nodeID ) &&
117 $excludeNode == false &&
118 $level < $maxLevel )
119 {
120 $node = eZContentObjectTreeNode::fetch( $nodeID );
121 if ( !isset( $node ) ) { $operatorValue = $pathArray; return; }
122 if ( isset( $tmpModulePath[$i+$depthSkip+1] ) )
123 {
124 $nextElements = explode( '/', $tmpModulePath[$i+$depthSkip+1]['url'] );
125 if ( isset( $nextElements[4] ) )
126 {
127 $nextNodeID = $nextElements[4];
128 }
129 else
130 {
131 $nextNodeID = false;
132 }
133 }
134 else
135 $nextNodeID = false;
136
137 $menuChildren = eZContentObjectTreeNode::subTreeByNodeID( array( 'Depth' => 1,
138 'Offset' => 0,
139 'SortBy' => $node->sortArray(),
140 'Language' => $language,
141 'ClassFilterType' => 'include',
142 'ClassFilterArray' => $classFilter ),
143 $nodeID );
144
146 // or if less then 16 nodes and param is not set (null)
147 if ( $loadDataMap || ( $loadDataMap === null && count( $menuChildren ) <= 15 ) )
148 eZContentObject::fillNodeListAttributes( $menuChildren );
149
150 $tmpPathArray = array();
151 foreach ( $menuChildren as $child )
152 {
153 $name = $child->attribute( 'name' );
154 $tmpNodeID = $child->attribute( 'node_id' );
155
156 $url = "/content/view/full/$tmpNodeID/";
157 $urlAlias = '/' . $child->attribute( 'url_alias' );
158 $hasChildren = $child->attribute( 'is_container' ) && $child->attribute( 'children_count' ) > 0;
159 $contentObject = $child->attribute( 'object' );
160
161 $indent = ($i - 1) * $indentationLevel;
162
163 $isSelected = false;
164 $nextNextElements = ( $isSelectedMethod == 'node' and isset( $tmpModulePath[$i+$depthSkip+2]['url'] ) ) ? explode( '/', $tmpModulePath[$i+$depthSkip+2]['url'] ) : null;
165 if ( $nextNodeID === $tmpNodeID and !isset( $nextNextElements[4] ) )
166 {
167 $isSelected = true;
168 }
169
170 $tmpPathArray[] = array( 'id' => $tmpNodeID,
171 'level' => $i,
172 'class_name' => $contentObject->classname(),
173 'is_main_node' => $child->attribute( 'is_main' ),
174 'has_children' => $hasChildren,
175 'indent' => $indent,
176 'url_alias' => $urlAlias,
177 'url' => $url,
178 'text' => $name,
179 'is_selected' => $isSelected,
180 'node' => $child );
181 }
182
183 // find insert pos
184 $j = 0;
185 $insertPos = 0;
186 foreach ( $pathArray as $path )
187 {
188 if ( $path['id'] == $nodeID )
189 $insertPos = $j;
190 $j++;
191 }
192 $restArray = array_splice( $pathArray, $insertPos + 1 );
193
194 $pathArray = array_merge( $pathArray, $tmpPathArray );
195 $pathArray = array_merge( $pathArray, $restArray );
196 }
197 else
198 {
199 if ( $level == 0 )
200 {
201 $node = eZContentObjectTreeNode::fetch( 2 );
202 if ( !$node instanceof eZContentObjectTreeNode )
203 {
204 $operatorValue = $pathArray;
205 return;
206 }
207
208 $menuChildren = eZContentObjectTreeNode::subTreeByNodeID( array( 'Depth' => 1,
209 'Offset' => 0,
210 'SortBy' => $node->sortArray(),
211 'Language' => $language,
212 'ClassFilterType' => 'include',
213 'ClassFilterArray' => $classFilter ),
214 2 );
215
217 // or if less then 16 nodes and param is not set (null)
218 if ( $loadDataMap || ( $loadDataMap === null && count( $menuChildren ) < 16 ) )
219 eZContentObject::fillNodeListAttributes( $menuChildren );
220
221 $pathArray = array();
222 foreach ( $menuChildren as $child )
223 {
224 $name = $child->attribute( 'name' );
225 $tmpNodeID = $child->attribute( 'node_id' );
226
227 $url = "/content/view/full/$tmpNodeID/";
228 $urlAlias = '/' . $child->attribute( 'url_alias' );
229
230 $pathArray[] = array( 'id' => $tmpNodeID,
231 'level' => $i,
232 'is_main_node' => $child->attribute( 'is_main' ),
233 'url_alias' => $urlAlias,
234 'url' => $url,
235 'text' => $name,
236 'is_selected' => false,
237 'node' => $child );
238 }
239 }
240 $done = true;
241 }
242 ++$level;
243 ++$i;
244 }
245
246 $operatorValue = $pathArray;
247 }
248
250 public $Operators;
251 }
252
253 ?>
eZContentObjectTreeNode
Definition: ezcontentobjecttreenode.php:17
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZContentObjectTreeNode\subTreeByNodeID
static subTreeByNodeID( $params=false, $nodeID=0)
Definition: ezcontentobjecttreenode.php:1940
eZContentObject\fillNodeListAttributes
static fillNodeListAttributes( $objList, $asObject=true)
Definition: ezcontentobject.php:2290
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZTreeMenuOperator
Definition: eztreemenuoperator.php:12
eZTreeMenuOperator\operatorList
operatorList()
Definition: eztreemenuoperator.php:26
eZTreeMenuOperator\namedParameterList
namedParameterList()
Definition: eztreemenuoperator.php:34
eZTreeMenuOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: eztreemenuoperator.php:65
eZTreeMenuOperator\$Operators
$Operators
Definition: eztreemenuoperator.php:250
eZTreeMenuOperator\__construct
__construct( $name='treemenu')
Definition: eztreemenuoperator.php:18
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.