3553c2e37086be7be0e028d8416ac32e136c51a1
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / ViewHelpers / SpriteIconForRecordViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Beuser\ViewHelpers;
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 use TYPO3\CMS\Backend\Utility\IconUtility;
17 use TYPO3\CMS\Extbase\Domain\Model\BackendUser;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
20 use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
21
22 /**
23 * Views sprite icon for a record (object)
24 *
25 * @author Felix Kopp <felix-source@phorax.com>
26 * @internal
27 */
28 class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper implements CompilableInterface {
29
30 /**
31 * Displays spriteIcon for database table and object
32 *
33 * @param string $table
34 * @param object $object
35 * @return string
36 * @see \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($table, $row)
37 */
38 public function render($table, $object) {
39 return self::renderStatic(
40 array(
41 'table' => $table,
42 'object' => $object
43 ),
44 $this->buildRenderChildrenClosure(),
45 $this->renderingContext
46 );
47 }
48
49 /**
50 * @param array $arguments
51 * @param callable $renderChildrenClosure
52 * @param RenderingContextInterface $renderingContext
53 *
54 * @return string
55 * @throws Exception
56 */
57 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
58 $object = $arguments['object'];
59 $table = $arguments['table'];
60
61 if (!is_object($object) || !method_exists($object, 'getUid')) {
62 return '';
63 }
64 $row = array(
65 'uid' => $object->getUid(),
66 'startTime' => FALSE,
67 'endTime' => FALSE
68 );
69 if (method_exists($object, 'getIsDisabled')) {
70 $row['disable'] = $object->getIsDisabled();
71 }
72 if (method_exists($object, 'getHidden')) {
73 $row['hidden'] = $object->getHidden();
74 }
75 if ($table === 'be_users' && $object instanceof BackendUser) {
76 $row['admin'] = $object->getIsAdministrator();
77 }
78 if (method_exists($object, 'getStartDateAndTime')) {
79 $row['startTime'] = $object->getStartDateAndTime();
80 }
81 if (method_exists($object, 'getEndDateAndTime')) {
82 $row['endTime'] = $object->getEndDateAndTime();
83 }
84 return IconUtility::getSpriteIconForRecord($table, $row);
85 }
86
87 }