TYPO3  7.6
PagetreeNode.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
23 {
29  protected $cachedAccessRights = array();
30 
36  protected $workspaceId = 0;
37 
43  protected $mountPoint = 0;
44 
50  protected $readableRootline = '';
51 
57  protected $isMountPoint = false;
58 
64  protected $backgroundColor = '';
65 
73  {
74  $this->backgroundColor = $backgroundColor;
75  }
76 
82  public function getBackgroundColor()
83  {
85  }
86 
93  public function setWorkspaceId($workspaceId)
94  {
95  $this->workspaceId = (int)$workspaceId;
96  }
97 
103  public function getWorkspaceId()
104  {
105  return $this->workspaceId;
106  }
107 
114  public function setMountPoint($mountPoint)
115  {
116  $this->mountPoint = (int)$mountPoint;
117  }
118 
124  public function getMountPoint()
125  {
126  return $this->mountPoint;
127  }
128 
136  {
137  $this->isMountPoint = $isMountPoint == true;
138  }
139 
145  public function isMountPoint()
146  {
147  return $this->isMountPoint;
148  }
149 
156  public function setReadableRootline($rootline)
157  {
158  $this->readableRootline = $rootline;
159  }
160 
166  public function getReadableRootline()
167  {
169  }
170 
176  protected function canCreate()
177  {
178  if (!isset($this->cachedAccessRights['create'])) {
179  $this->cachedAccessRights['create'] = $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 8);
180  }
181  return $this->cachedAccessRights['create'];
182  }
183 
189  protected function canEdit()
190  {
191  if (!isset($this->cachedAccessRights['edit'])) {
192  $this->cachedAccessRights['edit'] =
193  $GLOBALS['BE_USER']->isAdmin()
194  || (
195  (int)$this->record['editlock'] === 0
196  && $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 2)
197  );
198  }
199  return $this->cachedAccessRights['edit'];
200  }
201 
207  protected function canRemove()
208  {
209  if (!isset($this->cachedAccessRights['remove'])) {
210  $this->cachedAccessRights['remove'] =
211  $GLOBALS['BE_USER']->isAdmin()
212  || (
213  (int)$this->record['editlock'] === 0
214  && $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 4)
215  );
216  if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc['recursiveDelete']) {
217  $this->cachedAccessRights['remove'] = false;
218  }
219  }
220  return $this->cachedAccessRights['remove'];
221  }
222 
228  public function canBeDisabledAndEnabled()
229  {
230  return $this->canEdit($this->record) && $GLOBALS['BE_USER']->checkLanguageAccess(0);
231  }
232 
238  public function canBeCut()
239  {
240  return (
241  $this->canEdit($this->record)
242  && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
243  && $GLOBALS['BE_USER']->checkLanguageAccess(0)
244  );
245  }
246 
252  public function canBeEdited()
253  {
254  return $this->canEdit($this->record) && $GLOBALS['BE_USER']->checkLanguageAccess(0);
255  }
256 
262  public function canBeCopied()
263  {
264  return (
265  $this->canCreate($this->record)
266  && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
267  && $GLOBALS['BE_USER']->checkLanguageAccess(0)
268  );
269  }
270 
276  public function canCreateNewPages()
277  {
278  return $this->canCreate($this->record) && $GLOBALS['BE_USER']->checkLanguageAccess(0);
279  }
280 
286  public function canBeRemoved()
287  {
288  return (
289  $this->canRemove($this->record)
290  && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
291  && $GLOBALS['BE_USER']->checkLanguageAccess(0)
292  );
293  }
294 
300  public function canBePastedInto()
301  {
302  return (
303  $this->canCreate($this->record)
304  && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
305  && $GLOBALS['BE_USER']->checkLanguageAccess(0)
306  );
307  }
308 
314  public function canBePastedAfter()
315  {
316  return (
317  $this->canCreate($this->record)
318  && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
319  && $GLOBALS['BE_USER']->checkLanguageAccess(0)
320  );
321  }
322 
328  public function canShowHistory()
329  {
330  return $GLOBALS['BE_USER']->checkLanguageAccess(0);
331  }
332 
338  public function canBeViewed()
339  {
340  return !$this->isDeleted();
341  }
342 
348  public function canShowInfo()
349  {
350  return true;
351  }
352 
358  public function canBeTemporaryMountPoint()
359  {
360  return true;
361  }
362 
368  public function isDeleted()
369  {
370  return (
371  !empty($this->record['deleted'])
372  || VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
373  );
374  }
375 
382  public function calculateNodeId($prefix = 'p')
383  {
384  return $prefix . dechex($this->getId()) . ($this->getMountPoint() ? '-' . dechex($this->getMountPoint()) : '');
385  }
386 
393  public function toArray($addChildNodes = true)
394  {
395  $arrayRepresentation = parent::toArray();
396  $arrayRepresentation['id'] = $this->calculateNodeId();
397  $arrayRepresentation['realId'] = $this->getId();
398  $arrayRepresentation['nodeData']['id'] = $this->getId();
399  $arrayRepresentation['readableRootline'] = $this->getReadableRootline();
400  $arrayRepresentation['nodeData']['readableRootline'] = $this->getReadableRootline();
401  $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
402  $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
403  $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
404  $arrayRepresentation['nodeData']['backgroundColor'] = htmlspecialchars($this->getBackgroundColor());
405  $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
406  return $arrayRepresentation;
407  }
408 
415  public function dataFromArray($data)
416  {
417  parent::dataFromArray($data);
418  $this->setWorkspaceId($data['workspaceId']);
419  $this->setMountPoint($data['mountPoint']);
420  $this->setReadableRootline($data['readableRootline']);
421  $this->setIsMountPoint($data['isMountPoint']);
422  $this->setBackgroundColor($data['backgroundColor']);
423  }
424 }