2 /***************************************************************
5 * (c) 2010-2011 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Node designated for the page tree
31 * @author Stefan Galinski <stefan.galinski@gmail.com>
35 class t3lib_tree_pagetree_Node
extends t3lib_tree_extdirect_Node
{
37 * Cached access rights to save some performance
41 protected $cachedAccessRights = array();
44 * Workspace Overlay Id
48 protected $workspaceId = 0;
55 protected $mountPoint = 0;
62 protected $readableRootline = '';
65 * Indicator if the node is a mount point
69 protected $isMountPoint = FALSE;
72 * Set's the original id of the element
74 * @param int $workspaceId
77 public function setWorkspaceId($workspaceId) {
78 $this->workspaceId
= intval($workspaceId);
82 * Returns the original id of the element
86 public function getWorkspaceId() {
87 return $this->workspaceId
;
91 * Sets the mount point id
93 * @param int $mountPoint
96 public function setMountPoint($mountPoint) {
97 $this->mountPoint
= intval($mountPoint);
101 * Returns the mount point id
105 public function getMountPoint() {
106 return $this->mountPoint
;
110 * Sets the indicator if the node is a mount point
112 * @param boolean $isMountPoint
115 public function setIsMountPoint($isMountPoint) {
116 $this->isMountPoint
= ($isMountPoint == TRUE);
120 * Returns TRUE if the node is a mount point
124 public function isMountPoint() {
125 return $this->isMountPoint
;
129 * Sets the readable rootline
131 * @param string $rootline
134 public function setReadableRootline($rootline) {
135 $this->readableRootline
= $rootline;
139 * Returns the readable rootline
143 public function getReadableRootline() {
144 return $this->readableRootline
;
148 * Checks if the user may create pages below the given page
152 protected function canCreate() {
153 if (!isset($this->cachedAccessRights
['create'])) {
154 $this->cachedAccessRights
['create'] =
155 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record
, 8);
158 return $this->cachedAccessRights
['create'];
162 * Checks if the user has editing rights
166 protected function canEdit() {
167 if (!isset($this->cachedAccessRights
['edit'])) {
168 $this->cachedAccessRights
['edit'] =
169 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record
, 2);
172 return $this->cachedAccessRights
['edit'];
176 * Checks if the user has the right to delete the page
180 protected function canRemove() {
181 if (!isset($this->cachedAccessRights
['remove'])) {
182 $this->cachedAccessRights
['remove'] =
183 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record
, 4);
185 if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc
['recursiveDelete']) {
186 $this->cachedAccessRights
['remove'] = FALSE;
190 return $this->cachedAccessRights
['remove'];
194 * Checks if the page can be disabled
198 public function canBeDisabledAndEnabled() {
199 return $this->canEdit($this->record
);
203 * Checks if the page is allowed to can be cut
207 public function canBeCut() {
208 return $this->canEdit($this->record
) && intval($this->record
['t3ver_state']) !== 2;
212 * Checks if the page is allowed to be edited
216 public function canBeEdited() {
217 return $this->canEdit($this->record
);
221 * Checks if the page is allowed to be copied
225 public function canBeCopied() {
226 return $this->canCreate($this->record
) && intval($this->record
['t3ver_state']) !== 2;
230 * Checks if there can be new pages created
234 public function canCreateNewPages() {
235 return $this->canCreate($this->record
);
239 * Checks if the page is allowed to be removed
243 public function canBeRemoved() {
244 return $this->canRemove($this->record
) && intval($this->record
['t3ver_state']) !== 2;
248 * Checks if something can be pasted into the node
252 public function canBePastedInto() {
253 return intval($this->record
['t3ver_state']) !== 2;
257 * Checks if something can be pasted after the node
261 public function canBePastedAfter() {
262 return intval($this->record
['t3ver_state']) !== 2;
266 * Checks if the page is allowed to show history
270 public function canShowHistory() {
275 * Checks if the page is allowed to be viewed
279 public function canBeViewed() {
284 * Checks if the page is allowed to show info
288 public function canShowInfo() {
293 * Checks if the page is allowed to be a temporary mount point
297 public function canBeTemporaryMountPoint() {
302 * Returns the node in an array representation that can be used for serialization
306 public function toArray() {
307 $arrayRepresentation = parent
::toArray();
309 $arrayRepresentation['id'] = 'p' . dechex($this->getId()) . ($this->getMountPoint() ?
'-' . dechex($this->getMountPoint()) : '');
310 $arrayRepresentation['realId'] = $this->getId();
311 $arrayRepresentation['nodeData']['id'] = $this->getId();
313 $arrayRepresentation['readableRootline'] = $this->getReadableRootline();
314 $arrayRepresentation['nodeData']['readableRootline'] = $this->getReadableRootline();
316 $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
317 $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
318 $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
319 $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
321 return $arrayRepresentation;
325 * Sets data of the node by a given data array
330 public function dataFromArray($data) {
331 parent
::dataFromArray($data);
332 $this->setWorkspaceId($data['workspaceId']);
333 $this->setMountPoint($data['mountPoint']);
334 $this->setReadableRootline($data['readableRootline']);
335 $this->setIsMountPoint($data['isMountPoint']);
339 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_node.php'])) {
340 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_node.php']);