[BUGFIX] Refactored ElementInfo missed one table
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / ExtDirectNode.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Node for the usage with ExtDirect and ExtJS
31 *
32 * @author Stefan Galinski <stefan.galinski@gmail.com>
33 */
34 class ExtDirectNode extends \TYPO3\CMS\Backend\Tree\TreeNode {
35
36 /**
37 * Node type
38 *
39 * @var string
40 */
41 protected $type = '';
42
43 /**
44 * Leaf Node Indicator
45 *
46 * @var bool
47 */
48 protected $leaf = TRUE;
49
50 /**
51 * Indicator if the node is expanded
52 *
53 * @var boolean
54 */
55 protected $expanded = FALSE;
56
57 /**
58 * Indicator if the node can be expanded
59 *
60 * @var boolean
61 */
62 protected $expandable = FALSE;
63
64 /**
65 * Indicator if the node is draggable
66 *
67 * @var boolean
68 */
69 protected $draggable = TRUE;
70
71 /**
72 * Indicator if the node is allowed as a drop target
73 *
74 * @var boolean
75 */
76 protected $isDropTarget = TRUE;
77
78 /**
79 * Label
80 *
81 * @var string
82 */
83 protected $text = '';
84
85 /**
86 * Editable Label text
87 *
88 * @var string
89 */
90 protected $editableText = '';
91
92 /**
93 * Prefix text of the label
94 *
95 * @var string
96 */
97 protected $prefix = '';
98
99 /**
100 * Suffix text of the label
101 *
102 * @var string
103 */
104 protected $suffix = '';
105
106 /**
107 * CSS Class
108 *
109 * @var string
110 */
111 protected $cls = '';
112
113 /**
114 * Quick Tip
115 *
116 * @var string
117 */
118 protected $qtip = '';
119
120 /**
121 * Sprite Icon HTML
122 *
123 * @var string
124 */
125 protected $spriteIconCode = '';
126
127 /**
128 * Text source field (title, nav_title, ...)
129 *
130 * @var string
131 */
132 protected $t3TextSourceField = '';
133
134 /**
135 * Indicator if the copy mode is activated
136 *
137 * @var boolean
138 */
139 protected $t3InCopyMode = FALSE;
140
141 /**
142 * Indicator if the cut mode is activated
143 *
144 * @var boolean
145 */
146 protected $t3InCutMode = FALSE;
147
148 /**
149 * Database record (not serialized or merged into the result array!)
150 *
151 * @var array
152 */
153 protected $record = array();
154
155 /**
156 * Context Info
157 *
158 * @var array
159 */
160 protected $contextInfo = array();
161
162 /**
163 * Indicator if the label is editable
164 *
165 * @var boolean
166 */
167 protected $labelIsEditable = TRUE;
168
169 /**
170 * Indicator if the node can have children's
171 *
172 * @var boolean
173 */
174 protected $allowChildren = TRUE;
175
176 /**
177 * Set's the node type
178 *
179 * @param string $type
180 * @return void
181 */
182 public function setType($type) {
183 $this->type = $type;
184 }
185
186 /**
187 * Returns the node type
188 *
189 * @return string
190 */
191 public function getType() {
192 return $this->type;
193 }
194
195 /**
196 * Sets the leaf node indicator
197 *
198 * @param boolean $isLeaf
199 * @return void
200 */
201 public function setLeaf($isLeaf) {
202 $this->leaf = $isLeaf == TRUE;
203 }
204
205 /**
206 * Returns if the node is a leaf node
207 *
208 * @return boolean
209 */
210 public function isLeafNode() {
211 return $this->leaf;
212 }
213
214 /**
215 * Sets the expandable indicator
216 *
217 * @param boolean $expandable
218 * @return void
219 */
220 public function setExpandable($expandable) {
221 $this->expandable = $expandable == TRUE;
222 }
223
224 /**
225 * Returns the expandable indicator
226 *
227 * @return boolean
228 */
229 public function isExpandable() {
230 return $this->expandable;
231 }
232
233 /**
234 * Sets the expanded indicator
235 *
236 * @param boolean $expanded
237 * @return void
238 */
239 public function setExpanded($expanded) {
240 $this->expanded = $expanded == TRUE;
241 }
242
243 /**
244 * Returns the expanded indicator
245 *
246 * @return boolean
247 */
248 public function isExpanded() {
249 if ($this->isLeafNode()) {
250 return TRUE;
251 }
252 return $this->expanded;
253 }
254
255 /**
256 * Sets the draggable indicator
257 *
258 * @param boolean $draggable
259 * @return void
260 */
261 public function setDraggable($draggable) {
262 $this->draggable = $draggable == TRUE;
263 }
264
265 /**
266 * Returns the draggable indicator
267 *
268 * @return boolean
269 */
270 public function isDraggable() {
271 return $this->draggable;
272 }
273
274 /**
275 * Sets the indicator if the node can be a drop target
276 *
277 * @param boolean $isDropTarget
278 * @return void
279 */
280 public function setIsDropTarget($isDropTarget) {
281 $this->isDropTarget = $isDropTarget == TRUE;
282 }
283
284 /**
285 * Returns the indicator if the node is a drop target
286 *
287 * @return boolean
288 */
289 public function isDropTarget() {
290 return $this->isDropTarget;
291 }
292
293 /**
294 * Sets the label of the node with the source field and the prefix
295 *
296 * @param string $text
297 * @param string $textSourceField
298 * @param string $prefix
299 * @param string $suffix
300 * @return void
301 */
302 public function setText($text, $textSourceField = 'title', $prefix = '', $suffix = '') {
303 $this->text = $text;
304 $this->t3TextSourceField = $textSourceField;
305 $this->prefix = $prefix;
306 $this->suffix = $suffix;
307 }
308
309 /**
310 * Returns the label
311 *
312 * @return string
313 */
314 public function getText() {
315 return $this->text;
316 }
317
318 /**
319 * Sets the editable text
320 *
321 * @param string $editableText
322 * @return void
323 */
324 public function setEditableText($editableText) {
325 $this->editableText = $editableText;
326 }
327
328 /**
329 * Returns the editable text
330 *
331 * @return string
332 */
333 public function getEditableText() {
334 return $this->editableText;
335 }
336
337 /**
338 * Returns the source field of the label
339 *
340 * @return string
341 */
342 public function getTextSourceField() {
343 return $this->t3TextSourceField;
344 }
345
346 /**
347 * Sets the paste copy indicator
348 *
349 * @param boolean $inCopyMode
350 * @return void
351 */
352 public function setInCopyMode($inCopyMode) {
353 $this->t3InCopyMode = $inCopyMode == TRUE;
354 }
355
356 /**
357 * Returns the copy mode indicator
358 *
359 * @return boolean
360 */
361 public function isInCopyMode() {
362 return $this->t3InCopyMode;
363 }
364
365 /**
366 * Sets the paste cut indicator
367 *
368 * @param boolean $inCutMode
369 * @return void
370 */
371 public function setInCutMode($inCutMode) {
372 $this->t3InCutMode = $inCutMode == TRUE;
373 }
374
375 /**
376 * Returns the cut mode indicator
377 *
378 * @return boolean
379 */
380 public function isInCutMode() {
381 return $this->t3InCutMode;
382 }
383
384 /**
385 * Returns the prefix text of the label
386 *
387 * @return string
388 */
389 public function getPrefix() {
390 return $this->prefix;
391 }
392
393 /**
394 * Returns the suffix text of the label
395 *
396 * @return string
397 */
398 public function getSuffix() {
399 return $this->suffix;
400 }
401
402 /**
403 * Sets the css class(es)
404 *
405 * @param string $class
406 * @return void
407 */
408 public function setCls($class) {
409 $this->cls = $class;
410 }
411
412 /**
413 * Returns the css class(es)
414 *
415 * @return string
416 */
417 public function getCls() {
418 return $this->cls;
419 }
420
421 /**
422 * Sets the quick tip
423 *
424 * @param string $qtip
425 * @return void
426 */
427 public function setQTip($qtip) {
428 $this->qtip = $qtip;
429 }
430
431 /**
432 * Returns the quick tip
433 *
434 * @return string
435 */
436 public function getQTip() {
437 return $this->qtip;
438 }
439
440 /**
441 * Sets the sprite icon code
442 *
443 * @param string $spriteIcon
444 * @return void
445 */
446 public function setSpriteIconCode($spriteIcon) {
447 $this->spriteIconCode = $spriteIcon;
448 }
449
450 /**
451 * Returns the sprite icon code
452 *
453 * @return string
454 */
455 public function getSpriteIconCode() {
456 return $this->spriteIconCode;
457 }
458
459 /**
460 * Sets the indicator if the label is editable
461 *
462 * @param boolean $labelIsEditable
463 * @return void
464 */
465 public function setLabelIsEditable($labelIsEditable) {
466 $this->labelIsEditable = $labelIsEditable == TRUE;
467 }
468
469 /**
470 * Returns the editable label indicator
471 *
472 * @return boolean
473 */
474 public function isLabelEditable() {
475 return $this->labelIsEditable;
476 }
477
478 /**
479 * Sets the database record array
480 *
481 * @param array $record
482 * @return void
483 */
484 public function setRecord($record) {
485 $this->record = (array) $record;
486 }
487
488 /**
489 * Returns the database record array
490 *
491 * @return array
492 */
493 public function getRecord() {
494 return $this->record;
495 }
496
497 /**
498 * Sets the context info
499 *
500 * @param array $contextInfo
501 * @return void
502 */
503 public function setContextInfo($contextInfo) {
504 $this->contextInfo = (array) $contextInfo;
505 }
506
507 /**
508 * Returns the context info
509 *
510 * @return array
511 */
512 public function getContextInfo() {
513 return (array) $this->contextInfo;
514 }
515
516 /**
517 * Sets the child nodes collection
518 *
519 * @param \TYPO3\CMS\Backend\Tree\TreeNodeCollection $childNodes
520 * @return void
521 */
522 public function setChildNodes(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $childNodes) {
523 parent::setChildNodes($childNodes);
524 if ($childNodes->count()) {
525 $this->setLeaf(FALSE);
526 }
527 }
528
529 /**
530 * Sets the indicator if the node can have child nodes
531 *
532 * @param boolean $allowChildren
533 * @return void
534 */
535 public function setAllowChildren($allowChildren) {
536 $this->allowChildren = $allowChildren == TRUE;
537 }
538
539 /**
540 * Checks if the node can have child nodes
541 *
542 * @return boolean
543 */
544 public function canHaveChildren() {
545 return $this->allowChildren;
546 }
547
548 /**
549 * Returns the node in an array representation that can be used for serialization
550 *
551 * @param boolean $addChildNodes
552 * @return array
553 */
554 public function toArray($addChildNodes = TRUE) {
555 $arrayRepresentation = array(
556 'serializeClassName' => get_class($this),
557 'id' => $this->getId(),
558 'type' => $this->getType(),
559 'editableText' => $this->getEditableText(),
560 'text' => $this->getPrefix() . $this->getText() . $this->getSuffix(),
561 'cls' => $this->getCls(),
562 'prefix' => $this->getPrefix(),
563 'suffix' => $this->getSuffix(),
564 'qtip' => $this->getQTip(),
565 'expanded' => $this->isExpanded(),
566 'expandable' => $this->isExpandable(),
567 'draggable' => $this->isDraggable(),
568 'isTarget' => $this->isDropTarget(),
569 'spriteIconCode' => $this->getSpriteIconCode(),
570 't3TextSourceField' => $this->getTextSourceField(),
571 't3InCopyMode' => $this->isInCopyMode(),
572 't3InCutMode' => $this->isInCutMode(),
573 't3ContextInfo' => $this->getContextInfo(),
574 'editable' => $this->isLabelEditable(),
575 'allowChildren' => $this->canHaveChildren()
576 );
577 // only set the leaf attribute if the node has children's,
578 // otherwise you cannot add child's to real leaf nodes
579 if (!$this->isLeafNode()) {
580 $arrayRepresentation['leaf'] = FALSE;
581 }
582 // Suhosin(?) or some other strange environment thingy prevents
583 // the direct copy of an array into an index of the same array
584 $copy = $arrayRepresentation;
585 $arrayRepresentation['nodeData'] = $copy;
586 if ($this->hasChildNodes()) {
587 $arrayRepresentation['children'] = $this->childNodes->toArray();
588 }
589 return $arrayRepresentation;
590 }
591
592 /**
593 * Sets data of the node by a given data array
594 *
595 * @param array $data
596 * @return void
597 */
598 public function dataFromArray($data) {
599 parent::dataFromArray($data);
600 $this->setType($data['type']);
601 $this->setText($data['label'], $data['t3TextSourceField'], $data['prefix'], $data['suffix']);
602 $this->setEditableText($data['editableText']);
603 $this->setCls($data['cls']);
604 $this->setQTip($data['qtip']);
605 $this->setExpanded($data['expanded']);
606 $this->setExpandable($data['expandable']);
607 $this->setDraggable($data['draggable']);
608 $this->setIsDropTarget($data['isTarget']);
609 $this->setSpriteIconCode($data['spriteIconCode']);
610 $this->setInCopyMode($data['t3InCopyMode']);
611 $this->setInCutMode($data['t3InCutMode']);
612 $this->setContextInfo($data['t3ContextInfo']);
613 $this->setLabelIsEditable($data['editable']);
614 $this->setAllowChildren($data['allowChildren']);
615 // only set the leaf attribute if it's applied
616 // otherwise you cannot insert nodes into this one
617 if (isset($data['leaf'])) {
618 $this->setLeaf(FALSE);
619 }
620 }
621
622 }
623
624
625 ?>