[TASK] Utilize grunt-newer to build only changed files
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / ViewHelpers / Display / PagesViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Beuser\ViewHelpers\Display;
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\Core\Database\Connection;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23
24 /**
25 * Converts comma separated list of pages uids to html unordered list (<ul>) with speaking titles
26 * @internal
27 */
28 class PagesViewHelper extends AbstractViewHelper
29 {
30 use CompileWithRenderStatic;
31
32 /**
33 * As this ViewHelper renders HTML, the output must not be escaped.
34 *
35 * @var bool
36 */
37 protected $escapeOutput = false;
38
39 /**
40 * Initializes the arguments
41 */
42 public function initializeArguments()
43 {
44 $this->registerArgument('uids', 'string', '', false, '');
45 }
46
47 /**
48 * Render unordered list for pages
49 *
50 * @param array $arguments
51 * @param \Closure $renderChildrenClosure
52 * @param RenderingContextInterface $renderingContext
53 *
54 * @return string
55 */
56 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
57 {
58 $uids = $arguments['uids'];
59 if (!$uids) {
60 return '';
61 }
62
63 $content = '';
64
65 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
66 $queryBuilder->getRestrictions()->removeAll();
67
68 $res = $queryBuilder
69 ->select('uid', 'title')
70 ->from('pages')
71 ->where(
72 $queryBuilder->expr()->in(
73 'uid',
74 $queryBuilder->createNamedParameter(
75 GeneralUtility::intExplode(',', $uids),
76 Connection::PARAM_INT_ARRAY
77 )
78 )
79 )
80 ->orderBy('uid', 'ASC')
81 ->execute();
82
83 while ($row = $res->fetch()) {
84 $content .= '<li>' . htmlspecialchars($row['title']) . ' [' . htmlspecialchars($row['uid']) . ']</li>';
85 }
86 return '<ul>' . $content . '</ul>';
87 }
88 }