Merged new PageTree (version for TYPO3 4.5 Beta 3)
[Packages/TYPO3.CMS.git] / typo3 / sysext / pagetree / classes / class.tx_pagetree_node.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 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 tx_pagetree
34 */
35 class tx_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 int
47 */
48 protected $workspaceId = 0;
49
50 /**
51 * Mount Point Id
52 *
53 * @var int
54 */
55 protected $mountPoint = 0;
56
57 /**
58 * Set's the original id of the element
59 *
60 * @param int $workspaceId
61 * @return void
62 */
63 public function setWorkspaceId($workspaceId) {
64 $this->workspaceId = intval($workspaceId);
65 }
66
67 /**
68 * Returns the original id of the element
69 *
70 * @return int
71 */
72 public function getWorkspaceId() {
73 return $this->workspaceId;
74 }
75
76 /**
77 * Sets the mount point id
78 *
79 * @param int $mountPoint
80 * @return void
81 */
82 public function setMountPoint($mountPoint) {
83 $this->mountPoint = $mountPoint;
84 }
85
86 /**
87 * Returns the mount point id
88 *
89 * @return int
90 */
91 public function getMountPoint() {
92 return $this->mountPoint;
93 }
94
95 /**
96 * Checks if the user may create pages below the given page
97 *
98 * @return void
99 */
100 protected function canCreate() {
101 if (!isset($this->cachedAccessRights['create'])) {
102 $this->cachedAccessRights['create'] =
103 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 8);
104 }
105
106 return $this->cachedAccessRights['create'];
107 }
108
109 /**
110 * Checks if the user has editing rights
111 *
112 * @return void
113 */
114 protected function canEdit() {
115 if (!isset($this->cachedAccessRights['edit'])) {
116 $this->cachedAccessRights['edit'] =
117 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 2);
118 }
119
120 return $this->cachedAccessRights['edit'];
121 }
122
123 /**
124 * Checks if the user has the right to delete the page
125 *
126 * @return void
127 */
128 protected function canRemove() {
129 if (!isset($this->cachedAccessRights['remove'])) {
130 $this->cachedAccessRights['remove'] =
131 $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 4);
132
133 if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc['recursiveDelete']) {
134 $this->cachedAccessRights['remove'] = FALSE;
135 }
136 }
137
138 return $this->cachedAccessRights['remove'];
139 }
140
141 /**
142 * Checks if the page can be disabled
143 *
144 * @return void
145 */
146 public function canBeDisabledAndEnabled() {
147 return $this->canEdit($this->record);
148 }
149
150 /**
151 * Checks if the page is allowed to can be cut
152 *
153 * @return void
154 */
155 public function canBeCut() {
156 return $this->canEdit($this->record) && intval($this->record['t3ver_state']) !== 2;
157 }
158
159 /**
160 * Checks if the page is allowed to be edited
161 *
162 * @return void
163 */
164 public function canBeEdited() {
165 return $this->canEdit($this->record);
166 }
167
168 /**
169 * Checks if the page is allowed to be copied
170 *
171 * @return void
172 */
173 public function canBeCopied() {
174 return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
175 }
176
177 /**
178 * Checks if there can be new pages created
179 *
180 * @return void
181 */
182 public function canCreateNewPages() {
183 return $this->canCreate($this->record);
184 }
185
186 /**
187 * Checks if the page is allowed to be removed
188 *
189 * @return void
190 */
191 public function canBeRemoved() {
192 return $this->canRemove($this->record) && intval($this->record['t3ver_state']) !== 2;
193 }
194
195 /**
196 * Checks if something can be pasted into the node
197 *
198 * @return bool
199 */
200 public function canBePastedInto() {
201 return intval($this->record['t3ver_state']) !== 2;
202 }
203
204 /**
205 * Checks if something can be pasted after the node
206 *
207 * @return bool
208 */
209 public function canBePastedAfter() {
210 return intval($this->record['t3ver_state']) !== 2;
211 }
212
213 /**
214 * Checks if the page is allowed to show history
215 *
216 * @return void
217 */
218 public function canShowHistory() {
219 return TRUE;
220 }
221
222 /**
223 * Checks if the page is allowed to be viewed
224 *
225 * @return void
226 */
227 public function canBeViewed() {
228 return TRUE;
229 }
230
231 /**
232 * Checks if the page is allowed to show info
233 *
234 * @return void
235 */
236 public function canShowInfo() {
237 return TRUE;
238 }
239
240 /**
241 * Checks if the page is allowed to be a temporary mount point
242 *
243 * @return void
244 */
245 public function canBeTemporaryMountPoint() {
246 return TRUE;
247 }
248
249 /**
250 * Returns the node in an array representation that can be used for serialization
251 *
252 * @return array
253 */
254 public function toArray() {
255 $arrayRepresentation = parent::toArray();
256
257 $arrayRepresentation['id'] = 'mp-' . $this->getMountPoint() . '-' . $this->getId();
258 $arrayRepresentation['realId'] = $this->getId();
259 $arrayRepresentation['nodeData']['id'] = $this->getId();
260 $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
261 $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
262 $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
263
264 return $arrayRepresentation;
265 }
266
267 /**
268 * Sets data of the node by a given data array
269 *
270 * @param array $data
271 * @return void
272 */
273 public function dataFromArray($data) {
274 parent::dataFromArray($data);
275 $this->setWorkspaceId($data['workspaceId']);
276 $this->setMountPoint($data['mountPoint']);
277 }
278 }
279
280 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/class.tx_pagetree_node.php'])) {
281 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/class.tx_pagetree_node.php']);
282 }
283
284 ?>