[TASK] Remove blank line between docblock and the documented element
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / ViewHelpers / AvatarViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Backend\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\Backend\Avatar\Avatar;
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
20 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
21
22 /**
23 * Get avatar for backend user
24 */
25 class AvatarViewHelper extends AbstractViewHelper implements CompilableInterface
26 {
27 /**
28 * Resolve user avatar from backend user id.
29 *
30 * @param int $backendUser Uid of the user
31 * @param int $size width and height of the image
32 * @param bool $showIcon show the record icon
33 * @return string html image tag
34 */
35 public function render($backendUser = 0, $size = 32, $showIcon = false)
36 {
37 return static::renderStatic(
38 array(
39 'backendUser' => $backendUser,
40 'size' => $size,
41 'showIcon' => $showIcon
42 ),
43 $this->buildRenderChildrenClosure(),
44 $this->renderingContext
45 );
46 }
47
48 /**
49 * Resolve user avatar from backend user id.
50 *
51 * @param array $arguments
52 * @param \Closure $renderChildrenClosure
53 * @param RenderingContextInterface $renderingContext
54 * @return string
55 */
56 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
57 {
58 if ($arguments['backendUser'] > 0) {
59 $backendUser = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'be_users', 'uid=' . (int)$arguments['backendUser']);
60 } else {
61 $backendUser = $GLOBALS['BE_USER']->user;
62 }
63 /** @var Avatar $avatar */
64 $avatar = GeneralUtility::makeInstance(Avatar::class);
65 return $avatar->render($backendUser, $arguments['size'], $arguments['showIcon']);
66 }
67 }