TYPO3 CMS  TYPO3_6-2
AbstractRecordList.php
Go to the documentation of this file.
1 <?php
3 
20 
32 abstract class AbstractRecordList {
33 
34  // Used in this class:
35  // default Max items shown
39  public $iLimit = 10;
40 
41  // OBSOLETE - NOT USED ANYMORE. leftMargin
45  public $leftMargin = 0;
46 
50  public $showIcon = 1;
51 
55  public $no_noWrap = 0;
56 
57  // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
61  public $oddColumnsCssClass = '';
62 
66  public $backPath = '';
67 
68  // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
72  public $fieldArray = array();
73 
74  // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
78  public $addElement_tdParams = array();
79 
80  // Keys are fieldnames and values are td-css-classes to add in addElement();
84  public $addElement_tdCssClass = array();
85 
86  // Not used in this class - but maybe extension classes...
87  // Max length of strings
91  public $fixedL = 30;
92 
96  public $thisScript = '';
97 
98  // Set to zero, if you don't want a left-margin with addElement function
102  public $setLMargin = 1;
103 
104  // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
108  public $counter = 0;
109 
110  // This could be set to the total number of items. Used by the fwd_rew_navigation...
114  public $totalItems = '';
115 
116  // Internal (used in this class.)
121 
125  public $eCounter = 0;
126 
127  // String with accumulated HTML content
131  public $HTMLcode = '';
132 
133  // Contains page translation languages
137  public $pageOverlays = array();
138 
139  // Contains sys language icons and titles
143  public $languageIconTitles = array();
144 
150 
154  public function __construct() {
155  if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
156  $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
157  }
158  $this->getTranslateTools();
159  }
160 
164  protected function determineScriptUrl() {
165  if ($moduleName = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('M')) {
167  } else {
168  $this->thisScript = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME');
169  }
170  }
171 
175  protected function getThisScript() {
176  return strpos($this->thisScript, '?') === FALSE ? $this->thisScript . '?' : $this->thisScript . '&';
177  }
178 
192  public function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
193  $noWrap = $this->no_noWrap ? '' : ' nowrap="nowrap"';
194  // Start up:
195  $out = '
196  <!-- Element, begin: -->
197  <tr ' . $trParams . '>';
198  // Show icon and lines
199  if ($this->showIcon) {
200  $out .= '
201  <td nowrap="nowrap" class="col-icon">';
202  if (!$h) {
203  $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
204  } else {
205  for ($a = 0; $a < $h; $a++) {
206  if (!$a) {
207  if ($icon) {
208  $out .= $icon;
209  }
210  } else {
211 
212  }
213  }
214  }
215  $out .= '</td>
216  ';
217  }
218  // Init rendering.
219  $colsp = '';
220  $lastKey = '';
221  $c = 0;
222  $ccount = 0;
223  // Traverse field array which contains the data to present:
224  foreach ($this->fieldArray as $vKey) {
225  if (isset($data[$vKey])) {
226  if ($lastKey) {
227  $cssClass = $this->addElement_tdCssClass[$lastKey];
228  if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
229  $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
230  }
231  $out .= '
232  <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
233  }
234  $lastKey = $vKey;
235  $c = 1;
236  $ccount++;
237  } else {
238  if (!$lastKey) {
239  $lastKey = $vKey;
240  }
241  $c++;
242  }
243  if ($c > 1) {
244  $colsp = ' colspan="' . $c . '"';
245  } else {
246  $colsp = '';
247  }
248  }
249  if ($lastKey) {
250  $cssClass = $this->addElement_tdCssClass[$lastKey];
251  if ($this->oddColumnsCssClass) {
252  $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
253  }
254  $out .= '
255  <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
256  }
257  // End row
258  $out .= '
259  </tr>';
260  // Return row.
261  return $out;
262  }
263 
270  public function writeTop() {
271 
272  }
273 
281  public function writeBottom() {
283  }
284 
292  public function fwd_rwd_nav($table = '') {
293  $code = '';
294  if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
295  if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
296  // Reverse
297  $theData = array();
298  $titleCol = $this->fieldArray[0];
299  $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
300  $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
301  }
302  return array(1, $code);
303  } else {
304  if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
305  // Forward
306  $theData = array();
307  $titleCol = $this->fieldArray[0];
308  $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
309  $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
310  }
311  return array(0, $code);
312  }
313  }
314 
325  public function fwd_rwd_HTML($type, $pointer, $table = '') {
326  $content = '';
327  $tParam = $table ? '&table=' . rawurlencode($table) : '';
328  switch ($type) {
329  case 'fwd':
330  $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
331  $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-up') . '</a> <i>[1 - ' . $pointer . ']</i>';
332  break;
333  case 'rwd':
334  $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
335  $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-down') . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
336  break;
337  }
338  return $content;
339  }
340 
348  public function listURL($altId = '') {
349  return $this->getThisScript() . 'id=' . ($altId !== '' ? $altId : $this->id);
350  }
351 
358  public function CBfunctions() {
359  return '
360  // checkOffCB()
361  function checkOffCB(listOfCBnames, link) { //
362  var checkBoxes, flag, i;
363  var checkBoxes = listOfCBnames.split(",");
364  if (link.rel === "") {
365  link.rel = "allChecked";
366  flag = true;
367  } else {
368  link.rel = "";
369  flag = false;
370  }
371  for (i = 0; i < checkBoxes.length; i++) {
372  setcbValue(checkBoxes[i], flag);
373  }
374  }
375  // cbValue()
376  function cbValue(CBname) { //
377  var CBfullName = "CBC["+CBname+"]";
378  return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
379  }
380  // setcbValue()
381  function setcbValue(CBname,flag) { //
382  CBfullName = "CBC["+CBname+"]";
383  if(document.dblistForm[CBfullName]) {
384  document.dblistForm[CBfullName].checked = flag ? "on" : 0;
385  }
386  }
387 
388  ';
389  }
390 
397  public function initializeLanguages() {
398  // Look up page overlays:
399  $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=' . (int)$this->id . BackendUtility::deleteClause('pages_language_overlay') . BackendUtility::versioningPlaceholderClause('pages_language_overlay'), '', '', '', 'sys_language_uid');
400  $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
401  }
402 
411  public function languageFlag($sys_language_uid, $addAsAdditionalText = TRUE) {
412  $out = '';
413  $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
414  if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
415  $out .= IconUtility::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], array('title' => $title));
416  if (!$addAsAdditionalText) {
417  return $out;
418  }
419  $out .= '&nbsp;';
420  }
421  $out .= $title;
422  return $out;
423  }
424 
430  protected function getTranslateTools() {
431  if (!isset($this->translateTools)) {
432  $this->translateTools = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider');
433  }
434  return $this->translateTools;
435  }
436 
445  protected function generateReferenceToolTip(array $references, $launchViewParameter = '') {
446  $result = array();
447  foreach ($references as $reference) {
448  $result[] = $reference['tablename'] . ':' . $reference['recuid'] . ':' . $reference['field'];
449  if (strlen(implode(' / ', $result)) >= 100) {
450  break;
451  }
452  }
453  if (empty($result)) {
454  $htmlCode = '-';
455  } else {
456  $htmlCode = '<a href="#"';
457  if ($launchViewParameter !== '') {
458  $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
459  }
460  $htmlCode .= ' title="' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(implode(' / ', $result), 100)) . '">';
461  $htmlCode .= count($references);
462  $htmlCode .= '</a>';
463  }
464  return $htmlCode;
465  }
466 
467 }
generateReferenceToolTip(array $references, $launchViewParameter='')
$moduleName
Definition: mod.php:22
languageFlag($sys_language_uid, $addAsAdditionalText=TRUE)
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static fixed_lgd_cs($string, $chars, $appendString='...')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static deleteClause($table, $tableAlias='')
addElement($h, $icon, $data, $trParams='', $lMargin='', $altLine='')