‪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;
25 
32 {
37  protected ‪$expandAll = false;
38 
43  public ‪$bank = 0;
44 
45  public function ‪__construct()
46  {
47  parent::__construct();
48  $this->‪init();
49  }
50 
58  public function ‪init(‪$clause = '', ‪$orderByFields = '')
59  {
60  parent::init(' AND deleted=0 AND sys_language_uid=0 ' . ‪$clause, ‪$orderByFields ?: 'sorting');
61  }
62 
70  protected function ‪getTitleAttrib($row)
71  {
72  return BackendUtility::titleAttribForPages($row, '1=1 ', false);
73  }
74 
78  protected function ‪PMicon($row, $a, $c, $nextCount, $isOpen)
79  {
80  return '';
81  }
82 
89  public function ‪buildTreeByLevels(int $pid, int $levels): void
90  {
91  $this->expandAll = true;
92  $checkSub = $levels > 0;
93 
94  $this->‪buildTree($pid, $levels, $checkSub);
95  }
96 
104  protected function ‪buildTree(int $pid, int $levels, bool $checkSub): void
105  {
106  $this->‪reset();
107 
108  // Root page
109  if ($pid > 0) {
110  $rootRecord = BackendUtility::getRecordWSOL('pages', $pid);
111  $rootHtml = $this->‪getPageIcon($rootRecord);
112  } else {
113  $rootRecord = [
114  'title' => ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
115  'uid' => 0,
116  ];
117  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
118  $rootHtml = $iconFactory->getIcon('apps-pagetree-root', IconSize::SMALL)->render();
119  }
120 
121  $this->tree[] = [
122  'HTML' => $rootHtml,
123  'row' => $rootRecord,
124  'hasSub' => $checkSub,
125  'bank' => ‪$this->bank,
126  ];
127 
128  // Subtree
129  if ($checkSub) {
130  $this->‪getTree($pid, $levels);
131  }
132 
133  $idH = [];
134  $idH[$pid]['uid'] = $pid;
135  if (!empty($this->buffer_idH)) {
136  $idH[$pid]['subrow'] = ‪$this->buffer_idH;
137  }
138  $this->buffer_idH = $idH;
139 
140  // Check if root page has subtree
141  if (empty($this->buffer_idH)) {
142  $this->tree[0]['hasSub'] = false;
143  }
144  }
145 
152  public function ‪printTree($treeArr = '')
153  {
154  $titleLen = (int)$this->‪getBackendUser()->uc['titleLen'];
155  if (!is_array($treeArr)) {
156  $treeArr = ‪$this->tree;
157  }
158  $out = '';
159  $closeDepth = [];
160  foreach ($treeArr as $treeItem) {
161  if ($treeItem['isFirst'] ?? false) {
162  $out .= '<ul class="treelist">';
163  }
164 
165  $idAttr = htmlspecialchars('pages' . $treeItem['row']['uid']);
166  $out .= '
167  <li id="' . $idAttr . '">
168  <span class="treelist-group">
169  <span class="treelist-icon">' . $treeItem['HTML'] . '</span>
170  <span class="treelist-title">' . $this->‪getTitleStr($treeItem['row'], $titleLen) . '</span>
171  </span>';
172 
173  if (!($treeItem['hasSub'] ?? false)) {
174  $out .= '</li>';
175  }
176 
177  // We have to remember if this is the last one
178  // on level X so the last child on level X+1 closes the <ul>-tag
179  if ($treeItem['isLast'] ?? false) {
180  $closeDepth[$treeItem['invertedDepth']] = 1;
181  }
182  // If this is the last one and does not have subitems, we need to close
183  // the tree as long as the upper levels have last items too
184  if (($treeItem['isLast'] ?? false) && !($treeItem['hasSub'] ?? false)) {
185  for ($i = $treeItem['invertedDepth']; ($closeDepth[$i] ?? 0) == 1; $i++) {
186  $closeDepth[$i] = 0;
187  $out .= '</ul></li>';
188  }
189  }
190  }
191  return '<ul class="treelist treelist-root treelist-root-clean">' . $out . '</ul>';
192  }
193 
203  public function ‪expandNext($id)
204  {
205  return ‪$this->expandAll;
206  }
207 
213  protected function ‪getPageIcon(array $row): string
214  {
215  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
216  return $iconFactory->getIconForRecord($this->table, $row, IconSize::SMALL)->render();
217  }
218 }
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\__construct
‪__construct()
Definition: ExportPageTreeView.php:43
‪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:56
‪TYPO3\CMS\Impexp\View\ExportPageTreeView
Definition: ExportPageTreeView.php:32
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\printTree
‪string printTree($treeArr='')
Definition: ExportPageTreeView.php:150
‪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:36
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\getTitleAttrib
‪string getTitleAttrib($row)
Definition: ExportPageTreeView.php:68
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\buildTree
‪buildTree(int $pid, int $levels, bool $checkSub)
Definition: ExportPageTreeView.php:102
‪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:41
‪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:211
‪$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\View\ExportPageTreeView\expandNext
‪bool expandNext($id)
Definition: ExportPageTreeView.php:201
‪TYPO3\CMS\Impexp\View\ExportPageTreeView\buildTreeByLevels
‪buildTreeByLevels(int $pid, int $levels)
Definition: ExportPageTreeView.php:87
‪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:76
‪TYPO3\CMS\Backend\Tree\View\AbstractTreeView
Definition: AbstractTreeView.php:39
‪TYPO3\CMS\Impexp\View
Definition: ExportPageTreeView.php:18