TYPO3 API  SVNRelease
class.t3lib_recordlist.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 /**
00028  * Library with a single function addElement that returns tablerows based on some input.
00029  *
00030  * $Id: class.t3lib_recordlist.php 10121 2011-01-18 20:15:30Z ohader $
00031  * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
00032  * XHTML compliant
00033  *
00034  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00035  */
00036 /**
00037  * [CLASS/FUNCTION INDEX of SCRIPT]
00038  *
00039  *
00040  *
00041  *   80: class t3lib_recordList
00042  *  123:     function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')
00043  *  198:     function writeTop()
00044  *  206:     function writeBottom()
00045  *  225:     function fwd_rwd_nav($table='')
00046  *  258:     function fwd_rwd_HTML($type,$pointer,$table='')
00047  *  284:     function listURL($altId='')
00048  *  294:     function CBfunctions()
00049  *  344:     function initializeLanguages()
00050  *  411:     function languageFlag($sys_language_uid)
00051  *
00052  * TOTAL FUNCTIONS: 9
00053  * (This index is automatically created/updated by the extension "extdeveval")
00054  *
00055  */
00056 
00057 
00058 /**
00059  * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
00060  *
00061  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00062  * @package TYPO3
00063  * @subpackage t3lib
00064  * @see typo3/db_list.php, typo3/file_list.php
00065  */
00066 class t3lib_recordList {
00067 
00068         // Used in this class:
00069     var $iLimit = 10; // default Max items shown
00070     var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
00071     var $showIcon = 1;
00072     var $no_noWrap = 0;
00073     var $oddColumnsTDParams = ''; // Deprecated since TYPO3 4.2, remove in 4.4. If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
00074     var $oddColumnsCssClass = ''; // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
00075     var $backPath = '';
00076     var $fieldArray = Array(); // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
00077     var $addElement_tdParams = array(); // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
00078     var $addElement_tdCssClass = array(); // Keys are fieldnames and values are td-css-classes to add in addElement();
00079 
00080         // Not used in this class - but maybe extension classes...
00081     var $fixedL = 30; // Max length of strings
00082     var $script = '';
00083     var $thumbScript = 'thumbs.php';
00084     var $setLMargin = 1; // Set to zero, if you don't want a left-margin with addElement function
00085 
00086     var $counter = 0; // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
00087     var $totalItems = ''; // This could be set to the total number of items. Used by the fwd_rew_navigation...
00088 
00089         // Internal (used in this class.)
00090     var $firstElementNumber = 0;
00091     var $eCounter = 0;
00092     var $HTMLcode = ''; // String with accumulated HTML content
00093 
00094     var $pageOverlays = array(); // Contains page translation languages
00095     var $languageIconTitles = array(); // Contains sys language icons and titles
00096     var $translateTools; // translateTools object
00097 
00098     /**
00099      * constructor for t3lib_recordList
00100      *
00101      * @author  Ingo Renner <ingo@typo3.org>
00102      */
00103     public function __construct() {
00104         if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
00105             $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
00106         }
00107         $this->getTranslateTools();
00108     }
00109 
00110 
00111     /**
00112      * Returns a table-row with the content from the fields in the input data array.
00113      * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
00114      *
00115      * @param   integer     $h is an integer >=0 and denotes how tall a element is. Set to '0' makes a halv line, -1 = full line, set to 1 makes a 'join' and above makes 'line'
00116      * @param   string      $icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
00117      * @param   array       $data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
00118      * @param   string      $tdParams is insert in the <td>-tags. Must carry a ' ' as first character
00119      * @param   integer     OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
00120      * @param   string      $altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
00121      * @return  string      HTML content for the table row
00122      */
00123     function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
00124         $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
00125 
00126             // Start up:
00127         $out = '
00128         <!-- Element, begin: -->
00129         <tr ' . $trParams . '>';
00130             // Show icon and lines
00131         if ($this->showIcon) {
00132             $out .= '
00133             <td nowrap="nowrap" class="col-icon">';
00134 
00135             if (!$h) {
00136                 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
00137             } else {
00138                 for ($a = 0; $a < $h; $a++) {
00139                     if (!$a) {
00140                         if ($icon) {
00141                             $out .= $icon;
00142                         }
00143                     } else {
00144                     }
00145                 }
00146             }
00147             $out .= '</td>
00148             ';
00149         }
00150 
00151             // Init rendering.
00152         $colsp = '';
00153         $lastKey = '';
00154         $c = 0;
00155         $ccount = 0;
00156 
00157             // Traverse field array which contains the data to present:
00158         foreach ($this->fieldArray as $vKey) {
00159             if (isset($data[$vKey])) {
00160                 if ($lastKey) {
00161                     $cssClass = $this->addElement_tdCssClass[$lastKey];
00162                     if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
00163                         $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
00164                     }
00165 
00166                     $out .= '
00167                         <td' .
00168                             $noWrap .
00169                             ' class="' . $cssClass . '"' .
00170                             $colsp .
00171                             $this->addElement_tdParams[$lastKey] .
00172                             '>' . $data[$lastKey] . '</td>';
00173                 }
00174                 $lastKey = $vKey;
00175                 $c = 1;
00176                 $ccount++;
00177             } else {
00178                 if (!$lastKey) {
00179                     $lastKey = $vKey;
00180                 }
00181                 $c++;
00182             }
00183             if ($c > 1) {
00184                 $colsp = ' colspan="' . $c . '"';
00185             } else {
00186                 $colsp = '';
00187             }
00188         }
00189         if ($lastKey) {
00190             $cssClass = $this->addElement_tdCssClass[$lastKey];
00191             if ($this->oddColumnsCssClass) {
00192                 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
00193             }
00194 
00195             $out .= '
00196                 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
00197         }
00198 
00199             // End row
00200         $out .= '
00201         </tr>';
00202 
00203             // Return row.
00204         return $out;
00205     }
00206 
00207     /**
00208      * Dummy function, used to write the top of a table listing.
00209      *
00210      * @return  void
00211      */
00212     function writeTop() {
00213     }
00214 
00215     /**
00216      * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
00217      *
00218      * @return  void
00219      */
00220     function writeBottom() {
00221         $this->HTMLcode .= '
00222 
00223         <!--
00224             End of list table:
00225         -->
00226         <table border="0" cellpadding="0" cellspacing="0">';
00227         $theIcon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" />';
00228         $this->HTMLcode .= $this->addElement(1, '', '', '', $this->leftMargin, $theIcon);
00229         $this->HTMLcode .= '
00230         </table>';
00231     }
00232 
00233     /**
00234      * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
00235      *
00236      * @param   string      Table name
00237      * @return  array       array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
00238      */
00239     function fwd_rwd_nav($table = '') {
00240         $code = '';
00241         if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
00242             if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
00243                     //  reverse
00244                 $theData = Array();
00245                 $titleCol = $this->fieldArray[0];
00246                 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
00247                 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
00248             }
00249             return array(1, $code);
00250         } else {
00251             if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
00252                     //  forward
00253                 $theData = Array();
00254                 $titleCol = $this->fieldArray[0];
00255                 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
00256                 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
00257             }
00258             return array(0, $code);
00259         }
00260 
00261     }
00262 
00263     /**
00264      * Creates the button with link to either forward or reverse
00265      *
00266      * @param   string      Type: "fwd" or "rwd"
00267      * @param   integer     Pointer
00268      * @param   string      Table name
00269      * @return  string
00270      * @access private
00271      */
00272     function fwd_rwd_HTML($type, $pointer, $table = '') {
00273         $content = '';
00274         $tParam = $table ? '&table=' . rawurlencode($table) : '';
00275         switch ($type) {
00276             case 'fwd':
00277                 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
00278                 $content = '<a href="' . htmlspecialchars($href) . '">' .
00279                            t3lib_iconWorks::getSpriteIcon('actions-move-up') .
00280                            '</a> <i>[1 - ' . $pointer . ']</i>';
00281             break;
00282             case 'rwd':
00283                 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
00284                 $content = '<a href="' . htmlspecialchars($href) . '">' .
00285                            t3lib_iconWorks::getSpriteIcon('actions-move-down') .
00286                            '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
00287             break;
00288         }
00289         return $content;
00290     }
00291 
00292     /**
00293      * Creates the URL to this script, including all relevant GPvars
00294      *
00295      * @param   string      Alternative id value. Enter blank string for the current id ($this->id)
00296      * @return  string      URL
00297      */
00298     function listURL($altId = '') {
00299         return $this->script .
00300                '?id=' . (strcmp($altId, '') ? $altId : $this->id);
00301     }
00302 
00303     /**
00304      * Returning JavaScript for ClipBoard functionality.
00305      *
00306      * @return  string
00307      */
00308     function CBfunctions() {
00309         return '
00310         // checkOffCB()
00311     function checkOffCB(listOfCBnames, link)    {   //
00312         var checkBoxes, flag, i;
00313         var checkBoxes = listOfCBnames.split(",");
00314         if (link.rel === "") {
00315             link.rel = "allChecked";
00316             flag = true;
00317         } else {
00318             link.rel = "";
00319             flag = false;
00320         }
00321         for (i = 0; i < checkBoxes.length; i++) {
00322             setcbValue(checkBoxes[i], flag);
00323         }
00324     }
00325         // cbValue()
00326     function cbValue(CBname)    {   //
00327         var CBfullName = "CBC["+CBname+"]";
00328         return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
00329     }
00330         // setcbValue()
00331     function setcbValue(CBname,flag)    {   //
00332         CBfullName = "CBC["+CBname+"]";
00333         if(document.dblistForm[CBfullName]) {
00334             document.dblistForm[CBfullName].checked = flag ? "on" : 0;
00335         }
00336     }
00337 
00338         ';
00339     }
00340 
00341     /**
00342      * Initializes page languages and icons
00343      *
00344      * @return  void
00345      */
00346     function initializeLanguages() {
00347         global $TCA, $LANG;
00348 
00349             // Look up page overlays:
00350         $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00351             '*',
00352             'pages_language_overlay',
00353             'pid=' . intval($this->id) .
00354             t3lib_BEfunc::deleteClause('pages_language_overlay') .
00355             t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
00356             '',
00357             '',
00358             '',
00359             'sys_language_uid'
00360         );
00361 
00362         $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
00363     }
00364 
00365     /**
00366      * Return the icon for the language
00367      *
00368      * @param   integer     Sys language uid
00369      * @return  string      Language icon
00370      */
00371     function languageFlag($sys_language_uid) {
00372         $out = '';
00373         if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
00374             $out .= t3lib_iconWorks::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon']);
00375             $out .= '&nbsp;';
00376         }
00377         $out .= htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
00378         return $out;
00379     }
00380 
00381     /**
00382      * Gets an instance of t3lib_transl8tools.
00383      *
00384      * @return  t3lib_transl8tools
00385      */
00386     protected function getTranslateTools() {
00387         if (!isset($this->translateTools)) {
00388             $this->translateTools = t3lib_div::makeInstance('t3lib_transl8tools');
00389         }
00390         return $this->translateTools;
00391     }
00392 }
00393 
00394 
00395 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php'])) {
00396     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
00397 }
00398 
00399 ?>