‪TYPO3CMS  9.5
AbstractRecordList.php
Go to the documentation of this file.
1 <?php
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 
26 
35 abstract class ‪AbstractRecordList
36 {
41  protected ‪$id = 0;
42 
49  public ‪$iLimit = 10;
50 
57  public ‪$leftMargin = 0;
58 
63  public ‪$showIcon = 1;
64 
69  public ‪$no_noWrap = 0;
70 
77  public ‪$oddColumnsCssClass = '';
78 
85  public ‪$fieldArray = [];
86 
93  public ‪$addElement_tdParams = [];
94 
101  public ‪$addElement_tdCssClass = [];
102 
110  public ‪$fixedL = 30;
111 
118  public ‪$thisScript = '';
119 
126  public ‪$setLMargin = 1;
127 
134  public ‪$counter = 0;
135 
142  public ‪$totalItems = '';
143 
150  public ‪$firstElementNumber = 0;
151 
156  public ‪$eCounter = 0;
157 
164  public ‪$HTMLcode = '';
165 
172  public ‪$pageOverlays = [];
173 
180  public ‪$languageIconTitles = [];
181 
186  public ‪$translateTools;
187 
192  protected ‪$iconFactory;
193 
198  public function ‪__construct()
199  {
200  trigger_error('The class AbstractRecordList will be removed in TYPO3 v10.0, as all logic was moved into specific classes that inherited from AbstractRecordList.', E_USER_DEPRECATED);
201  if (isset(‪$GLOBALS['BE_USER']->uc['titleLen']) && ‪$GLOBALS['BE_USER']->uc['titleLen'] > 0) {
202  $this->fixedL = ‪$GLOBALS['BE_USER']->uc['titleLen'];
203  }
204  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
205  $this->‪getTranslateTools();
207  }
208 
213  protected function ‪determineScriptUrl()
214  {
215  if ($routePath = GeneralUtility::_GP('route')) {
216  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
217  $this->thisScript = (string)$uriBuilder->buildUriFromRoutePath($routePath);
218  } else {
219  $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
220  }
221  }
222 
227  protected function ‪getThisScript()
228  {
229  return strpos($this->thisScript, '?') === false ? $this->thisScript . '?' : $this->thisScript . '&';
230  }
231 
246  public function ‪addElement($h, $icon, $data, $rowParams = '', $_ = '', $_2 = '', $colType = 'td')
247  {
248  $colType = ($colType === 'th') ? 'th' : 'td';
249  $noWrap = $this->no_noWrap ? '' : ' nowrap';
250  // Start up:
251  $l10nParent = isset($data['_l10nparent_']) ? (int)$data['_l10nparent_'] : 0;
252  $out = '
253  <!-- Element, begin: -->
254  <tr ' . $rowParams . ' data-uid="' . (int)$data['uid'] . '" data-l10nparent="' . $l10nParent . '">';
255  // Show icon and lines
256  if ($this->showIcon) {
257  $out .= '
258  <' . $colType . ' class="col-icon nowrap">';
259  if (!$h) {
260  $out .= '&nbsp;';
261  } else {
262  for ($a = 0; $a < $h; $a++) {
263  if (!$a) {
264  if ($icon) {
265  $out .= $icon;
266  }
267  }
268  }
269  }
270  $out .= '</' . $colType . '>
271  ';
272  }
273  // Init rendering.
274  $colsp = '';
275  $lastKey = '';
276  $c = 0;
277  $ccount = 0;
278  // __label is used as the label key to circumvent problems with uid used as label (see #67756)
279  // as it was introduced later on, check if it really exists before using it
281  if ($colType === 'td' && array_key_exists('__label', $data)) {
282  ‪$fields[0] = '__label';
283  }
284  // Traverse field array which contains the data to present:
285  foreach (‪$fields as $vKey) {
286  if (isset($data[$vKey])) {
287  if ($lastKey) {
288  $cssClass = $this->addElement_tdCssClass[$lastKey];
289  if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
290  $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
291  }
292  $out .= '
293  <' . $colType . ' class="' . $cssClass . $noWrap . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
294  }
295  $lastKey = $vKey;
296  $c = 1;
297  $ccount++;
298  } else {
299  if (!$lastKey) {
300  $lastKey = $vKey;
301  }
302  $c++;
303  }
304  if ($c > 1) {
305  $colsp = ' colspan="' . $c . '"';
306  } else {
307  $colsp = '';
308  }
309  }
310  if ($lastKey) {
311  $cssClass = $this->addElement_tdCssClass[$lastKey];
312  if ($this->oddColumnsCssClass) {
313  $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
314  }
315  $out .= '
316  <' . $colType . ' class="' . $cssClass . $noWrap . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
317  }
318  // End row
319  $out .= '
320  </tr>';
321  // Return row.
322  return $out;
323  }
324 
329  public function ‪writeTop()
330  {
331  }
332 
340  public function ‪fwd_rwd_nav($table = '')
341  {
342  $code = '';
343  if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
344  if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
345  // Reverse
346  $theData = [];
347  $titleCol = $this->fieldArray[0];
348  $theData[$titleCol] = $this->‪fwd_rwd_HTML('fwd', $this->eCounter, $table);
349  $code = $this->‪addElement(1, '', $theData, 'class="fwd_rwd_nav"');
350  }
351  return [1, $code];
352  }
353  if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
354  // Forward
355  $theData = [];
356  $titleCol = $this->fieldArray[0];
357  $theData[$titleCol] = $this->‪fwd_rwd_HTML('rwd', $this->eCounter, $table);
358  $code = $this->‪addElement(1, '', $theData, 'class="fwd_rwd_nav"');
359  }
360  return [0, $code];
361  }
362 
373  public function ‪fwd_rwd_HTML($type, $pointer, $table = '')
374  {
375  $content = '';
376  $tParam = $table ? '&table=' . rawurlencode($table) : '';
377  switch ($type) {
378  case 'fwd':
379  $href = $this->‪listURL() . '&pointer=' . ($pointer - ‪$this->iLimit) . $tParam;
380  $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-up', ‪Icon::SIZE_SMALL)->render() . '</a> <i>[' . (max(0, $pointer - $this->iLimit) + 1) . ' - ' . $pointer . ']</i>';
381  break;
382  case 'rwd':
383  $href = $this->‪listURL() . '&pointer=' . $pointer . $tParam;
384  $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-down', ‪Icon::SIZE_SMALL)->render() . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
385  break;
386  }
387  return $content;
388  }
389 
399  public function ‪listURL($altId = '', $table = '-1', $exclList = '')
400  {
401  return $this->‪getThisScript() . 'id=' . ($altId !== '' ? $altId : ‪$this->id);
402  }
403 
410  public function ‪CBfunctions()
411  {
412  return '
413  // checkOffCB()
414  function checkOffCB(listOfCBnames, link) { //
415  var checkBoxes, flag, i;
416  var checkBoxes = listOfCBnames.split(",");
417  if (link.rel === "") {
418  link.rel = "allChecked";
419  flag = true;
420  } else {
421  link.rel = "";
422  flag = false;
423  }
424  for (i = 0; i < checkBoxes.length; i++) {
425  setcbValue(checkBoxes[i], flag);
426  }
427  }
428  // cbValue()
429  function cbValue(CBname) { //
430  var CBfullName = "CBC["+CBname+"]";
431  return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
432  }
433  // setcbValue()
434  function setcbValue(CBname,flag) { //
435  CBfullName = "CBC["+CBname+"]";
436  if(document.dblistForm[CBfullName]) {
437  document.dblistForm[CBfullName].checked = flag ? "on" : 0;
438  }
439  }
440 
441  ';
442  }
443 
448  public function ‪initializeLanguages()
449  {
450  // Look up page overlays:
451  $localizationParentField = ‪$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
452  $languageField = ‪$GLOBALS['TCA']['pages']['ctrl']['languageField'];
453  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
454  ->getQueryBuilderForTable('pages');
455  $queryBuilder->getRestrictions()
456  ->removeAll()
457  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
458  ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
459  $result = $queryBuilder
460  ->select('*')
461  ->from('pages')
462  ->where(
463  $queryBuilder->expr()->andX(
464  $queryBuilder->expr()->eq($localizationParentField, $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
465  $queryBuilder->expr()->gt($languageField, $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
466  )
467  )
468  ->execute();
469 
470  $this->pageOverlays = [];
471  while ($row = $result->fetch()) {
472  $this->pageOverlays[$row[$languageField]] = $row;
473  }
474 
475  $this->languageIconTitles = $this->‪getTranslateTools()->‪getSystemLanguages($this->id);
476  }
477 
486  public function ‪languageFlag($sys_language_uid, $addAsAdditionalText = true)
487  {
488  $out = '';
489  $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
490  if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
491  $out .= '<span title="' . $title . '">' . $this->iconFactory->getIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], ‪Icon::SIZE_SMALL)->render() . '</span>';
492  if (!$addAsAdditionalText) {
493  return $out;
494  }
495  $out .= '&nbsp;';
496  }
497  $out .= $title;
498  return $out;
499  }
500 
507  protected function ‪getTranslateTools()
508  {
509  if (!isset($this->translateTools)) {
510  $this->translateTools = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
511  }
513  }
514 
524  protected function ‪generateReferenceToolTip($references, $launchViewParameter = '')
525  {
526  if (!$references) {
527  $htmlCode = '-';
528  } else {
529  $htmlCode = '<a href="#"';
530  if ($launchViewParameter !== '') {
531  $htmlCode .= ' onclick="' . htmlspecialchars('top.TYPO3.InfoWindow.showItem(' . $launchViewParameter . '); return false;') . '"';
532  }
533  $htmlCode .= ' title="' . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:show_references') . ' (' . $references . ')') . '">';
534  $htmlCode .= $references;
535  $htmlCode .= '</a>';
536  }
537  return $htmlCode;
538  }
539 
545  protected function ‪getLanguageService()
546  {
547  return ‪$GLOBALS['LANG'];
548  }
549 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$thisScript
‪string $thisScript
Definition: AbstractRecordList.php:107
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$counter
‪int $counter
Definition: AbstractRecordList.php:121
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\fwd_rwd_HTML
‪string fwd_rwd_HTML($type, $pointer, $table='')
Definition: AbstractRecordList.php:352
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$fixedL
‪int $fixedL
Definition: AbstractRecordList.php:100
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$showIcon
‪int $showIcon
Definition: AbstractRecordList.php:59
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$firstElementNumber
‪int $firstElementNumber
Definition: AbstractRecordList.php:135
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\addElement
‪string addElement($h, $icon, $data, $rowParams='', $_='', $_2='', $colType='td')
Definition: AbstractRecordList.php:225
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction
Definition: BackendWorkspaceRestriction.php:28
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$totalItems
‪string $totalItems
Definition: AbstractRecordList.php:128
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$languageIconTitles
‪array $languageIconTitles
Definition: AbstractRecordList.php:161
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪$fields
‪$fields
Definition: pages.php:4
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$addElement_tdCssClass
‪array $addElement_tdCssClass
Definition: AbstractRecordList.php:92
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\listURL
‪string listURL($altId='', $table='-1', $exclList='')
Definition: AbstractRecordList.php:378
‪TYPO3\CMS\Backend\RecordList
Definition: AbstractRecordList.php:2
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\getThisScript
‪string getThisScript()
Definition: AbstractRecordList.php:206
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$id
‪int $id
Definition: AbstractRecordList.php:40
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$leftMargin
‪int $leftMargin
Definition: AbstractRecordList.php:54
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$addElement_tdParams
‪array $addElement_tdParams
Definition: AbstractRecordList.php:85
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\__construct
‪__construct()
Definition: AbstractRecordList.php:177
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$iLimit
‪int $iLimit
Definition: AbstractRecordList.php:47
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\writeTop
‪writeTop()
Definition: AbstractRecordList.php:308
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$eCounter
‪int $eCounter
Definition: AbstractRecordList.php:140
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\initializeLanguages
‪initializeLanguages()
Definition: AbstractRecordList.php:427
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\getTranslateTools
‪TranslationConfigurationProvider getTranslateTools()
Definition: AbstractRecordList.php:486
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$pageOverlays
‪array $pageOverlays
Definition: AbstractRecordList.php:154
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$fieldArray
‪array $fieldArray
Definition: AbstractRecordList.php:78
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:35
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider\getSystemLanguages
‪array getSystemLanguages($pageId=0)
Definition: TranslationConfigurationProvider.php:51
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$HTMLcode
‪string $HTMLcode
Definition: AbstractRecordList.php:147
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$iconFactory
‪IconFactory $iconFactory
Definition: AbstractRecordList.php:171
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$oddColumnsCssClass
‪string $oddColumnsCssClass
Definition: AbstractRecordList.php:71
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractRecordList.php:524
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$setLMargin
‪int $setLMargin
Definition: AbstractRecordList.php:114
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList
Definition: AbstractRecordList.php:36
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$translateTools
‪TranslationConfigurationProvider $translateTools
Definition: AbstractRecordList.php:166
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\CBfunctions
‪string CBfunctions()
Definition: AbstractRecordList.php:389
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\generateReferenceToolTip
‪string generateReferenceToolTip($references, $launchViewParameter='')
Definition: AbstractRecordList.php:503
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\languageFlag
‪string languageFlag($sys_language_uid, $addAsAdditionalText=true)
Definition: AbstractRecordList.php:465
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\$no_noWrap
‪int $no_noWrap
Definition: AbstractRecordList.php:64
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\fwd_rwd_nav
‪array fwd_rwd_nav($table='')
Definition: AbstractRecordList.php:319
‪TYPO3\CMS\Backend\RecordList\AbstractRecordList\determineScriptUrl
‪determineScriptUrl()
Definition: AbstractRecordList.php:192