@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
10 | 10 | * @author Agel_Nash <[email protected]>, kabachello <[email protected]> |
11 | 11 | */ |
12 | -class site_content_menuDocLister extends site_contentDocLister |
|
13 | -{ |
|
12 | +class site_content_menuDocLister extends site_contentDocLister |
|
13 | +{ |
|
14 | 14 | public $levels = array(); |
15 | 15 | protected $currentLevel = 1; |
16 | 16 | protected $docTvs = array(); |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | * @param mixed $IDs список id документов по которым необходима выборка |
26 | 26 | * @return array очищенный массив |
27 | 27 | */ |
28 | - public function setIDs($IDs) |
|
29 | - { |
|
28 | + public function setIDs($IDs) |
|
29 | + { |
|
30 | 30 | $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2); |
31 | 31 | $IDs = $this->cleanIDs($IDs); |
32 | 32 | $this->debug->debugEnd("setIDs"); |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @param string $tvlist |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - public function getDocs($tvlist = '') |
|
42 | - { |
|
41 | + public function getDocs($tvlist = '') |
|
42 | + { |
|
43 | 43 | $this->extTV->getAllTV_Name(); |
44 | - if ($ids = $this->getCFGDef('documents')) { |
|
44 | + if ($ids = $this->getCFGDef('documents')) { |
|
45 | 45 | $this->setIDs($ids); |
46 | 46 | $docs = $this->getDocList(); |
47 | 47 | $display = count($docs); |
48 | 48 | $iteration = 1; |
49 | - foreach ($docs as $id => &$item) { |
|
49 | + foreach ($docs as $id => &$item) { |
|
50 | 50 | $item['iteration'] = $iteration++; |
51 | 51 | $item['_display'] = $display; |
52 | 52 | $item['_parent'] = $item['parent']; |
@@ -54,52 +54,53 @@ discard block |
||
54 | 54 | } |
55 | 55 | $this->levels[1] = $docs; |
56 | 56 | $this->setActiveBranch($this->getHereId(), 1); |
57 | - } else { |
|
57 | + } else { |
|
58 | 58 | $this->_getChildren(); |
59 | 59 | } |
60 | 60 | |
61 | - if ($tvlist == '') { |
|
61 | + if ($tvlist == '') { |
|
62 | 62 | $tvlist = $this->getCFGDef('tvList', ''); |
63 | 63 | } |
64 | 64 | |
65 | - if ($tvlist != '') { |
|
65 | + if ($tvlist != '') { |
|
66 | 66 | $ids = array(); |
67 | - foreach ($this->levels as $level => $docs) { |
|
67 | + foreach ($this->levels as $level => $docs) { |
|
68 | 68 | $ids = array_merge($ids, array_keys($docs)); |
69 | 69 | } |
70 | - if (!empty($ids)) { |
|
70 | + if (!empty($ids)) { |
|
71 | 71 | $tv = $this->extTV->getTVList($ids, $tvlist); |
72 | - if (!is_array($tv)) { |
|
72 | + if (!is_array($tv)) { |
|
73 | 73 | $tv = array(); |
74 | 74 | } |
75 | 75 | $this->docTvs = $tv; |
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
79 | - if ($this->getCFGDef('countChildren', 0)) { |
|
79 | + if ($this->getCFGDef('countChildren', 0)) { |
|
80 | 80 | $this->countChildren(); |
81 | 81 | } |
82 | 82 | //TODO кэширование |
83 | 83 | return $this->levels; |
84 | 84 | } |
85 | 85 | |
86 | - public function _getChildren() { |
|
86 | + public function _getChildren() |
|
87 | + { |
|
87 | 88 | $maxDepth = $this->getCFGDef('maxDepth', 10); |
88 | - if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) { |
|
89 | + if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) { |
|
89 | 90 | $maxDepth = min($maxDepth, $this->setActiveBranch($this->getHereId())); |
90 | - if (empty(array_intersect($this->IDs, $this->activeBranch))) { |
|
91 | + if (empty(array_intersect($this->IDs, $this->activeBranch))) { |
|
91 | 92 | $maxDepth = 1; |
92 | 93 | $this->config->setConfig(array('hideSubMenus' => 0)); |
93 | 94 | }; |
94 | - } else { |
|
95 | + } else { |
|
95 | 96 | $this->setActiveBranch($this->getHereId()); |
96 | 97 | } |
97 | - if ($oIds = $this->getCFGDef('openIds')) { |
|
98 | + if ($oIds = $this->getCFGDef('openIds')) { |
|
98 | 99 | $maxDepth = 1; |
99 | 100 | $oIds = $this->cleanIDs($oIds); |
100 | 101 | $oIds[] = $this->getHereId(); |
101 | - foreach ($oIds as $id) { |
|
102 | - if (($c = $this->setActiveBranch($id)) > $maxDepth) { |
|
102 | + foreach ($oIds as $id) { |
|
103 | + if (($c = $this->setActiveBranch($id)) > $maxDepth) { |
|
103 | 104 | $maxDepth = $c; |
104 | 105 | } |
105 | 106 | } |
@@ -107,44 +108,44 @@ discard block |
||
107 | 108 | } |
108 | 109 | $currentLevel = &$this->currentLevel; |
109 | 110 | $currentLevel = 1; |
110 | - if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) { |
|
111 | + if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) { |
|
111 | 112 | $this->config->setConfig(array('showParent' => 0)); |
112 | 113 | } |
113 | 114 | $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
114 | - while ($currentLevel <= $maxDepth) { |
|
115 | + while ($currentLevel <= $maxDepth) { |
|
115 | 116 | $orderBy = $this->getCFGDef('orderBy'); |
116 | - if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) { |
|
117 | + if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) { |
|
117 | 118 | $docs = $this->getDocList(); |
118 | 119 | $this->config->setConfig(array('showParent' => 0)); |
119 | - } else { |
|
120 | + } else { |
|
120 | 121 | $docs = $this->getChildrenList(); |
121 | 122 | } |
122 | - if ($currentLevel == 1 && $joinMenus) { |
|
123 | + if ($currentLevel == 1 && $joinMenus) { |
|
123 | 124 | $tmp = array(); |
124 | 125 | $display = 0; |
125 | 126 | $iteration = 1; |
126 | - foreach ($docs as $id => $item) { |
|
127 | + foreach ($docs as $id => $item) { |
|
127 | 128 | $tmp[$item['parent']][] = $item['id']; |
128 | 129 | $display++; |
129 | 130 | } |
130 | - foreach ($tmp as $id => $item) { |
|
131 | - foreach ($item as $_id) { |
|
131 | + foreach ($tmp as $id => $item) { |
|
132 | + foreach ($item as $_id) { |
|
132 | 133 | $docs[$_id]['_display'] = $display; |
133 | 134 | $docs[$_id]['iteration'] = $iteration++; |
134 | 135 | } |
135 | 136 | } |
136 | 137 | unset($tmp); |
137 | - } else { |
|
138 | - foreach ($docs as $id => &$item) { |
|
138 | + } else { |
|
139 | + foreach ($docs as $id => &$item) { |
|
139 | 140 | $parent = $item['parent']; |
140 | - if (!isset($this->display[$parent])) { |
|
141 | + if (!isset($this->display[$parent])) { |
|
141 | 142 | $this->display[$parent] = 1; |
142 | 143 | } |
143 | 144 | $item['iteration'] = $this->display[$parent]++; |
144 | 145 | } |
145 | 146 | } |
146 | 147 | $this->config->setConfig(array('orderBy' => $orderBy)); |
147 | - if (empty($docs)) { |
|
148 | + if (empty($docs)) { |
|
148 | 149 | break; |
149 | 150 | } |
150 | 151 | $this->levels[$currentLevel++] = $docs; |
@@ -158,8 +159,8 @@ discard block |
||
158 | 159 | * @param $id |
159 | 160 | * @param int $maxDepth |
160 | 161 | */ |
161 | - public function setActiveBranch($id, $maxDepth = 10) |
|
162 | - { |
|
162 | + public function setActiveBranch($id, $maxDepth = 10) |
|
163 | + { |
|
163 | 164 | $ids = array_values($this->modx->getParentIds($id, $maxDepth)); |
164 | 165 | $ids[] = $id; |
165 | 166 | $ids[] = 0; |
@@ -172,29 +173,29 @@ discard block |
||
172 | 173 | /** |
173 | 174 | * Подсчет количества непосредственных дочерних документов |
174 | 175 | */ |
175 | - public function countChildren() |
|
176 | - { |
|
176 | + public function countChildren() |
|
177 | + { |
|
177 | 178 | $ids = array(); |
178 | 179 | $out = &$this->countChildren; |
179 | - foreach ($this->levels as $level => $docs) { |
|
180 | + foreach ($this->levels as $level => $docs) { |
|
180 | 181 | $ids = array_merge($ids, array_keys($docs)); |
181 | 182 | } |
182 | 183 | $maxDepth = count($this->levels); |
183 | 184 | $currentDepth = 1; |
184 | - while ($currentDepth <= $maxDepth) { |
|
185 | + while ($currentDepth <= $maxDepth) { |
|
185 | 186 | $_ids = implode(',', $ids); |
186 | - if (empty($_ids)) { |
|
187 | + if (empty($_ids)) { |
|
187 | 188 | break; |
188 | 189 | } |
189 | 190 | $q = $this->dbQuery("SELECT `parent`,COUNT(*) as `count` FROM {$this->getTable('site_content')} WHERE `parent` IN ({$_ids}) AND `published`=1 AND `deleted`=0 GROUP BY `parent`"); |
190 | 191 | $_ids = array(); |
191 | - while ($row = $this->modx->db->getRow($q)) { |
|
192 | + while ($row = $this->modx->db->getRow($q)) { |
|
192 | 193 | $_ids[] = $row['parent']; |
193 | 194 | $out[$row['parent']] = $row['count']; |
194 | 195 | } |
195 | - if ($_ids) { |
|
196 | + if ($_ids) { |
|
196 | 197 | $ids = $this->diff($ids, $_ids); |
197 | - } else { |
|
198 | + } else { |
|
198 | 199 | break; |
199 | 200 | } |
200 | 201 | $currentDepth++; |
@@ -207,12 +208,12 @@ discard block |
||
207 | 208 | * @param $a |
208 | 209 | * @return array |
209 | 210 | */ |
210 | - private function diff($b, $a) |
|
211 | - { |
|
211 | + private function diff($b, $a) |
|
212 | + { |
|
212 | 213 | $at = array_flip($a); |
213 | 214 | $d = array(); |
214 | - foreach ($b as $i) { |
|
215 | - if (!isset($at[$i])) { |
|
215 | + foreach ($b as $i) { |
|
216 | + if (!isset($at[$i])) { |
|
216 | 217 | $d[] = $i; |
217 | 218 | } |
218 | 219 | } |
@@ -227,17 +228,17 @@ discard block |
||
227 | 228 | * @param string $tpl шаблон |
228 | 229 | * @return string |
229 | 230 | */ |
230 | - public function render($tpl = '') |
|
231 | - { |
|
231 | + public function render($tpl = '') |
|
232 | + { |
|
232 | 233 | $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html')); |
233 | - if (empty($this->levels)) { |
|
234 | + if (empty($this->levels)) { |
|
234 | 235 | $noneTpl = $this->getCFGDef('noneTpl'); |
235 | 236 | $out = $noneTpl ? $this->parseChunk($noneTpl, array()) : ''; |
236 | - } else { |
|
237 | + } else { |
|
237 | 238 | $out = $this->_render($tpl); |
238 | 239 | } |
239 | 240 | |
240 | - if ($out) { |
|
241 | + if ($out) { |
|
241 | 242 | $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out); |
242 | 243 | } |
243 | 244 | $this->debug->debugEnd('render'); |
@@ -249,43 +250,45 @@ discard block |
||
249 | 250 | * @param string $tpl |
250 | 251 | * @return string |
251 | 252 | */ |
252 | - public function _render($tpl = '') |
|
253 | - { |
|
253 | + public function _render($tpl = '') |
|
254 | + { |
|
254 | 255 | $currentLevel = &$this->currentLevel; |
255 | 256 | $currentLevel = count($this->levels); |
256 | 257 | $docs = $this->levels; |
257 | 258 | /** @var prepare_DL_Extender_ $extPrepare */ |
258 | 259 | $extPrepare = $this->getExtender('prepare'); |
259 | - while ($currentLevel > 0) { |
|
260 | - foreach ($docs[$currentLevel] as $id => &$data) { |
|
261 | - if ($out = $this->prepareData($data)) { |
|
262 | - if (is_array($out)) { |
|
260 | + while ($currentLevel > 0) { |
|
261 | + foreach ($docs[$currentLevel] as $id => &$data) { |
|
262 | + if ($out = $this->prepareData($data)) { |
|
263 | + if (is_array($out)) { |
|
263 | 264 | $data = $out; |
264 | 265 | } |
265 | 266 | }; |
266 | - if (!isset($data['maxLevel'])) { |
|
267 | + if (!isset($data['maxLevel'])) { |
|
267 | 268 | $data['maxLevel'] = 1; |
268 | 269 | $docs[$currentLevel - 1][$data['parent']]['maxLevel'] = 0; |
269 | 270 | } |
270 | 271 | |
271 | - if ($extPrepare) { |
|
272 | + if ($extPrepare) { |
|
272 | 273 | $data = $extPrepare->init($this, array( |
273 | 274 | 'data' => $data, |
274 | 275 | 'nameParam' => 'prepare' |
275 | 276 | )); |
276 | - if (is_bool($data) && $data === false) { |
|
277 | + if (is_bool($data) && $data === false) { |
|
277 | 278 | continue; |
278 | 279 | } |
279 | 280 | } |
280 | 281 | |
281 | - if (isset($data['wrap'])) { |
|
282 | - if(is_array($data['wrap'])) $data['wrap'] = $this->parseRow($data['wrap']); |
|
282 | + if (isset($data['wrap'])) { |
|
283 | + if(is_array($data['wrap'])) { |
|
284 | + $data['wrap'] = $this->parseRow($data['wrap']); |
|
285 | + } |
|
283 | 286 | $data['wrap'] = $this->parseOuter($data); |
284 | 287 | } |
285 | 288 | $hideSubMenus = $this->getCFGDef('hideSubMenus', 0); |
286 | 289 | $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'], |
287 | 290 | $this->activeBranch)); |
288 | - if ($hideSubMenus) { |
|
291 | + if ($hideSubMenus) { |
|
289 | 292 | $docs[$currentLevel - 1][$data['parent']]['wrap'][] = $data; |
290 | 293 | } |
291 | 294 | } |
@@ -295,17 +298,19 @@ discard block |
||
295 | 298 | unset($data); |
296 | 299 | $out = ''; |
297 | 300 | $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
298 | - foreach ($docs[0] as $id => $data) { |
|
299 | - if (isset($data['wrap'])) { |
|
300 | - if ($joinMenus) { |
|
301 | + foreach ($docs[0] as $id => $data) { |
|
302 | + if (isset($data['wrap'])) { |
|
303 | + if ($joinMenus) { |
|
301 | 304 | $out .= $this->parseRow($data['wrap']); |
302 | - } else { |
|
305 | + } else { |
|
303 | 306 | $data['wrap'] = $this->parseRow($data['wrap']); |
304 | 307 | $out .= $this->parseOuter($data); |
305 | 308 | } |
306 | 309 | } |
307 | 310 | } |
308 | - if ($joinMenus) $out = $this->parseOuter(array('wrap' => $out)); |
|
311 | + if ($joinMenus) { |
|
312 | + $out = $this->parseOuter(array('wrap' => $out)); |
|
313 | + } |
|
309 | 314 | |
310 | 315 | return $out; |
311 | 316 | } |
@@ -315,33 +320,33 @@ discard block |
||
315 | 320 | * @param $data |
316 | 321 | * @return array |
317 | 322 | */ |
318 | - public function prepareData($data) |
|
319 | - { |
|
323 | + public function prepareData($data) |
|
324 | + { |
|
320 | 325 | /** |
321 | 326 | * @var e_DL_Extender $extE |
322 | 327 | */ |
323 | 328 | $extE = $this->getExtender('e', true, true); |
324 | 329 | $id = $data['id']; |
325 | - if (isset($this->docTvs[$id])) { |
|
330 | + if (isset($this->docTvs[$id])) { |
|
326 | 331 | $data = array_merge($data, $this->docTvs[$id]); |
327 | 332 | } |
328 | - if ($id == $this->getHereId()) { |
|
333 | + if ($id == $this->getHereId()) { |
|
329 | 334 | $data['here'] = 1; |
330 | 335 | } |
331 | - if (!isset($data['here']) && in_array($id, $this->activeBranch)) { |
|
336 | + if (!isset($data['here']) && in_array($id, $this->activeBranch)) { |
|
332 | 337 | $data['active'] = 1; |
333 | 338 | } |
334 | - if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) { |
|
339 | + if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) { |
|
335 | 340 | $data['state'] = in_array($data['id'], $this->activeBranch) ? 'open' : 'closed'; |
336 | 341 | } |
337 | 342 | |
338 | - if (!isset($data['_display'])) { |
|
343 | + if (!isset($data['_display'])) { |
|
339 | 344 | $data['_display'] = $this->display[$data['parent']] - 1; |
340 | 345 | } |
341 | - if ($data['iteration'] == 1) { |
|
346 | + if ($data['iteration'] == 1) { |
|
342 | 347 | $data['first'] = 1; |
343 | 348 | } |
344 | - if ($data['iteration'] == $data['_display']) { |
|
349 | + if ($data['iteration'] == $data['_display']) { |
|
345 | 350 | $data['last'] = 1; |
346 | 351 | } |
347 | 352 | |
@@ -349,12 +354,12 @@ discard block |
||
349 | 354 | $data[$titleField] = isset($data['menutitle']) && !empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle']; |
350 | 355 | $data['level'] = $this->currentLevel; |
351 | 356 | $data['url'] = $this->makeUrl($data); |
352 | - if ($this->getCFGDef('countChildren', 0)) { |
|
357 | + if ($this->getCFGDef('countChildren', 0)) { |
|
353 | 358 | $data['count'] = isset($this->countChildren[$data['id']]) ? $this->countChildren[$data['id']] : 0; |
354 | 359 | } |
355 | 360 | |
356 | - if ($out = $extE->init($this, compact('data'))) { |
|
357 | - if (is_array($out)) { |
|
361 | + if ($out = $extE->init($this, compact('data'))) { |
|
362 | + if (is_array($out)) { |
|
358 | 363 | $data = $out; |
359 | 364 | } |
360 | 365 | } |
@@ -367,16 +372,16 @@ discard block |
||
367 | 372 | * @param array $data |
368 | 373 | * @return string |
369 | 374 | */ |
370 | - public function parseOuter($data = array()) |
|
371 | - { |
|
375 | + public function parseOuter($data = array()) |
|
376 | + { |
|
372 | 377 | $tpl = $this->getCFGDef('outerTpl', '@CODE:<ul[+classes+]>[+wrap+]</ul>'); |
373 | 378 | $classes = ''; |
374 | 379 | $classNames = $this->getCFGDef('outerClass'); |
375 | - if ($this->currentLevel >= 1) { |
|
380 | + if ($this->currentLevel >= 1) { |
|
376 | 381 | $tpl = $this->getCFGDef('innerTpl', $tpl); |
377 | 382 | $classNames = $this->getCFGDef('innerClass'); |
378 | 383 | } |
379 | - if ($classNames) { |
|
384 | + if ($classNames) { |
|
380 | 385 | $classes = " class=\"{$classNames}\""; |
381 | 386 | } |
382 | 387 | $tpl = isset($data['_renderOuterTpl']) ? $data['_renderOuterTpl'] : $tpl; |
@@ -393,10 +398,10 @@ discard block |
||
393 | 398 | * @param array $data |
394 | 399 | * @return string |
395 | 400 | */ |
396 | - public function parseRow($data = array()) |
|
397 | - { |
|
401 | + public function parseRow($data = array()) |
|
402 | + { |
|
398 | 403 | $out = ''; |
399 | - foreach ($data as $iteration => $item) { |
|
404 | + foreach ($data as $iteration => $item) { |
|
400 | 405 | $tpl = isset($item['_renderRowTpl']) ? $item['_renderRowTpl'] : $this->getRowTemplate($item); |
401 | 406 | $item = array_merge($item, $this->getClasses($item)); |
402 | 407 | $out .= $this->parseChunk($tpl, $item); |
@@ -410,14 +415,14 @@ discard block |
||
410 | 415 | * @param array $data |
411 | 416 | * @return string |
412 | 417 | */ |
413 | - protected function makeUrl($data = array()) |
|
414 | - { |
|
418 | + protected function makeUrl($data = array()) |
|
419 | + { |
|
415 | 420 | $out = ''; |
416 | - if ($this->getCFGDef('makeUrl', 1)) { |
|
417 | - if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) { |
|
421 | + if ($this->getCFGDef('makeUrl', 1)) { |
|
422 | + if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) { |
|
418 | 423 | $out = is_numeric($data['content']) ? $this->modx->makeUrl($data['content'], '', '', |
419 | 424 | $this->getCFGDef('urlScheme', '')) : $data['content']; |
420 | - } else { |
|
425 | + } else { |
|
421 | 426 | $out = isset($data['id']) && is_numeric($data['id']) ? $this->modx->makeUrl($data['id'], '', '', |
422 | 427 | $this->getCFGDef('urlScheme', '')) : ''; |
423 | 428 | } |
@@ -430,9 +435,9 @@ discard block |
||
430 | 435 | * Вовзращает id текущего документа |
431 | 436 | * @return int |
432 | 437 | */ |
433 | - public function getHereId() |
|
434 | - { |
|
435 | - if (!$hereId = (int)$this->getCFGDef('hereId')) { |
|
438 | + public function getHereId() |
|
439 | + { |
|
440 | + if (!$hereId = (int)$this->getCFGDef('hereId')) { |
|
436 | 441 | $hereId = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
437 | 442 | } |
438 | 443 | |
@@ -444,8 +449,8 @@ discard block |
||
444 | 449 | * @param array $data |
445 | 450 | * @return array |
446 | 451 | */ |
447 | - protected function getClasses($data = array()) |
|
448 | - { |
|
452 | + protected function getClasses($data = array()) |
|
453 | + { |
|
449 | 454 | $classes = isset($data['classes']) ? $data['classes'] : array( |
450 | 455 | 'rowClass' => '', |
451 | 456 | 'firstClass' => '', |
@@ -458,34 +463,34 @@ discard block |
||
458 | 463 | 'oddClass' => '', |
459 | 464 | 'evenClass' => '' |
460 | 465 | ); |
461 | - if (isset($data['state'])) { |
|
466 | + if (isset($data['state'])) { |
|
462 | 467 | $classes['stateClass'] = $this->getCFGDef($data['state'] . 'Class', $data['state']); |
463 | 468 | } |
464 | - if (isset($data['here'])) { |
|
469 | + if (isset($data['here'])) { |
|
465 | 470 | $classes['hereClass'] = $this->getCFGDef('hereClass', 'current'); |
466 | 471 | } |
467 | - if (isset($data['active'])) { |
|
472 | + if (isset($data['active'])) { |
|
468 | 473 | $classes['activeClass'] = $this->getCFGDef('activeClass', 'active'); |
469 | 474 | } |
470 | 475 | $classes['rowClass'] = $this->getCFGDef('rowClass'); |
471 | - if ($data['iteration'] % 2 == 1) { |
|
476 | + if ($data['iteration'] % 2 == 1) { |
|
472 | 477 | $classes['oddClass'] = $this->getCFGDef('oddClass', 'odd'); |
473 | - } else { |
|
478 | + } else { |
|
474 | 479 | $classes['evenClass'] = $this->getCFGDef('evenClass', 'even'); |
475 | 480 | } |
476 | - if (isset($data['first'])) { |
|
481 | + if (isset($data['first'])) { |
|
477 | 482 | $classes['firstClass'] = $this->getCFGDef('firstClass', 'first'); |
478 | 483 | } |
479 | - if (isset($data['last'])) { |
|
484 | + if (isset($data['last'])) { |
|
480 | 485 | $classes['lastClass'] = $this->getCFGDef('lastClass', 'last'); |
481 | 486 | } |
482 | - if ($levelClass = $this->getCFGDef('levelClass', 'level')) { |
|
487 | + if ($levelClass = $this->getCFGDef('levelClass', 'level')) { |
|
483 | 488 | $classes['levelClass'] = $levelClass . $data['level']; |
484 | 489 | } |
485 | - if (isset($data['type']) && $data['type'] == 'reference') { |
|
490 | + if (isset($data['type']) && $data['type'] == 'reference') { |
|
486 | 491 | $classes['webLinkClass'] = $this->getCFGDef('webLinkClass'); |
487 | 492 | } |
488 | - if (!empty($data['wrap'])) { |
|
493 | + if (!empty($data['wrap'])) { |
|
489 | 494 | $classes['parentClass'] = $this->getCFGDef('parentClass'); |
490 | 495 | } |
491 | 496 | $classNames = implode(' ', array_filter(array_values($classes))); |
@@ -500,28 +505,28 @@ discard block |
||
500 | 505 | * @param array $data |
501 | 506 | * @return string |
502 | 507 | */ |
503 | - protected function getRowTemplate($data = array()) |
|
504 | - { |
|
508 | + protected function getRowTemplate($data = array()) |
|
509 | + { |
|
505 | 510 | $tpl = $this->getCFGDef('rowTpl', '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a></li>'); |
506 | - if (!empty($data['wrap'])) { |
|
511 | + if (!empty($data['wrap'])) { |
|
507 | 512 | $tpl = $this->getCFGDef('parentRowTpl', |
508 | 513 | '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a>[+wrap+]</li>'); |
509 | 514 | if ((isset($data['template']) && !$data['template']) || (isset($data['link_attributes']) && strpos($data['link_attributes'], |
510 | 515 | 'category') !== false) |
511 | - ) { |
|
516 | + ) { |
|
512 | 517 | $tpl = $this->getCFGDef('categoryFolderTpl', $tpl); |
513 | - } elseif (isset($data['here'])) { |
|
518 | + } elseif (isset($data['here'])) { |
|
514 | 519 | $tpl = $this->getCFGDef('parentRowHereTpl', $tpl); |
515 | - } elseif (isset($data['active'])) { |
|
520 | + } elseif (isset($data['active'])) { |
|
516 | 521 | $tpl = $this->getCFGDef('parentRowActiveTpl', $tpl); |
517 | 522 | } |
518 | - } elseif ($data['level'] > 1) { |
|
523 | + } elseif ($data['level'] > 1) { |
|
519 | 524 | $tpl = $this->getCFGDef('innerRowTpl', $tpl); |
520 | - if (isset($data['here'])) { |
|
525 | + if (isset($data['here'])) { |
|
521 | 526 | $tpl = $this->getCFGDef('innerRowHereTpl', $tpl); |
522 | 527 | } |
523 | - } else { |
|
524 | - if (isset($data['here'])) { |
|
528 | + } else { |
|
529 | + if (isset($data['here'])) { |
|
525 | 530 | $tpl = $this->getCFGDef('rowHereTpl', $tpl); |
526 | 531 | } |
527 | 532 | } |
@@ -535,35 +540,37 @@ discard block |
||
535 | 540 | * @param array $array |
536 | 541 | * @return string |
537 | 542 | */ |
538 | - public function getJSON($data, $fields, $array = array()) |
|
539 | - { |
|
543 | + public function getJSON($data, $fields, $array = array()) |
|
544 | + { |
|
540 | 545 | $currentLevel = &$this->currentLevel; |
541 | 546 | $currentLevel = count($this->levels); |
542 | 547 | $docs = $this->levels; |
543 | 548 | |
544 | - if (empty($docs)) return '[]'; |
|
549 | + if (empty($docs)) { |
|
550 | + return '[]'; |
|
551 | + } |
|
545 | 552 | |
546 | 553 | /** @var prepare_DL_Extender_ $extPrepare */ |
547 | 554 | $extPrepare = $this->getExtender('prepare'); |
548 | 555 | |
549 | - while ($currentLevel > 0) { |
|
550 | - foreach ($docs[$currentLevel] as $id => &$data) { |
|
551 | - if ($out = $this->prepareData($data)) { |
|
552 | - if (is_array($out)) { |
|
556 | + while ($currentLevel > 0) { |
|
557 | + foreach ($docs[$currentLevel] as $id => &$data) { |
|
558 | + if ($out = $this->prepareData($data)) { |
|
559 | + if (is_array($out)) { |
|
553 | 560 | $data = $out; |
554 | 561 | } |
555 | 562 | }; |
556 | 563 | |
557 | - if (isset($data['here']) || isset($data['active'])) { |
|
564 | + if (isset($data['here']) || isset($data['active'])) { |
|
558 | 565 | $docs[$currentLevel - 1][$data['parent']]['active'] = 1; |
559 | 566 | } |
560 | 567 | |
561 | - if ($extPrepare) { |
|
568 | + if ($extPrepare) { |
|
562 | 569 | $data = $extPrepare->init($this, array( |
563 | 570 | 'data' => $data, |
564 | 571 | 'nameParam' => 'prepare' |
565 | 572 | )); |
566 | - if (is_bool($data) && $data === false) { |
|
573 | + if (is_bool($data) && $data === false) { |
|
567 | 574 | continue; |
568 | 575 | } |
569 | 576 | } |
@@ -571,7 +578,7 @@ discard block |
||
571 | 578 | $hideSubMenus = $this->getCFGDef('hideSubMenus', 0); |
572 | 579 | $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'], |
573 | 580 | $this->activeBranch)); |
574 | - if ($hideSubMenus) { |
|
581 | + if ($hideSubMenus) { |
|
575 | 582 | $docs[$currentLevel - 1][$data['parent']]['children'][] = $data; |
576 | 583 | } |
577 | 584 | } |
@@ -581,11 +588,11 @@ discard block |
||
581 | 588 | unset($data); |
582 | 589 | $out = array(); |
583 | 590 | $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0); |
584 | - foreach ($docs[0] as $id => $data) { |
|
585 | - if (isset($data['children'])) { |
|
586 | - if ($joinMenus) { |
|
591 | + foreach ($docs[0] as $id => $data) { |
|
592 | + if (isset($data['children'])) { |
|
593 | + if ($joinMenus) { |
|
587 | 594 | $out = array_merge($out, $data['children']); |
588 | - } else { |
|
595 | + } else { |
|
589 | 596 | $out[] = $data['children']; |
590 | 597 | } |
591 | 598 | } |
@@ -602,8 +609,8 @@ discard block |
||
602 | 609 | * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра |
603 | 610 | * @return mixed значение из конфига |
604 | 611 | */ |
605 | - public function getCFGDef($name, $def = null) |
|
606 | - { |
|
612 | + public function getCFGDef($name, $def = null) |
|
613 | + { |
|
607 | 614 | return parent::getCFGDef($name . $this->currentLevel, parent::getCFGDef($name, $def)); |
608 | 615 | } |
609 | 616 | } |