TYPO3 API  SVNRelease
class.t3lib_tree_pagetree_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 designated for the page tree
00030  *
00031  * @author Stefan Galinski <stefan.galinski@gmail.com>
00032  * @package TYPO3
00033  * @subpackage t3lib
00034  */
00035 class t3lib_tree_pagetree_Node extends t3lib_tree_extdirect_Node {
00036     /**
00037      * Cached access rights to save some performance
00038      *
00039      * @var array
00040      */
00041     protected $cachedAccessRights = array();
00042 
00043     /**
00044      * Workspace Overlay Id
00045      *
00046      * @var int
00047      */
00048     protected $workspaceId = 0;
00049 
00050     /**
00051      * Mount Point Id
00052      *
00053      * @var int
00054      */
00055     protected $mountPoint = 0;
00056 
00057     /**
00058      * Readable Rootline
00059      *
00060      * @var string
00061      */
00062     protected $readableRootline = '';
00063 
00064     /**
00065      * Indicator if the node is a mount point
00066      *
00067      * @var bool
00068      */
00069     protected $isMountPoint = FALSE;
00070 
00071     /**
00072      * Set's the original id of the element
00073      *
00074      * @param int $workspaceId
00075      * @return void
00076      */
00077     public function setWorkspaceId($workspaceId) {
00078         $this->workspaceId = intval($workspaceId);
00079     }
00080 
00081     /**
00082      * Returns the original id of the element
00083      *
00084      * @return int
00085      */
00086     public function getWorkspaceId() {
00087         return $this->workspaceId;
00088     }
00089 
00090     /**
00091      * Sets the mount point id
00092      *
00093      * @param int $mountPoint
00094      * @return void
00095      */
00096     public function setMountPoint($mountPoint) {
00097         $this->mountPoint = intval($mountPoint);
00098     }
00099 
00100     /**
00101      * Returns the mount point id
00102      *
00103      * @return int
00104      */
00105     public function getMountPoint() {
00106         return $this->mountPoint;
00107     }
00108 
00109     /**
00110      * Sets the indicator if the node is a mount point
00111      *
00112      * @param boolean $isMountPoint
00113      * @return void
00114      */
00115     public function setIsMountPoint($isMountPoint) {
00116         $this->isMountPoint = ($isMountPoint == TRUE);
00117     }
00118 
00119     /**
00120      * Returns true if the node is a mount point
00121      *
00122      * @return bool
00123      */
00124     public function isMountPoint() {
00125         return $this->isMountPoint;
00126     }
00127 
00128     /**
00129      * Sets the readable rootline
00130      *
00131      * @param string $rootline
00132      * @return void
00133      */
00134     public function setReadableRootline($rootline) {
00135         $this->readableRootline = $rootline;
00136     }
00137 
00138     /**
00139      * Returns the readable rootline
00140      *
00141      * @return string
00142      */
00143     public function getReadableRootline() {
00144         return $this->readableRootline;
00145     }
00146 
00147     /**
00148      * Checks if the user may create pages below the given page
00149      *
00150      * @return void
00151      */
00152     protected function canCreate() {
00153         if (!isset($this->cachedAccessRights['create'])) {
00154             $this->cachedAccessRights['create'] =
00155                 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 8);
00156         }
00157 
00158         return $this->cachedAccessRights['create'];
00159     }
00160 
00161     /**
00162      * Checks if the user has editing rights
00163      *
00164      * @return void
00165      */
00166     protected function canEdit() {
00167         if (!isset($this->cachedAccessRights['edit'])) {
00168             $this->cachedAccessRights['edit'] =
00169                 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 2);
00170         }
00171 
00172         return $this->cachedAccessRights['edit'];
00173     }
00174 
00175     /**
00176      * Checks if the user has the right to delete the page
00177      *
00178      * @return void
00179      */
00180     protected function canRemove()  {
00181         if (!isset($this->cachedAccessRights['remove'])) {
00182             $this->cachedAccessRights['remove'] =
00183                 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 4);
00184 
00185             if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc['recursiveDelete']) {
00186                 $this->cachedAccessRights['remove'] = FALSE;
00187             }
00188         }
00189 
00190         return $this->cachedAccessRights['remove'];
00191     }
00192 
00193     /**
00194      * Checks if the page can be disabled
00195      *
00196      * @return void
00197      */
00198     public function canBeDisabledAndEnabled() {
00199         return $this->canEdit($this->record);
00200     }
00201 
00202     /**
00203      * Checks if the page is allowed to can be cut
00204      *
00205      * @return void
00206      */
00207     public function canBeCut() {
00208         return $this->canEdit($this->record) && intval($this->record['t3ver_state']) !== 2;
00209     }
00210 
00211     /**
00212      * Checks if the page is allowed to be edited
00213      *
00214      * @return void
00215      */
00216     public function canBeEdited() {
00217         return $this->canEdit($this->record);
00218     }
00219 
00220     /**
00221      * Checks if the page is allowed to be copied
00222      *
00223      * @return void
00224      */
00225     public function canBeCopied() {
00226         return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
00227     }
00228 
00229     /**
00230      * Checks if there can be new pages created
00231      *
00232      * @return void
00233      */
00234     public function canCreateNewPages() {
00235         return $this->canCreate($this->record);
00236     }
00237 
00238     /**
00239      * Checks if the page is allowed to be removed
00240      *
00241      * @return void
00242      */
00243     public function canBeRemoved() {
00244         return $this->canRemove($this->record) && intval($this->record['t3ver_state']) !== 2;
00245     }
00246 
00247     /**
00248      * Checks if something can be pasted into the node
00249      *
00250      * @return bool
00251      */
00252     public function canBePastedInto() {
00253         return intval($this->record['t3ver_state']) !== 2;
00254     }
00255 
00256     /**
00257      * Checks if something can be pasted after the node
00258      *
00259      * @return bool
00260      */
00261     public function canBePastedAfter() {
00262         return intval($this->record['t3ver_state']) !== 2;
00263     }
00264 
00265     /**
00266      * Checks if the page is allowed to show history
00267      *
00268      * @return void
00269      */
00270     public function canShowHistory() {
00271         return TRUE;
00272     }
00273 
00274     /**
00275      * Checks if the page is allowed to be viewed
00276      *
00277      * @return void
00278      */
00279     public function canBeViewed() {
00280         return TRUE;
00281     }
00282 
00283     /**
00284      * Checks if the page is allowed to show info
00285      *
00286      * @return void
00287      */
00288     public function canShowInfo() {
00289         return TRUE;
00290     }
00291 
00292     /**
00293      * Checks if the page is allowed to be a temporary mount point
00294      *
00295      * @return void
00296      */
00297     public function canBeTemporaryMountPoint() {
00298         return TRUE;
00299     }
00300 
00301     /**
00302      * Returns the node in an array representation that can be used for serialization
00303      *
00304      * @return array
00305      */
00306     public function toArray() {
00307         $arrayRepresentation = parent::toArray();
00308 
00309         $arrayRepresentation['id'] = 'mp-' . $this->getMountPoint() . '-' . $this->getId();
00310         $arrayRepresentation['realId'] = $this->getId();
00311         $arrayRepresentation['nodeData']['id'] = $this->getId();
00312 
00313         $arrayRepresentation['readableRootline'] = $this->getReadableRootline();
00314         $arrayRepresentation['nodeData']['readableRootline'] = $this->getReadableRootline();
00315 
00316         $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
00317         $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
00318         $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
00319         $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
00320 
00321         return $arrayRepresentation;
00322     }
00323 
00324     /**
00325      * Sets data of the node by a given data array
00326      *
00327      * @param array $data
00328      * @return void
00329      */
00330     public function dataFromArray($data) {
00331         parent::dataFromArray($data);
00332         $this->setWorkspaceId($data['workspaceId']);
00333         $this->setMountPoint($data['mountPoint']);
00334         $this->setReadableRootline($data['readableRootline']);
00335         $this->setIsMountPoint($data['isMountPoint']);
00336     }
00337 }
00338 
00339 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_node.php'])) {
00340     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_node.php']);
00341 }
00342 
00343 ?>