class.t3lib_tree_pagetree_node.php

Alexander Wende, 2012-04-18 14:56

Download (7.67 KB)

 
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 int
47
         */
48
        protected $workspaceId = 0;
49

    
50
        /**
51
         * Mount Point Id
52
         *
53
         * @var int
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 bool
68
         */
69
        protected $isMountPoint = FALSE;
70

    
71
        /**
72
         * Set's the original id of the element
73
         *
74
         * @param int $workspaceId
75
         * @return void
76
         */
77
        public function setWorkspaceId($workspaceId) {
78
                $this->workspaceId = intval($workspaceId);
79
        }
80

    
81
        /**
82
         * Returns the original id of the element
83
         *
84
         * @return int
85
         */
86
        public function getWorkspaceId() {
87
                return $this->workspaceId;
88
        }
89

    
90
        /**
91
         * Sets the mount point id
92
         *
93
         * @param int $mountPoint
94
         * @return void
95
         */
96
        public function setMountPoint($mountPoint) {
97
                $this->mountPoint = intval($mountPoint);
98
        }
99

    
100
        /**
101
         * Returns the mount point id
102
         *
103
         * @return int
104
         */
105
        public function getMountPoint() {
106
                return $this->mountPoint;
107
        }
108

    
109
        /**
110
         * Sets the indicator if the node is a mount point
111
         *
112
         * @param boolean $isMountPoint
113
         * @return void
114
         */
115
        public function setIsMountPoint($isMountPoint) {
116
                $this->isMountPoint = ($isMountPoint == TRUE);
117
        }
118

    
119
        /**
120
         * Returns true if the node is a mount point
121
         *
122
         * @return bool
123
         */
124
        public function isMountPoint() {
125
                return $this->isMountPoint;
126
        }
127

    
128
        /**
129
         * Sets the readable rootline
130
         *
131
         * @param string $rootline
132
         * @return void
133
         */
134
        public function setReadableRootline($rootline) {
135
                $this->readableRootline = $rootline;
136
        }
137

    
138
        /**
139
         * Returns the readable rootline
140
         *
141
         * @return string
142
         */
143
        public function getReadableRootline() {
144
                return $this->readableRootline;
145
        }
146

    
147
        /**
148
         * Checks if the user may create pages below the given page
149
         *
150
         * @return void
151
         */
152
        protected function canCreate() {
153
                if (!isset($this->cachedAccessRights['create'])) {
154
                        $this->cachedAccessRights['create'] =
155
                                $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 8);
156
                }
157

    
158
                return $this->cachedAccessRights['create'];
159
        }
160

    
161
        /**
162
         * Checks if the user has editing rights
163
         *
164
         * @return void
165
         */
166
        protected function canEdit() {
167
                if (!isset($this->cachedAccessRights['edit'])) {
168
                        $this->cachedAccessRights['edit'] =
169
                                $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 2);
170
                }
171

    
172
                return $this->cachedAccessRights['edit'];
173
        }
174

    
175
        /**
176
         * Checks if the user has the right to delete the page
177
         *
178
         * @return void
179
         */
180
        protected function canRemove()        {
181
                if (!isset($this->cachedAccessRights['remove'])) {
182
                        $this->cachedAccessRights['remove'] =
183
                                $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 4);
184

    
185
                        if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc['recursiveDelete']) {
186
                                $this->cachedAccessRights['remove'] = FALSE;
187
                        }
188
                }
189

    
190
                return $this->cachedAccessRights['remove'];
191
        }
192

    
193
        /**
194
         * Checks if the page can be disabled
195
         *
196
         * @return void
197
         */
198
        public function canBeDisabledAndEnabled() {
199
                return $this->canEdit($this->record);
200
        }
201

    
202
        /**
203
         * Checks if the page is allowed to can be cut
204
         *
205
         * @return void
206
         */
207
        public function canBeCut() {
208
                return $this->canEdit($this->record) && intval($this->record['t3ver_state']) !== 2;
209
        }
210

    
211
        /**
212
         * Checks if the page is allowed to be edited
213
         *
214
         * @return void
215
         */
216
        public function canBeEdited() {
217
                return $this->canEdit($this->record);
218
        }
219

    
220
        /**
221
         * Checks if the page is allowed to be copied
222
         *
223
         * @return void
224
         */
225
        public function canBeCopied() {
226
                return $this->canCreate($this->record) && intval($this->record['t3ver_state']) !== 2;
227
        }
228

    
229
        /**
230
         * Checks if there can be new pages created
231
         *
232
         * @return void
233
         */
234
        public function canCreateNewPages() {
235
                return $this->canCreate($this->record);
236
        }
237

    
238
        /**
239
         * Checks if the page is allowed to be removed
240
         *
241
         * @return void
242
         */
243
        public function canBeRemoved() {
244
                return $this->canRemove($this->record) && intval($this->record['t3ver_state']) !== 2;
245
        }
246

    
247
        /**
248
         * Checks if something can be pasted into the node
249
         *
250
         * @return bool
251
         */
252
        public function canBePastedInto() {
253
                return intval($this->record['t3ver_state']) !== 2;
254
        }
255

    
256
        /**
257
         * Checks if something can be pasted after the node
258
         *
259
         * @return bool
260
         */
261
        public function canBePastedAfter() {
262
                return intval($this->record['t3ver_state']) !== 2;
263
        }
264

    
265
        /**
266
         * Checks if the page is allowed to show history
267
         *
268
         * @return void
269
         */
270
        public function canShowHistory() {
271
                return TRUE;
272
        }
273

    
274
        /**
275
         * Checks if the page is allowed to be viewed
276
         *
277
         * @return void
278
         */
279
        public function canBeViewed() {
280
                return TRUE;
281
        }
282

    
283
        /**
284
         * Checks if the page is allowed to show info
285
         *
286
         * @return void
287
         */
288
        public function canShowInfo() {
289
                return TRUE;
290
        }
291

    
292
        /**
293
         * Checks if the page is allowed to be a temporary mount point
294
         *
295
         * @return void
296
         */
297
        public function canBeTemporaryMountPoint() {
298
                return TRUE;
299
        }
300

    
301
        /**
302
         * Returns the node in an array representation that can be used for serialization
303
         *
304
         * @return array
305
         */
306
        public function toArray() {
307
                $arrayRepresentation = parent::toArray();
308

    
309
                $arrayRepresentation['id'] = 'p' . dechex($this->getId()) . ($this->getMountPoint() ? '-' . dechex($this->getMountPoint()) : '');
310
                $arrayRepresentation['realId'] = $this->getId();
311
                $arrayRepresentation['nodeData']['id'] = $this->getId();
312

    
313
                $arrayRepresentation['readableRootline'] = $this->getReadableRootline();
314
                $arrayRepresentation['nodeData']['readableRootline'] = $this->getReadableRootline();
315

    
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);
320

    
321
                return $arrayRepresentation;
322
        }
323

    
324
        /**
325
         * Sets data of the node by a given data array
326
         *
327
         * @param array $data
328
         * @return void
329
         */
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']);
336
        }
337
}
338

    
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']);
341
}
342

    
343
?>