TYPO3  7.6
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 
26 
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 = array();
80 
86  public $addElement_tdParams = array();
87 
93  public $addElement_tdCssClass = array();
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 = array();
156 
162  public $languageIconTitles = array();
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  $parent = isset($data['parent']) ? (int)$data['parent'] : 0;
231  $out = '
232  <!-- Element, begin: -->
233  <tr ' . $rowParams . ' data-uid="' . (int)$data['uid'] . '" data-l10nparent="' . $parent . '">';
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  } else {
247  }
248  }
249  }
250  $out .= '</' . $colType . '>
251  ';
252  }
253  // Init rendering.
254  $colsp = '';
255  $lastKey = '';
256  $c = 0;
257  $ccount = 0;
258  // __label is used as the label key to circumvent problems with uid used as label (see #67756)
259  // as it was introduced later on, check if it really exists before using it
260  $fields = $this->fieldArray;
261  if ($colType === 'td' && array_key_exists('__label', $data)) {
262  $fields[0] = '__label';
263  }
264  // Traverse field array which contains the data to present:
265  foreach ($fields as $vKey) {
266  if (isset($data[$vKey])) {
267  if ($lastKey) {
268  $cssClass = $this->addElement_tdCssClass[$lastKey];
269  if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
270  $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
271  }
272  $out .= '
273  <' . $colType . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
274  }
275  $lastKey = $vKey;
276  $c = 1;
277  $ccount++;
278  } else {
279  if (!$lastKey) {
280  $lastKey = $vKey;
281  }
282  $c++;
283  }
284  if ($c > 1) {
285  $colsp = ' colspan="' . $c . '"';
286  } else {
287  $colsp = '';
288  }
289  }
290  if ($lastKey) {
291  $cssClass = $this->addElement_tdCssClass[$lastKey];
292  if ($this->oddColumnsCssClass) {
293  $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
294  }
295  $out .= '
296  <' . $colType . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
297  }
298  // End row
299  $out .= '
300  </tr>';
301  // Return row.
302  return $out;
303  }
304 
310  public function writeTop()
311  {
312  }
313 
320  public function fwd_rwd_nav($table = '')
321  {
322  $code = '';
323  if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
324  if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
325  // Reverse
326  $theData = array();
327  $titleCol = $this->fieldArray[0];
328  $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
329  $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
330  }
331  return array(1, $code);
332  } else {
333  if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
334  // Forward
335  $theData = array();
336  $titleCol = $this->fieldArray[0];
337  $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
338  $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
339  }
340  return array(0, $code);
341  }
342  }
343 
353  public function fwd_rwd_HTML($type, $pointer, $table = '')
354  {
355  $content = '';
356  $tParam = $table ? '&table=' . rawurlencode($table) : '';
357  switch ($type) {
358  case 'fwd':
359  $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
360  $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a> <i>[1 - ' . $pointer . ']</i>';
361  break;
362  case 'rwd':
363  $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
364  $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
365  break;
366  }
367  return $content;
368  }
369 
376  public function listURL($altId = '')
377  {
378  return $this->getThisScript() . 'id=' . ($altId !== '' ? $altId : $this->id);
379  }
380 
386  public function CBfunctions()
387  {
388  return '
389  // checkOffCB()
390  function checkOffCB(listOfCBnames, link) { //
391  var checkBoxes, flag, i;
392  var checkBoxes = listOfCBnames.split(",");
393  if (link.rel === "") {
394  link.rel = "allChecked";
395  flag = true;
396  } else {
397  link.rel = "";
398  flag = false;
399  }
400  for (i = 0; i < checkBoxes.length; i++) {
401  setcbValue(checkBoxes[i], flag);
402  }
403  }
404  // cbValue()
405  function cbValue(CBname) { //
406  var CBfullName = "CBC["+CBname+"]";
407  return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
408  }
409  // setcbValue()
410  function setcbValue(CBname,flag) { //
411  CBfullName = "CBC["+CBname+"]";
412  if(document.dblistForm[CBfullName]) {
413  document.dblistForm[CBfullName].checked = flag ? "on" : 0;
414  }
415  }
416 
417  ';
418  }
419 
425  public function initializeLanguages()
426  {
427  // Look up page overlays:
428  $this->pageOverlays = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=' . (int)$this->id . BackendUtility::deleteClause('pages_language_overlay') . BackendUtility::versioningPlaceholderClause('pages_language_overlay'), '', '', '', 'sys_language_uid');
429  $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id);
430  }
431 
439  public function languageFlag($sys_language_uid, $addAsAdditionalText = true)
440  {
441  $out = '';
442  $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
443  if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
444  $out .= '<span title="' . $title . '">' . $this->iconFactory->getIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], Icon::SIZE_SMALL)->render() . '</span>';
445  if (!$addAsAdditionalText) {
446  return $out;
447  }
448  $out .= '&nbsp;';
449  }
450  $out .= $title;
451  return $out;
452  }
453 
459  protected function getTranslateTools()
460  {
461  if (!isset($this->translateTools)) {
462  $this->translateTools = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
463  }
464  return $this->translateTools;
465  }
466 
475  protected function generateReferenceToolTip($references, $launchViewParameter = '')
476  {
477  if (!$references) {
478  $htmlCode = '-';
479  } else {
480  $htmlCode = '<a href="#"';
481  if ($launchViewParameter !== '') {
482  $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
483  }
484  $htmlCode .= ' title="' . htmlspecialchars($this->getLanguageService()->sl('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:show_references') . ' (' . $references . ')') . '">';
485  $htmlCode .= $references;
486  $htmlCode .= '</a>';
487  }
488  return $htmlCode;
489  }
490 
495  protected function getLanguageService()
496  {
497  return $GLOBALS['LANG'];
498  }
499 
505  protected function getDatabaseConnection()
506  {
507  return $GLOBALS['TYPO3_DB'];
508  }
509 }