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