[TASK] Clean up the phpDoc of t3lib/tree/
[Packages/TYPO3.CMS.git] / t3lib / tree / pagetree / class.t3lib_tree_pagetree_node.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 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 t3lib
34 */
35 class t3lib_tree_pagetree_Node extends t3lib_tree_extdirect_Node {
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'] =
181 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 8);
182 }
183
184 return $this->cachedAccessRights['create'];
185 }
186
187 /**
188 * Checks if the user has editing rights
189 *
190 * @return boolean
191 */
192 protected function canEdit() {
193 if (!isset($this->cachedAccessRights['edit'])) {
194 $this->cachedAccessRights['edit'] =
195 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 2);
196 }
197
198 return $this->cachedAccessRights['edit'];
199 }
200
201 /**
202 * Checks if the user has the right to delete the page
203 *
204 * @return boolean
205 */
206 protected function canRemove() {
207 if (!isset($this->cachedAccessRights['remove'])) {
208 $this->cachedAccessRights['remove'] =
209 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 4);
210
211 if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc['recursiveDelete']) {
212 $this->cachedAccessRights['remove'] = FALSE;
213 }
214 }
215
216 return $this->cachedAccessRights['remove'];
217 }
218
219 /**
220 * Checks if the page can be disabled
221 *
222 * @return boolean
223 */
224 public function canBeDisabledAndEnabled() {
225 return $this->canEdit($this->record);
226 }
227
228 /**
229 * Checks if the page is allowed to can be cut
230 *
231 * @return boolean
232 */
233 public function canBeCut() {
234 return $this->canEdit($this->record) && intval($this->record['t3ver_state']) !== 2;
235 }
236
237 /**
238 * Checks if the page is allowed to be edited
239 *
240 * @return boolean
241 */
242 public function canBeEdited() {
243 return $this->canEdit($this->record);
244 }
245
246 /**
247 * Checks if the page is allowed to be copied
248 *
249 * @return boolean
250 */
251 public function canBeCopied() {
252 return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
253 }
254
255 /**
256 * Checks if there can be new pages created
257 *
258 * @return boolean
259 */
260 public function canCreateNewPages() {
261 return $this->canCreate($this->record);
262 }
263
264 /**
265 * Checks if the page is allowed to be removed
266 *
267 * @return boolean
268 */
269 public function canBeRemoved() {
270 return $this->canRemove($this->record) && intval($this->record['t3ver_state']) !== 2;
271 }
272
273 /**
274 * Checks if something can be pasted into the node
275 *
276 * @return boolean
277 */
278 public function canBePastedInto() {
279 return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
280 }
281
282 /**
283 * Checks if something can be pasted after the node
284 *
285 * @return boolean
286 */
287 public function canBePastedAfter() {
288 return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
289 }
290
291 /**
292 * Checks if the page is allowed to show history
293 *
294 * @return boolean
295 */
296 public function canShowHistory() {
297 return TRUE;
298 }
299
300 /**
301 * Checks if the page is allowed to be viewed
302 *
303 * @return boolean
304 */
305 public function canBeViewed() {
306 return TRUE;
307 }
308
309 /**
310 * Checks if the page is allowed to show info
311 *
312 * @return boolean
313 */
314 public function canShowInfo() {
315 return TRUE;
316 }
317
318 /**
319 * Checks if the page is allowed to be a temporary mount point
320 *
321 * @return boolean
322 */
323 public function canBeTemporaryMountPoint() {
324 return TRUE;
325 }
326
327 /**
328 * Returns the calculated id representation of this node
329 *
330 * @param string $prefix Defaults to 'p'
331 * @return string
332 */
333 public function calculateNodeId($prefix = 'p') {
334 return $prefix . dechex($this->getId()) . ($this->getMountPoint() ? '-' . dechex($this->getMountPoint()) : '');
335 }
336
337 /**
338 * Returns the node in an array representation that can be used for serialization
339 *
340 * @param boolean $addChildNodes
341 * @return array
342 */
343 public function toArray($addChildNodes = TRUE) {
344 $arrayRepresentation = parent::toArray();
345
346 $arrayRepresentation['id'] = $this->calculateNodeId();
347 $arrayRepresentation['realId'] = $this->getId();
348 $arrayRepresentation['nodeData']['id'] = $this->getId();
349
350 $arrayRepresentation['readableRootline'] = $this->getReadableRootline();
351 $arrayRepresentation['nodeData']['readableRootline'] = $this->getReadableRootline();
352
353 $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
354 $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
355 $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
356 $arrayRepresentation['nodeData']['backgroundColor'] = htmlspecialchars($this->getBackgroundColor());
357 $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
358
359 return $arrayRepresentation;
360 }
361
362 /**
363 * Sets data of the node by a given data array
364 *
365 * @param array $data
366 * @return void
367 */
368 public function dataFromArray($data) {
369 parent::dataFromArray($data);
370 $this->setWorkspaceId($data['workspaceId']);
371 $this->setMountPoint($data['mountPoint']);
372 $this->setReadableRootline($data['readableRootline']);
373 $this->setIsMountPoint($data['isMountPoint']);
374 $this->setBackgroundColor($data['backgroundColor']);
375 }
376 }
377
378 ?>