7f59e34afcdaa393003142a80a78b86411ea45c3
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / Pagetree / PagetreeNode.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2011 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 designated for the page tree
31 *
32 * @author Stefan Galinski <stefan.galinski@gmail.com>
33 */
34 class PagetreeNode extends \TYPO3\CMS\Backend\Tree\ExtDirectNode {
35
36 /**
37 * Cached access rights to save some performance
38 *
39 * @var array
40 */
41 protected $cachedAccessRights = array();
42
43 /**
44 * Workspace Overlay Id
45 *
46 * @var integer
47 */
48 protected $workspaceId = 0;
49
50 /**
51 * Mount Point Id
52 *
53 * @var integer
54 */
55 protected $mountPoint = 0;
56
57 /**
58 * Readable Rootline
59 *
60 * @var string
61 */
62 protected $readableRootline = '';
63
64 /**
65 * Indicator if the node is a mount point
66 *
67 * @var boolean
68 */
69 protected $isMountPoint = FALSE;
70
71 /**
72 * Background color for the node
73 *
74 * @var string
75 */
76 protected $backgroundColor = '';
77
78 /**
79 * Sets the background color
80 *
81 * @param string $backgroundColor
82 * @return void
83 */
84 public function setBackgroundColor($backgroundColor) {
85 $this->backgroundColor = $backgroundColor;
86 }
87
88 /**
89 * Returns the background color
90 *
91 * @return string
92 */
93 public function getBackgroundColor() {
94 return $this->backgroundColor;
95 }
96
97 /**
98 * Set's the original id of the element
99 *
100 * @param integer $workspaceId
101 * @return void
102 */
103 public function setWorkspaceId($workspaceId) {
104 $this->workspaceId = intval($workspaceId);
105 }
106
107 /**
108 * Returns the original id of the element
109 *
110 * @return integer
111 */
112 public function getWorkspaceId() {
113 return $this->workspaceId;
114 }
115
116 /**
117 * Sets the mount point id
118 *
119 * @param integer $mountPoint
120 * @return void
121 */
122 public function setMountPoint($mountPoint) {
123 $this->mountPoint = intval($mountPoint);
124 }
125
126 /**
127 * Returns the mount point id
128 *
129 * @return integer
130 */
131 public function getMountPoint() {
132 return $this->mountPoint;
133 }
134
135 /**
136 * Sets the indicator if the node is a mount point
137 *
138 * @param boolean $isMountPoint
139 * @return void
140 */
141 public function setIsMountPoint($isMountPoint) {
142 $this->isMountPoint = $isMountPoint == TRUE;
143 }
144
145 /**
146 * Returns TRUE if the node is a mount point
147 *
148 * @return boolean
149 */
150 public function isMountPoint() {
151 return $this->isMountPoint;
152 }
153
154 /**
155 * Sets the readable rootline
156 *
157 * @param string $rootline
158 * @return void
159 */
160 public function setReadableRootline($rootline) {
161 $this->readableRootline = $rootline;
162 }
163
164 /**
165 * Returns the readable rootline
166 *
167 * @return string
168 */
169 public function getReadableRootline() {
170 return $this->readableRootline;
171 }
172
173 /**
174 * Checks if the user may create pages below the given page
175 *
176 * @return boolean
177 */
178 protected function canCreate() {
179 if (!isset($this->cachedAccessRights['create'])) {
180 $this->cachedAccessRights['create'] = $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 8);
181 }
182 return $this->cachedAccessRights['create'];
183 }
184
185 /**
186 * Checks if the user has editing rights
187 *
188 * @return boolean
189 */
190 protected function canEdit() {
191 if (!isset($this->cachedAccessRights['edit'])) {
192 $this->cachedAccessRights['edit'] = $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 2);
193 }
194 return $this->cachedAccessRights['edit'];
195 }
196
197 /**
198 * Checks if the user has the right to delete the page
199 *
200 * @return boolean
201 */
202 protected function canRemove() {
203 if (!isset($this->cachedAccessRights['remove'])) {
204 $this->cachedAccessRights['remove'] = $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 4);
205 if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc['recursiveDelete']) {
206 $this->cachedAccessRights['remove'] = FALSE;
207 }
208 }
209 return $this->cachedAccessRights['remove'];
210 }
211
212 /**
213 * Checks if the page can be disabled
214 *
215 * @return boolean
216 */
217 public function canBeDisabledAndEnabled() {
218 return $this->canEdit($this->record);
219 }
220
221 /**
222 * Checks if the page is allowed to can be cut
223 *
224 * @return boolean
225 */
226 public function canBeCut() {
227 return $this->canEdit($this->record) && intval($this->record['t3ver_state']) !== 2;
228 }
229
230 /**
231 * Checks if the page is allowed to be edited
232 *
233 * @return boolean
234 */
235 public function canBeEdited() {
236 return $this->canEdit($this->record);
237 }
238
239 /**
240 * Checks if the page is allowed to be copied
241 *
242 * @return boolean
243 */
244 public function canBeCopied() {
245 return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
246 }
247
248 /**
249 * Checks if there can be new pages created
250 *
251 * @return boolean
252 */
253 public function canCreateNewPages() {
254 return $this->canCreate($this->record);
255 }
256
257 /**
258 * Checks if the page is allowed to be removed
259 *
260 * @return boolean
261 */
262 public function canBeRemoved() {
263 return $this->canRemove($this->record) && intval($this->record['t3ver_state']) !== 2;
264 }
265
266 /**
267 * Checks if something can be pasted into the node
268 *
269 * @return boolean
270 */
271 public function canBePastedInto() {
272 return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
273 }
274
275 /**
276 * Checks if something can be pasted after the node
277 *
278 * @return boolean
279 */
280 public function canBePastedAfter() {
281 return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
282 }
283
284 /**
285 * Checks if the page is allowed to show history
286 *
287 * @return boolean
288 */
289 public function canShowHistory() {
290 return TRUE;
291 }
292
293 /**
294 * Checks if the page is allowed to be viewed
295 *
296 * @return boolean
297 */
298 public function canBeViewed() {
299 return TRUE;
300 }
301
302 /**
303 * Checks if the page is allowed to show info
304 *
305 * @return boolean
306 */
307 public function canShowInfo() {
308 return TRUE;
309 }
310
311 /**
312 * Checks if the page is allowed to be a temporary mount point
313 *
314 * @return boolean
315 */
316 public function canBeTemporaryMountPoint() {
317 return TRUE;
318 }
319
320 /**
321 * Returns the calculated id representation of this node
322 *
323 * @param string $prefix Defaults to 'p'
324 * @return string
325 */
326 public function calculateNodeId($prefix = 'p') {
327 return $prefix . dechex($this->getId()) . ($this->getMountPoint() ? '-' . dechex($this->getMountPoint()) : '');
328 }
329
330 /**
331 * Returns the node in an array representation that can be used for serialization
332 *
333 * @param boolean $addChildNodes
334 * @return array
335 */
336 public function toArray($addChildNodes = TRUE) {
337 $arrayRepresentation = parent::toArray();
338 $arrayRepresentation['id'] = $this->calculateNodeId();
339 $arrayRepresentation['realId'] = $this->getId();
340 $arrayRepresentation['nodeData']['id'] = $this->getId();
341 $arrayRepresentation['readableRootline'] = $this->getReadableRootline();
342 $arrayRepresentation['nodeData']['readableRootline'] = $this->getReadableRootline();
343 $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
344 $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
345 $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
346 $arrayRepresentation['nodeData']['backgroundColor'] = htmlspecialchars($this->getBackgroundColor());
347 $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
348 return $arrayRepresentation;
349 }
350
351 /**
352 * Sets data of the node by a given data array
353 *
354 * @param array $data
355 * @return void
356 */
357 public function dataFromArray($data) {
358 parent::dataFromArray($data);
359 $this->setWorkspaceId($data['workspaceId']);
360 $this->setMountPoint($data['mountPoint']);
361 $this->setReadableRootline($data['readableRootline']);
362 $this->setIsMountPoint($data['isMountPoint']);
363 $this->setBackgroundColor($data['backgroundColor']);
364 }
365
366 }
367
368
369 ?>