‪TYPO3CMS  ‪main
ExportPageTreeView.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\IconSize;
26 
33 {
38  protected ‪$expandAll = false;
39 
44  public ‪$bank = 0;
45 
46  public function ‪__construct()
47  {
48  parent::__construct();
49  $this->‪init();
50  }
51 
59  public function ‪init(‪$clause = '', ‪$orderByFields = '')
60  {
61  parent::init(' AND deleted=0 AND sys_language_uid=0 ' . ‪$clause, ‪$orderByFields ?: 'sorting');
62  }
63 
71  protected function ‪getTitleAttrib($row)
72  {
73  return BackendUtility::titleAttribForPages($row, '1=1 ', false);
74  }
75 
79  protected function ‪PMicon($row, $a, $c, $nextCount, $isOpen)
80  {
81  return '';
82  }
83 
90  public function ‪buildTreeByLevels(int $pid, int $levels): void
91  {
92  $this->expandAll = true;
93  $checkSub = $levels > 0;
94 
95  $this->‪buildTree($pid, $levels, $checkSub);
96  }
97 
105  protected function ‪buildTree(int $pid, int $levels, bool $checkSub): void
106  {
107  $this->‪reset();
108 
109  // Root page
110  if ($pid > 0) {
111  $rootRecord = BackendUtility::getRecordWSOL('pages', $pid);
112  $rootHtml = $this->‪getPageIcon($rootRecord);
113  } else {
114  $rootRecord = [
115  'title' => ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
116  'uid' => 0,
117  ];
118  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
119  $rootHtml = $iconFactory->getIcon('apps-pagetree-root', IconSize::SMALL)->render();
120  }
121 
122  $this->tree[] = [
123  'HTML' => $rootHtml,
124  'row' => $rootRecord,
125  'hasSub' => $checkSub,
126  'bank' => ‪$this->bank,
127  ];
128 
129  // Subtree
130  if ($checkSub) {
131  $this->‪getTree($pid, $levels);
132  }
133 
134  $idH = [];
135  $idH[$pid]['uid'] = $pid;
136  if (!empty($this->buffer_idH)) {
137  $idH[$pid]['subrow'] = ‪$this->buffer_idH;
138  }
139  $this->buffer_idH = $idH;
140 
141  // Check if root page has subtree
142  if (empty($this->buffer_idH)) {
143  $this->tree[0]['hasSub'] = false;
144  }
145  }
146 
153  public function ‪printTree($treeArr = '')
154  {
155  $titleLen = (int)$this->‪getBackendUser()->uc['titleLen'];
156  if (!is_array($treeArr)) {
157  $treeArr = ‪$this->tree;
158  }
159  $out = '';
160  $closeDepth = [];
161  foreach ($treeArr as $treeItem) {
162  if ($treeItem['isFirst'] ?? false) {
163  $out .= '<ul class="treelist">';
164  }
165 
166  $idAttr = htmlspecialchars('pages' . $treeItem['row']['uid']);
167  $out .= '
168  <li id="' . $idAttr . '">
169  <span class="treelist-group">
170  <span class="treelist-icon">' . $treeItem['HTML'] . '</span>
171  <span class="treelist-title">' . $this->‪getTitleStr($treeItem['row'], $titleLen) . '</span>
172  </span>';
173 
174  if (!($treeItem['hasSub'] ?? false)) {
175  $out .= '</li>';
176  }
177 
178  // We have to remember if this is the last one
179  // on level X so the last child on level X+1 closes the <ul>-tag
180  if ($treeItem['isLast'] ?? false) {
181  $closeDepth[$treeItem['invertedDepth']] = 1;
182  }
183  // If this is the last one and does not have subitems, we need to close
184  // the tree as long as the upper levels have last items too
185  if (($treeItem['isLast'] ?? false) && !($treeItem['hasSub'] ?? false)) {
186  for ($i = $treeItem['invertedDepth']; ($closeDepth[$i] ?? 0) == 1; $i++) {
187  $closeDepth[$i] = 0;
188  $out .= '</ul></li>';
189  }
190  }
191  }
192  return '<ul class="treelist treelist-root treelist-root-clean">' . $out . '</ul>';
193  }
194 
204  public function ‪expandNext($id)
205  {
206  return ‪$this->expandAll;
207  }
208 
214  protected function ‪getPageIcon(array $row): string
215  {
216  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
217  return $iconFactory->getIconForRecord($this->table, $row, IconSize::SMALL)->render();
218  }
219 }
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\__construct
‪__construct()
Definition: ExportPageTreeView.php:44
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\$clause
‪string $clause
Definition: AbstractTreeView.php:56
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\init
‪init($clause='', $orderByFields='')
Definition: ExportPageTreeView.php:57
‪TYPO3\CMS\Impexp\View\ExportPageTreeView
Definition: ExportPageTreeView.php:33
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\printTree
‪string printTree($treeArr='')
Definition: ExportPageTreeView.php:151
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\$buffer_idH
‪array $buffer_idH
Definition: AbstractTreeView.php:126
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\$expandAll
‪bool $expandAll
Definition: ExportPageTreeView.php:37
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\getTitleAttrib
‪string getTitleAttrib($row)
Definition: ExportPageTreeView.php:69
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\buildTree
‪buildTree(int $pid, int $levels, bool $checkSub)
Definition: ExportPageTreeView.php:103
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\reset
‪reset()
Definition: AbstractTreeView.php:175
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\$tree
‪array $tree
Definition: AbstractTreeView.php:132
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\$bank
‪int $bank
Definition: ExportPageTreeView.php:42
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\$orderByFields
‪string $orderByFields
Definition: AbstractTreeView.php:63
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\getPageIcon
‪string getPageIcon(array $row)
Definition: ExportPageTreeView.php:212
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getTree
‪int getTree($uid, $depth=999, $depthData='')
Definition: AbstractTreeView.php:309
‪TYPO3\CMS\Impexp\Export
Definition: Export.php:52
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\expandNext
‪bool expandNext($id)
Definition: ExportPageTreeView.php:202
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\buildTreeByLevels
‪buildTreeByLevels(int $pid, int $levels)
Definition: ExportPageTreeView.php:88
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getBackendUser
‪getBackendUser()
Definition: AbstractTreeView.php:476
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getTitleStr
‪string getTitleStr($row, $titleLen=30)
Definition: AbstractTreeView.php:279
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\PMicon
‪PMicon($row, $a, $c, $nextCount, $isOpen)
Definition: ExportPageTreeView.php:77
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView
Definition: AbstractTreeView.php:39
‪TYPO3\CMS\Impexp\View
Definition: ExportPageTreeView.php:18