[TASK] Set TYPO3 version to 7.3-dev
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / Classes / ViewHelpers / WorkspaceTitleViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Belog\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 /**
18 * Get workspace title from workspace id
19 *
20 * @author Christian Kuhn <lolli@schwarzbu.ch>
21 * @internal
22 */
23 class WorkspaceTitleViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
24
25 /**
26 * @var \TYPO3\CMS\Belog\Domain\Repository\WorkspaceRepository
27 * @inject
28 */
29 protected $workspaceRepository = NULL;
30
31 /**
32 * First level cache of workspace titles
33 *
34 * @var array
35 */
36 static protected $workspaceTitleRuntimeCache = array();
37
38 /**
39 * Resolve workspace title from UID.
40 *
41 * @param int $uid UID of the workspace
42 * @return string username or UID
43 */
44 public function render($uid) {
45 if (isset(static::$workspaceTitleRuntimeCache[$uid])) {
46 return static::$workspaceTitleRuntimeCache[$uid];
47 }
48
49 if ($uid === 0) {
50 static::$workspaceTitleRuntimeCache[$uid] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('live', $this->controllerContext->getRequest()->getControllerExtensionName());
51 } elseif (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) {
52 static::$workspaceTitleRuntimeCache[$uid] = '';
53 } else {
54 /** @var $workspace \TYPO3\CMS\Belog\Domain\Model\Workspace */
55 $workspace = $this->workspaceRepository->findByUid($uid);
56 // $workspace may be null, force empty string in this case
57 static::$workspaceTitleRuntimeCache[$uid] = ($workspace === NULL) ? '' : $workspace->getTitle();
58 }
59
60 return static::$workspaceTitleRuntimeCache[$uid];
61 }
62
63 }