[TASK] Remove DocumentTemplate section in Wizard controllers
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_sortpages / Classes / View / SortPagesWizardModuleFunction.php
1 <?php
2 namespace TYPO3\CMS\WizardSortpages\View;
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Messaging\FlashMessage;
21 use TYPO3\CMS\Core\Page\PageRenderer;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Creates the "Sort pages" wizard
26 */
27 class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
28 {
29 /**
30 * Main function creating the content for the module.
31 *
32 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
33 */
34 public function main()
35 {
36 $lang = $this->getLanguageService();
37 $lang->includeLLFile('EXT:wizard_sortpages/Resources/Private/Language/locallang.xlf');
38 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
39 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
40 $out = $this->pObj->doc->header($lang->getLL('wiz_sort'));
41 if ($this->getBackendUser()->workspace === 0) {
42 $theCode = '';
43 // Check if user has modify permissions to
44 $sys_pages = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
45 $sortByField = GeneralUtility::_GP('sortByField');
46 if ($sortByField) {
47 $menuItems = array();
48 if (GeneralUtility::inList('title,subtitle,crdate,tstamp', $sortByField)) {
49 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', $sortByField, '', false);
50 } elseif ($sortByField === 'REV') {
51 $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', 'sorting', '', false);
52 $menuItems = array_reverse($menuItems);
53 }
54 if (!empty($menuItems)) {
55 $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
56 $tce->stripslashes_values = 0;
57 $menuItems = array_reverse($menuItems);
58 $cmd = array();
59 foreach ($menuItems as $r) {
60 $cmd['pages'][$r['uid']]['move'] = $this->pObj->id;
61 }
62 $tce->start(array(), $cmd);
63 $tce->process_cmdmap();
64 BackendUtility::setUpdateSignal('updatePageTree');
65 }
66 }
67 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', false);
68
69 if (!empty($menuItems)) {
70 $lines = array();
71 $lines[] = '<thead><tr>';
72 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_title') . '</th>';
73 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_subtitle') . '</th>';
74 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tChange') . '</th>';
75 $lines[] = '<th>' . $lang->getLL('wiz_changeOrder_tCreate') . '</th>';
76 $lines[] = '</tr></thead>';
77
78 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
79 foreach ($menuItems as $rec) {
80 $m_perms_clause = $this->getBackendUser()->getPagePermsClause(2);
81 // edit permissions for that page!
82 $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
83 $lines[] = '<tr><td nowrap="nowrap">' . $iconFactory->getIconForRecord('pages', $rec, Icon::SIZE_SMALL)->render() . (!is_array($pRec) ? '<strong class="text-danger">' . $lang->getLL('wiz_W', true) . '</strong></span> ' : '') . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
84 <td nowrap="nowrap">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['subtitle'], $this->getBackendUser()->uc['titleLen'])) . '</td>
85 <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '</td>
86 <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '</td>
87 </tr>';
88 }
89 $theCode .= '<h2>' . $lang->getLL('wiz_currentPageOrder', true) . '</h2>';
90 $theCode .= '<div class="table-fit"><table class="table table-striped table-hover">' . implode('', $lines) . '</table></div>';
91
92 // Menu:
93 $lines = array();
94 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_title'), 'title');
95 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_subtitle'), 'subtitle');
96 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tChange'), 'tstamp');
97 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_tCreate'), 'crdate');
98 $lines[] = '';
99 $lines[] = $this->wiz_linkOrder($lang->getLL('wiz_changeOrder_REVERSE'), 'REV');
100 $theCode .= '<h4>' . $lang->getLL('wiz_changeOrder') . '</h4><p>' . implode(' ', $lines) . '</p>';
101 } else {
102 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('no_subpages'), '', FlashMessage::NOTICE);
103 $theCode .= $flashMessage->render();
104 }
105 // CSH:
106 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', null, '<br />|');
107 $out .= '<div>' . $theCode . '</div>';
108 } else {
109 $out .= '<div>Sorry, this function is not available in the current draft workspace!</div>';
110 }
111 return $out;
112 }
113
114 /**
115 * Creates a link for the sorting order
116 *
117 * @param string $title Title of the link
118 * @param string $order Field to sort by
119 * @return string HTML string
120 */
121 protected function wiz_linkOrder($title, $order)
122 {
123 $href = BackendUtility::getModuleUrl('web_func',
124 array(
125 'id' => $GLOBALS['SOBE']->id,
126 'sortByField' => $order
127 )
128 );
129 return '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($href) . '" '
130 . ' data-severity="warning"'
131 . ' data-title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:pleaseConfirm', true) . '"'
132 . ' data-button-close-text="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel', true) . '"'
133 . ' data-content="' . $this->getLanguageService()->getLL('wiz_changeOrder_msg1', true) . '"'
134 . ' >' . htmlspecialchars($title) . '</a>';
135 }
136
137 /**
138 * Returns LanguageService
139 *
140 * @return \TYPO3\CMS\Lang\LanguageService
141 */
142 protected function getLanguageService()
143 {
144 return $GLOBALS['LANG'];
145 }
146
147 /**
148 * Returns the current BE user.
149 *
150 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
151 */
152 protected function getBackendUser()
153 {
154 return $GLOBALS['BE_USER'];
155 }
156 }