[TASK] Make ViewHelpers compilable in ext:extensionmanager
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / TimeSinceLastUpdateViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\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
17 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
20
21 /**
22 * Shows the elapsed time since the last update of the extension repository
23 * from TER in a readable manner.
24 *
25 * @internal
26 */
27 class TimeSinceLastUpdateViewHelper extends AbstractViewHelper implements CompilableInterface {
28
29 /**
30 * Render method
31 *
32 * @param \DateTime $lastUpdateTime The date of the last update.
33 * @return string
34 */
35 public function render($lastUpdateTime) {
36 return self::renderStatic(
37 array(
38 'lastUpdateTime' => $lastUpdateTime,
39 ),
40 $this->buildRenderChildrenClosure(),
41 $this->renderingContext
42 );
43 }
44
45 /**
46 * @param array $arguments
47 * @param callable $renderChildrenClosure
48 * @param RenderingContextInterface $renderingContext
49 *
50 * @return string
51 */
52 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
53 $lastUpdateTime = $arguments['lastUpdateTime'];
54 if (NULL === $lastUpdateTime) {
55 return $GLOBALS['LANG']->sL(
56 'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.updateFromTer.never'
57 );
58 }
59 return \TYPO3\CMS\Backend\Utility\BackendUtility::calcAge(
60 time() - $lastUpdateTime->format('U'),
61 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')
62 );
63 }
64
65 }