[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / TableListViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * View helper which renders a record list as known from the TYPO3 list module
21 * Note: This feature is experimental!
22 *
23 * = Examples =
24 *
25 * <code title="Minimal">
26 * <f:be.tableList tableName="fe_users" />
27 * </code>
28 * <output>
29 * List of all "Website user" records stored in the configured storage PID.
30 * Records will be editable, if the current BE user has got edit rights for the table "fe_users".
31 * Only the title column (username) will be shown.
32 * Context menu is active.
33 * </output>
34 *
35 * <code title="Full">
36 * <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" />
37 * </code>
38 * <output>
39 * List of "Website user" records with a text property of "foo" stored on PID 1 and two levels down.
40 * Clicking on a username will open the TYPO3 info popup for the respective record
41 * </output>
42 */
43 class TableListViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper {
44
45 /**
46 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
47 * @inject
48 */
49 protected $configurationManager;
50
51 /**
52 * Renders a record list as known from the TYPO3 list module
53 * Note: This feature is experimental!
54 *
55 * @param string $tableName name of the database table
56 * @param array $fieldList list of fields to be displayed. If empty, only the title column (configured in $TCA[$tableName]['ctrl']['title']) is shown
57 * @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
58 * @param integer $levels corresponds to the level selector of the TYPO3 list module. By default only records from the current storagePid are fetched
59 * @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
60 * @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
61 * @param string $sortField table field to sort the results by
62 * @param boolean $sortDescending if TRUE records will be sorted in descending order
63 * @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!
64 * @param boolean $enableClickMenu enables context menu
65 * @param string $clickTitleMode one of "edit", "show" (only pages, tt_content), "info
66 * @param boolean $alternateBackgroundColors if set, rows will have alternate background colors
67 * @return string the rendered record list
68 * @see localRecordList
69 */
70 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) {
71 $pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'), $GLOBALS['BE_USER']->getPagePermsClause(1));
72 /** @var $dblist \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList */
73 $dblist = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recordlist\\RecordList\\DatabaseRecordList');
74 $dblist->backPath = $GLOBALS['BACK_PATH'];
75 $dblist->pageRow = $pageinfo;
76 if ($readOnly === FALSE) {
77 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageinfo);
78 }
79 $dblist->showClipboard = FALSE;
80 $dblist->disableSingleTableView = TRUE;
81 $dblist->clickTitleMode = $clickTitleMode;
82 $dblist->alternateBgColors = $alternateBackgroundColors;
83 $dblist->clickMenuEnabled = $enableClickMenu;
84 if ($storagePid === NULL) {
85 $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
86 $storagePid = $frameworkConfiguration['persistence']['storagePid'];
87 }
88 $dblist->start($storagePid, $tableName, (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pointer'), $filter, $levels, $recordsPerPage);
89 $dblist->allFields = TRUE;
90 $dblist->dontShowClipControlPanels = TRUE;
91 $dblist->displayFields = FALSE;
92 $dblist->setFields = array($tableName => $fieldList);
93 $dblist->noControlPanels = TRUE;
94 $dblist->sortField = $sortField;
95 $dblist->sortRev = $sortDescending;
96 $dblist->script = $_SERVER['REQUEST_URI'];
97 $dblist->generateList();
98 return $dblist->HTMLcode;
99 }
100 }