TYPO3 API  SVNRelease
TableListViewHelper.php
Go to the documentation of this file.
00001 <?php
00002 /*                                                                        *
00003  * This script belongs to the FLOW3 package "Fluid".                      *
00004  *                                                                        *
00005  * It is free software; you can redistribute it and/or modify it under    *
00006  * the terms of the GNU Lesser General Public License as published by the *
00007  * Free Software Foundation, either version 3 of the License, or (at your *
00008  * option) any later version.                                             *
00009  *                                                                        *
00010  * This script is distributed in the hope that it will be useful, but     *
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00012  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00013  * General Public License for more details.                               *
00014  *                                                                        *
00015  * You should have received a copy of the GNU Lesser General Public       *
00016  * License along with the script.                                         *
00017  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00018  *                                                                        *
00019  * The TYPO3 project - inspiring people to share!                         *
00020  *                                                                        */
00021 
00022 /**
00023  * View helper which renders a record list as known from the TYPO3 list module
00024  * Note: This feature is experimental!
00025  *
00026  * = Examples =
00027  *
00028  * <code title="Minimal">
00029  * <f:be.tableList tableName="fe_users" />
00030  * </code>
00031  * <output>
00032  * List of all "Website user" records stored in the configured storage PID.
00033  * Records will be editable, if the current BE user has got edit rights for the table "fe_users".
00034  * Only the title column (username) will be shown.
00035  * Context menu is active.
00036  * </output>
00037  *
00038  * <code title="Full">
00039  * <f:be.tableList tableName="fe_users" fieldList="{0: 'name', 1: 'email'}" storagePid="1" levels="2" filter='foo' recordsPerPage="10" sortField="name" sortDescending="true" readOnly="true" enableClickMenu="false" clickTitleMode="info" alternateBackgroundColors="true" />
00040  * </code>
00041  * <output>
00042  * List of "Website user" records with a text property of "foo" stored on PID 1 and two levels down.
00043  * Clicking on a username will open the TYPO3 info popup for the respective record
00044  * </output>
00045  *
00046  * @author Bastian Waidelich <bastian@typo3.org>
00047  * @license http://www.gnu.org/copyleft/gpl.html
00048  */
00049 require_once (PATH_typo3 . 'class.db_list.inc');
00050 require_once (PATH_typo3 . 'class.db_list_extra.inc');
00051 
00052 class Tx_Fluid_ViewHelpers_Be_TableListViewHelper extends Tx_Fluid_ViewHelpers_Be_AbstractBackendViewHelper {
00053 
00054     /**
00055      * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
00056      */
00057     protected $configurationManager;
00058 
00059     /**
00060      * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
00061      * @return void
00062      */
00063     public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
00064         $this->configurationManager = $configurationManager;
00065     }
00066 
00067     /**
00068      * Renders a record list as known from the TYPO3 list module
00069      * Note: This feature is experimental!
00070      *
00071      * @param string $tableName name of the database table
00072      * @param array $fieldList list of fields to be displayed. If empty, only the title column (configured in $TCA[$tableName]['ctrl']['title']) is shown
00073      * @param integer $storagePid by default, records are fetched from the storage PID configured in persistence.storagePid. With this argument, the storage PID can be overwritten
00074      * @param integer $levels corresponds to the level selector of the TYPO3 list module. By default only records from the current storagePid are fetched
00075      * @param string $filter corresponds to the "Search String" textbox of the TYPO3 list module. If not empty, only records matching the string will be fetched
00076      * @param integer $recordsPerPage amount of records to be displayed at once. Defaults to $TCA[$tableName]['interface']['maxSingleDBListItems'] or (if that's not set) to 100
00077      * @param string $sortField table field to sort the results by
00078      * @param boolean $sortDescending if TRUE records will be sorted in descending order
00079      * @param boolean $readOnly if TRUE, the edit icons won't be shown. Otherwise edit icons will be shown, if the current BE user has edit rights for the specified table!
00080      * @param boolean $enableClickMenu enables context menu
00081      * @param string $clickTitleMode one of "edit", "show" (only pages, tt_content), "info"
00082      * @param boolean $alternateBackgroundColors if set, rows will have alternate background colors
00083      * @return string the rendered record list
00084      * @see localRecordList
00085      */
00086     public function render($tableName, array $fieldList = array(), $storagePid = NULL, $levels = 0, $filter = '', $recordsPerPage = 0, $sortField = '', $sortDescending = FALSE, $readOnly = FALSE, $enableClickMenu = TRUE, $clickTitleMode = NULL, $alternateBackgroundColors = FALSE) {
00087         $pageinfo = t3lib_BEfunc::readPageAccess(t3lib_div::_GP('id'), $GLOBALS['BE_USER']->getPagePermsClause(1));
00088 
00089         $dblist = t3lib_div::makeInstance('localRecordList');
00090         $dblist->backPath = $GLOBALS['BACK_PATH'];
00091         $dblist->pageRow = $pageinfo;
00092         if ($readOnly === FALSE) {
00093             $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageinfo);
00094         }
00095         $dblist->showClipboard = FALSE;
00096         $dblist->disableSingleTableView = TRUE;
00097         $dblist->clickTitleMode = $clickTitleMode;
00098         $dblist->alternateBgColors = $alternateBackgroundColors;
00099         $dblist->clickMenuEnabled = $enableClickMenu;
00100 
00101         if ($storagePid === NULL) {
00102             $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
00103             $storagePid = $frameworkConfiguration['persistence']['storagePid'];
00104         }
00105 
00106         $dblist->start($storagePid, $tableName, (integer)t3lib_div::_GP('pointer'), $filter, $levels, $recordsPerPage);
00107         $dblist->allFields = TRUE;
00108         $dblist->dontShowClipControlPanels = TRUE;
00109         $dblist->displayFields = FALSE;
00110         $dblist->setFields = array($tableName => $fieldList);
00111         $dblist->noControlPanels = TRUE;
00112         $dblist->sortField = $sortField;
00113         $dblist->sortRev = $sortDescending;
00114 
00115         $dblist->script = $_SERVER['REQUEST_URI'];
00116         $dblist->generateList();
00117 
00118         return $dblist->HTMLcode;
00119     }
00120 }
00121 ?>