TYPO3 API  SVNRelease
class.t3lib_tree_extdirect_node.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010-2011 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 
00028 /**
00029  * Node for the usage with ExtDirect and ExtJS
00030  *
00031  * @author Stefan Galinski <stefan.galinski@gmail.com>
00032  * @package TYPO3
00033  * @subpackage t3lib
00034  */
00035 class t3lib_tree_extdirect_Node extends t3lib_tree_Node {
00036     /**
00037      * Node type
00038      *
00039      * @var string
00040      */
00041     protected $type = '';
00042 
00043     /**
00044      * Leaf Node Indicator
00045      *
00046      * @var bool
00047      */
00048     protected $leaf = TRUE;
00049 
00050     /**
00051      * Indicator if the node is expanded
00052      *
00053      * @var bool
00054      */
00055     protected $expanded = FALSE;
00056 
00057     /**
00058      * Indicator if the node can be expanded
00059      *
00060      * @var bool
00061      */
00062     protected $expandable = FALSE;
00063 
00064     /**
00065      * Indicator if the node is draggable
00066      *
00067      * @var bool
00068      */
00069     protected $draggable = TRUE;
00070 
00071     /**
00072      * Indicator if the node is allowed as a drop target
00073      *
00074      * @var bool
00075      */
00076     protected $isDropTarget = TRUE;
00077 
00078     /**
00079      * Label
00080      *
00081      * @var string
00082      */
00083     protected $text = '';
00084 
00085     /**
00086      * Editable Label text
00087      *
00088      * @var string
00089      */
00090     protected $editableText = '';
00091 
00092     /**
00093      * Prefix text of the label
00094      *
00095      * @var string
00096      */
00097     protected $prefix = '';
00098 
00099     /**
00100      * Suffix text of the label
00101      *
00102      * @var string
00103      */
00104     protected $suffix = '';
00105 
00106     /**
00107      * CSS Class
00108      *
00109      * @var string
00110      */
00111     protected $cls = '';
00112 
00113     /**
00114      * Quick Tip
00115      *
00116      * @var string
00117      */
00118     protected $qtip = '';
00119 
00120     /**
00121      * Sprite Icon HTML
00122      *
00123      * @var string
00124      */
00125     protected $spriteIconCode = '';
00126 
00127     /**
00128      * Text source field (title, nav_title, ...)
00129      *
00130      * @var string
00131      */
00132     protected $t3TextSourceField = '';
00133 
00134     /**
00135      * Indicator if the copy mode is activated
00136      *
00137      * @var bool
00138      */
00139     protected $t3InCopyMode = FALSE;
00140 
00141     /**
00142      * Indicator if the cut mode is activated
00143      *
00144      * @var bool
00145      */
00146     protected $t3InCutMode = FALSE;
00147 
00148     /**
00149      * Database record (not serialized or merged into the result array!)
00150      *
00151      * @var array
00152      */
00153     protected $record = array();
00154 
00155     /**
00156      * Context Info
00157      *
00158      * @var array
00159      */
00160     protected $contextInfo = array();
00161 
00162     /**
00163      * Indicator if the label is editable
00164      *
00165      * @var bool
00166      */
00167     protected $labelIsEditable = TRUE;
00168 
00169     /**
00170      * Indicator if the node can have children's
00171      *
00172      * @var bool
00173      */
00174     protected $allowChildren = TRUE;
00175 
00176     /**
00177      * Set's the node type
00178      *
00179      * @param string $type
00180      * @return void
00181      */
00182     public function setType($type) {
00183         $this->type = $type;
00184     }
00185 
00186     /**
00187      * Returns the node type
00188      *
00189      * @return string
00190      */
00191     public function getType() {
00192         return $this->type;
00193     }
00194 
00195     /**
00196      * Sets the leaf node indicator
00197      *
00198      * @param bool $isLeaf
00199      * @return void
00200      */
00201     public function setLeaf($isLeaf) {
00202         $this->leaf = ($isLeaf == TRUE);
00203     }
00204 
00205     /**
00206      * Returns if the node is a leaf node
00207      *
00208      * @return bool
00209      */
00210     public function isLeafNode() {
00211         return $this->leaf;
00212     }
00213 
00214     /**
00215      * Sets the expandable indicator
00216      *
00217      * @param bool $expandable
00218      * @return void
00219      */
00220     public function setExpandable($expandable) {
00221         $this->expandable = ($expandable == TRUE);
00222     }
00223 
00224     /**
00225      * Returns the expandable indicator
00226      *
00227      * @return bool
00228      */
00229     public function isExpandable() {
00230         return $this->expandable;
00231     }
00232 
00233     /**
00234      * Sets the expanded indicator
00235      *
00236      * @param bool $expanded
00237      * @return void
00238      */
00239     public function setExpanded($expanded) {
00240         $this->expanded = ($expanded == TRUE);
00241     }
00242 
00243     /**
00244      * Returns the expanded indicator
00245      *
00246      * @return bool
00247      */
00248     public function isExpanded() {
00249         if ($this->isLeafNode()) {
00250             return TRUE;
00251         }
00252 
00253         return $this->expanded;
00254     }
00255 
00256     /**
00257      * Sets the draggable indicator
00258      *
00259      * @param bool $draggable
00260      * @return void
00261      */
00262     public function setDraggable($draggable) {
00263         $this->draggable = ($draggable == TRUE);
00264     }
00265 
00266     /**
00267      * Returns the draggable indicator
00268      *
00269      * @return bool
00270      */
00271     public function isDraggable() {
00272         return $this->draggable;
00273     }
00274 
00275     /**
00276      * Sets the indicator if the node can be a drop target
00277      *
00278      * @param bool $isDropTarget
00279      * @return void
00280      */
00281     public function setIsDropTarget($isDropTarget) {
00282         $this->isDropTarget = ($isDropTarget == TRUE);
00283     }
00284 
00285     /**
00286      * Returns the indicator if the node is a drop target
00287      *
00288      * @return bool
00289      */
00290     public function isDropTarget() {
00291         return $this->isDropTarget;
00292     }
00293 
00294     /**
00295      * Sets the label of the node with the source field and the prefix
00296      *
00297      * @param string $text
00298      * @param string $textSourceField
00299      * @param string $prefix
00300      * @param string $suffix
00301      * @return void
00302      */
00303     public function setText($text, $textSourceField = 'title', $prefix = '', $suffix = '') {
00304         $this->text = $text;
00305         $this->t3TextSourceField = $textSourceField;
00306         $this->prefix = $prefix;
00307         $this->suffix = $suffix;
00308     }
00309 
00310     /**
00311      * Returns the label
00312      *
00313      * @return string
00314      */
00315     public function getText() {
00316         return $this->text;
00317     }
00318 
00319     /**
00320      * Sets the editable text
00321      *
00322      * @param string $editableText
00323      * @return void
00324      */
00325     public function setEditableText($editableText) {
00326         $this->editableText = $editableText;
00327     }
00328 
00329     /**
00330      * Returns the editable text
00331      *
00332      * @return string
00333      */
00334     public function getEditableText() {
00335         return $this->editableText;
00336     }
00337 
00338     /**
00339      * Returns the source field of the label
00340      *
00341      * @return string
00342      */
00343     public function getTextSourceField() {
00344         return $this->t3TextSourceField;
00345     }
00346 
00347     /**
00348      * Sets the paste copy indicator
00349      *
00350      * @param boolean $inCopyMode
00351      * @return void
00352      */
00353     public function setInCopyMode($inCopyMode) {
00354         $this->t3InCopyMode = ($inCopyMode == TRUE);
00355     }
00356 
00357     /**
00358      * Returns the copy mode indicator
00359      *
00360      * @return bool
00361      */
00362     public function isInCopyMode() {
00363         return $this->t3InCopyMode;
00364     }
00365 
00366     /**
00367      * Sets the paste cut indicator
00368      *
00369      * @param boolean $inCutMode
00370      * @return void
00371      */
00372     public function setInCutMode($inCutMode) {
00373         $this->t3InCutMode = ($inCutMode == TRUE);
00374     }
00375 
00376     /**
00377      * Returns the cut mode indicator
00378      *
00379      * @return bool
00380      */
00381     public function isInCutMode() {
00382         return $this->t3InCutMode;
00383     }
00384 
00385     /**
00386      * Returns the prefix text of the label
00387      *
00388      * @return string
00389      */
00390     public function getPrefix() {
00391         return $this->prefix;
00392     }
00393 
00394     /**
00395      * Returns the suffix text of the label
00396      *
00397      * @return string
00398      */
00399     public function getSuffix() {
00400         return $this->suffix;
00401     }
00402 
00403     /**
00404      * Sets the css class(es)
00405      *
00406      * @param string $class
00407      * @return void
00408      */
00409     public function setCls($class) {
00410         $this->cls = $class;
00411     }
00412 
00413     /**
00414      * Returns the css class(es)
00415      *
00416      * @return string
00417      */
00418     public function getCls() {
00419         return $this->cls;
00420     }
00421 
00422     /**
00423      * Sets the quick tip
00424      *
00425      * @param string $qtip
00426      * @return void
00427      */
00428     public function setQTip($qtip) {
00429         $this->qtip = $qtip;
00430     }
00431 
00432     /**
00433      * Returns the quick tip
00434      *
00435      * @return string
00436      */
00437     public function getQTip() {
00438         return $this->qtip;
00439     }
00440 
00441     /**
00442      * Sets the sprite icon code
00443      *
00444      * @param string $spriteIcon
00445      * @return void
00446      */
00447     public function setSpriteIconCode($spriteIcon) {
00448         $this->spriteIconCode = $spriteIcon;
00449     }
00450 
00451     /**
00452      * Returns the sprite icon code
00453      *
00454      * @return string
00455      */
00456     public function getSpriteIconCode() {
00457         return $this->spriteIconCode;
00458     }
00459 
00460     /**
00461      * Sets the indicator if the label is editable
00462      *
00463      * @param bool $labelIsEditable
00464      * @return void
00465      */
00466     public function setLabelIsEditable($labelIsEditable) {
00467         $this->labelIsEditable = ($labelIsEditable == TRUE);
00468     }
00469 
00470     /**
00471      * Returns the editable label indicator
00472      *
00473      * @return bool
00474      */
00475     public function isLabelEditable() {
00476         return $this->labelIsEditable;
00477     }
00478 
00479     /**
00480      * Sets the database record array
00481      *
00482      * @param array $record
00483      * @return void
00484      */
00485     public function setRecord($record) {
00486         $this->record = (array) $record;
00487     }
00488 
00489     /**
00490      * Returns the database record array
00491      *
00492      * @return array
00493      */
00494     public function getRecord() {
00495         return $this->record;
00496     }
00497 
00498     /**
00499      * Sets the context info
00500      *
00501      * @param array $contextInfo
00502      * @return void
00503      */
00504     public function setContextInfo($contextInfo) {
00505         $this->contextInfo = (array) $contextInfo;
00506     }
00507 
00508     /**
00509      * Returns the context info
00510      *
00511      * @return array
00512      */
00513     public function getContextInfo() {
00514         return (array) $this->contextInfo;
00515     }
00516 
00517     /**
00518      * Sets the child nodes collection
00519      *
00520      * @param t3lib_tree_NodeCollection $childNodes
00521      * @return void
00522      */
00523     public function setChildNodes(t3lib_tree_NodeCollection $childNodes) {
00524         parent::setChildNodes($childNodes);
00525 
00526         if ($childNodes->count()) {
00527             $this->setLeaf(FALSE);
00528         }
00529     }
00530 
00531     /**
00532      * Sets the indicator if the node can have child nodes
00533      *
00534      * @param boolean $allowChildren
00535      * @return void
00536      */
00537     public function setAllowChildren($allowChildren) {
00538         $this->allowChildren = ($allowChildren == TRUE);
00539     }
00540 
00541     /**
00542      * Checks if the node can have child nodes
00543      *
00544      * @return bool
00545      */
00546     public function canHaveChildren() {
00547         return $this->allowChildren;
00548     }
00549 
00550     /**
00551      * Returns the node in an array representation that can be used for serialization
00552      *
00553      * @return array
00554      */
00555     public function toArray() {
00556         $arrayRepresentation = array(
00557             'serializeClassName' => get_class($this),
00558             'id' => $this->getId(),
00559             'type' => $this->getType(),
00560             'editableText' => $this->getEditableText(),
00561             'text' => $this->getPrefix() . $this->getText() . $this->getSuffix(),
00562             'cls' => $this->getCls(),
00563             'prefix' => $this->getPrefix(),
00564             'suffix' => $this->getSuffix(),
00565             'qtip' => $this->getQTip(),
00566             'expanded' => $this->isExpanded(),
00567             'expandable' => $this->isExpandable(),
00568             'draggable' => $this->isDraggable(),
00569             'isTarget' => $this->isDropTarget(),
00570             'spriteIconCode' => $this->getSpriteIconCode(),
00571             't3TextSourceField' => $this->getTextSourceField(),
00572             't3InCopyMode' => $this->isInCopyMode(),
00573             't3InCutMode' => $this->isInCutMode(),
00574             't3ContextInfo' => $this->getContextInfo(),
00575             'editable' => $this->isLabelEditable(),
00576             'allowChildren' => $this->canHaveChildren(),
00577         );
00578 
00579             // only set the leaf attribute if the node has children's,
00580             // otherwise you cannot add child's to real leaf nodes
00581         if (!$this->isLeafNode()) {
00582             $arrayRepresentation['leaf'] = FALSE;
00583         }
00584 
00585             // Suhosin(?) or some other strange environment thingy prevents
00586             // the direct copy of an array into an index of the same array
00587         $copy = $arrayRepresentation;
00588         $arrayRepresentation['nodeData'] = $copy;
00589 
00590         if ($this->hasChildNodes()) {
00591             $arrayRepresentation['children'] = $this->childNodes->toArray();
00592         }
00593 
00594         return $arrayRepresentation;
00595     }
00596 
00597     /**
00598      * Sets data of the node by a given data array
00599      *
00600      * @param array $data
00601      * @return void
00602      */
00603     public function dataFromArray($data) {
00604         parent::dataFromArray($data);
00605 
00606         $this->setType($data['type']);
00607         $this->setText($data['label'], $data['t3TextSourceField'], $data['prefix'], $data['suffix']);
00608         $this->setEditableText($data['editableText']);
00609         $this->setCls($data['cls']);
00610         $this->setQTip($data['qtip']);
00611         $this->setExpanded($data['expanded']);
00612         $this->setExpandable($data['expandable']);
00613         $this->setDraggable($data['draggable']);
00614         $this->setIsDropTarget($data['isTarget']);
00615         $this->setSpriteIconCode($data['spriteIconCode']);
00616         $this->setInCopyMode($data['t3InCopyMode']);
00617         $this->setInCutMode($data['t3InCutMode']);
00618         $this->setContextInfo($data['t3ContextInfo']);
00619         $this->setLabelIsEditable($data['editable']);
00620         $this->setAllowChildren($data['allowChildren']);
00621 
00622             // only set the leaf attribute if it's applied
00623             // otherwise you cannot insert nodes into this one
00624         if (isset($data['leaf'])) {
00625             $this->setLeaf(FALSE);
00626         }
00627     }
00628 }
00629 
00630 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/extdirect/class.t3lib_tree_extdirect_node.php'])) {
00631     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/extdirect/class.t3lib_tree_extdirect_node.php']);
00632 }
00633 
00634 ?>