TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AbstractRecordList.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\RecordList;
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 
28 
36 abstract class AbstractRecordList
37 {
41  protected $id = 0;
42 
48  public $iLimit = 10;
49 
55  public $leftMargin = 0;
56 
60  public $showIcon = 1;
61 
65  public $no_noWrap = 0;
66 
72  public $oddColumnsCssClass = '';
73 
79  public $fieldArray = [];
80 
86  public $addElement_tdParams = [];
87 
94 
101  public $fixedL = 30;
102 
108  public $thisScript = '';
109 
115  public $setLMargin = 1;
116 
122  public $counter = 0;
123 
129  public $totalItems = '';
130 
137 
141  public $eCounter = 0;
142 
148  public $HTMLcode = '';
149 
155  public $pageOverlays = [];
156 
162  public $languageIconTitles = [];
163 
168 
172  protected $iconFactory;
173 
177  public function __construct()
178  {
179  if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
180  $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
181  }
182  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
183  $this->getTranslateTools();
184  $this->determineScriptUrl();
185  }
186 
190  protected function determineScriptUrl()
191  {
192  if ($routePath = GeneralUtility::_GP('route')) {
193  $router = GeneralUtility::makeInstance(Router::class);
194  $route = $router->match($routePath);
195  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
196  $this->thisScript = (string)$uriBuilder->buildUriFromRoute($route->getOption('_identifier'));
197  } elseif ($moduleName = GeneralUtility::_GP('M')) {
198  $this->thisScript = BackendUtility::getModuleUrl($moduleName);
199  } else {
200  $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
201  }
202  }
203 
207  protected function getThisScript()
208  {
209  return strpos($this->thisScript, '?') === false ? $this->thisScript . '?' : $this->thisScript . '&';
210  }
211 
225  public function addElement($h, $icon, $data, $rowParams = '', $_ = '', $_2 = '', $colType = 'td')
226  {
227  $colType = ($colType === 'th') ? 'th' : 'td';
228  $noWrap = $this->no_noWrap ? '' : ' nowrap="nowrap"';
229  // Start up:
230  $l10nParent = isset($data['_l10nparent_']) ? (int)$data['_l10nparent_'] : 0;
231  $out = '
232  <!-- Element, begin: -->
233  <tr ' . $rowParams . ' data-uid="' . (int)$data['uid'] . '" data-l10nparent="' . $l10nParent . '">';
234  // Show icon and lines
235  if ($this->showIcon) {
236  $out .= '
237  <' . $colType . ' nowrap="nowrap" class="col-icon">';
238  if (!$h) {
239  $out .= '&nbsp;';
240  } else {
241  for ($a = 0; $a < $h; $a++) {
242  if (!$a) {
243  if ($icon) {
244  $out .= $icon;
245  }
246  }
247  }
248  }
249  $out .= '</' . $colType . '>
250  ';
251  }
252  // Init rendering.
253  $colsp = '';
254  $lastKey = '';
255  $c = 0;
256  $ccount = 0;
257  // __label is used as the label key to circumvent problems with uid used as label (see #67756)
258  // as it was introduced later on, check if it really exists before using it
260  if ($colType === 'td' && array_key_exists('__label', $data)) {
261  $fields[0] = '__label';
262  }
263  // Traverse field array which contains the data to present:
264  foreach ($fields as $vKey) {
265  if (isset($data[$vKey])) {
266  if ($lastKey) {
267  $cssClass = $this->addElement_tdCssClass[$lastKey];
268  if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
269  $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
270  }
271  $out .= '
272  <' . $colType . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
273  }
274  $lastKey = $vKey;
275  $c = 1;
276  $ccount++;
277  } else {
278  if (!$lastKey) {
279  $lastKey = $vKey;
280  }
281  $c++;
282  }
283  if ($c > 1) {
284  $colsp = ' colspan="' . $c . '"';
285  } else {
286  $colsp = '';
287  }
288  }
289  if ($lastKey) {
290  $cssClass = $this->addElement_tdCssClass[$lastKey];
291  if ($this->oddColumnsCssClass) {
292  $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
293  }
294  $out .= '
295  <' . $colType . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
296  }
297  // End row
298  $out .= '
299  </tr>';
300  // Return row.
301  return $out;
302  }
303 
309  public function writeTop()
310  {
311  }
312 
319  public function fwd_rwd_nav($table = '')
320  {
321  $code = '';
322  if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
323  if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
324  // Reverse
325  $theData = [];
326  $titleCol = $this->fieldArray[0];
327  $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
328  $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
329  }
330  return [1, $code];
331  } else {
332  if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
333  // Forward
334  $theData = [];
335  $titleCol = $this->fieldArray[0];
336  $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
337  $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
338  }
339  return [0, $code];
340  }
341  }
342 
352  public function fwd_rwd_HTML($type, $pointer, $table = '')
353  {
354  $content = '';
355  $tParam = $table ? '&table=' . rawurlencode($table) : '';
356  switch ($type) {
357  case 'fwd':
358  $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
359  $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a> <i>[1 - ' . $pointer . ']</i>';
360  break;
361  case 'rwd':
362  $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
363  $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
364  break;
365  }
366  return $content;
367  }
368 
377  public function listURL($altId = '', $table = '-1', $exclList = '')
378  {
379  return $this->getThisScript() . 'id=' . ($altId !== '' ? $altId : $this->id);
380  }
381 
387  public function CBfunctions()
388  {
389  return '
390  // checkOffCB()
391  function checkOffCB(listOfCBnames, link) { //
392  var checkBoxes, flag, i;
393  var checkBoxes = listOfCBnames.split(",");
394  if (link.rel === "") {
395  link.rel = "allChecked";
396  flag = true;
397  } else {
398  link.rel = "";
399  flag = false;
400  }
401  for (i = 0; i < checkBoxes.length; i++) {
402  setcbValue(checkBoxes[i], flag);
403  }
404  }
405  // cbValue()
406  function cbValue(CBname) { //
407  var CBfullName = "CBC["+CBname+"]";
408  return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
409  }
410  // setcbValue()
411  function setcbValue(CBname,flag) { //
412  CBfullName = "CBC["+CBname+"]";
413  if(document.dblistForm[CBfullName]) {
414  document.dblistForm[CBfullName].checked = flag ? "on" : 0;
415  }
416  }
417 
418  ';
419  }
420 
426  public function initializeLanguages()
427  {
428  // Look up page overlays:
429  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
430  ->getQueryBuilderForTable('pages_language_overlay');
431  $queryBuilder->getRestrictions()
432  ->removeAll()
433  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
434  ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
435  $result = $queryBuilder
436  ->select('*')
437  ->from('pages_language_overlay')
438  ->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)))
439  ->execute();
440 
441  $this->pageOverlays = [];
442  while ($row = $result->fetch()) {
443  $this->pageOverlays[$row['sys_language_uid']] = $row;
444  }
445 
446  $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id);
447  }
448 
456  public function languageFlag($sys_language_uid, $addAsAdditionalText = true)
457  {
458  $out = '';
459  $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
460  if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
461  $out .= '<span title="' . $title . '">' . $this->iconFactory->getIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], Icon::SIZE_SMALL)->render() . '</span>';
462  if (!$addAsAdditionalText) {
463  return $out;
464  }
465  $out .= '&nbsp;';
466  }
467  $out .= $title;
468  return $out;
469  }
470 
476  protected function getTranslateTools()
477  {
478  if (!isset($this->translateTools)) {
479  $this->translateTools = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
480  }
481  return $this->translateTools;
482  }
483 
492  protected function generateReferenceToolTip($references, $launchViewParameter = '')
493  {
494  if (!$references) {
495  $htmlCode = '-';
496  } else {
497  $htmlCode = '<a href="#"';
498  if ($launchViewParameter !== '') {
499  $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
500  }
501  $htmlCode .= ' title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:show_references') . ' (' . $references . ')') . '">';
502  $htmlCode .= $references;
503  $htmlCode .= '</a>';
504  }
505  return $htmlCode;
506  }
507 
512  protected function getLanguageService()
513  {
514  return $GLOBALS['LANG'];
515  }
516 }
generateReferenceToolTip($references, $launchViewParameter= '')
addElement($h, $icon, $data, $rowParams= '', $_= '', $_2= '', $colType= 'td')
languageFlag($sys_language_uid, $addAsAdditionalText=true)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
listURL($altId= '', $table= '-1', $exclList= '')