af937575f8817db27ead3d6fbcd4bb53ddbbe5cd
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / ListController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Susanne Moog, <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Controller for extension listings (TER or local extensions)
31 *
32 * @author Susanne Moog <typo3@susannemoog.de>
33 * @package Extension Manager
34 * @subpackage Controller
35 */
36 class ListController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController {
37
38 /**
39 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
40 */
41 protected $extensionRepository;
42
43 /**
44 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
45 */
46 protected $listUtility;
47
48 /**
49 * Dependency injection of the Extension Repository
50 *
51 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
52 * @return void
53 */
54 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository) {
55 $this->extensionRepository = $extensionRepository;
56 }
57
58 /**
59 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
60 * @return void
61 */
62 public function injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility) {
63 $this->listUtility = $listUtility;
64 }
65
66 /**
67 * @var \TYPO3\CMS\Core\Page\PageRenderer
68 */
69 protected $pageRenderer;
70
71 /**
72 * @param \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer
73 * @return void
74 */
75 public function injectPageRenderer(\TYPO3\CMS\Core\Page\PageRenderer $pageRenderer) {
76 $this->pageRenderer = $pageRenderer;
77 }
78
79 /**
80 * Shows list of extensions present in the system
81 *
82 * @return void
83 */
84 public function indexAction() {
85 $this->pageRenderer->addJsFile('../t3lib/js/extjs/notifications.js');
86 $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
87 $this->pageRenderer->addJsFile(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('lang') . 'res/js/be/typo3lang.js');
88 $availableExtensions = $this->listUtility->getAvailableExtensions();
89 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($availableExtensions);
90 $availableAndInstalledExtensions = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
91 $this->view->assign('extensions', $availableAndInstalledExtensions);
92 }
93
94 /**
95 * Shows extensions from TER
96 * Either all extensions or depending on a search param
97 *
98 * @return void
99 */
100 public function terAction() {
101 $this->pageRenderer->addJsFile('../t3lib/js/extjs/notifications.js');
102 $search = $this->getSearchParam();
103 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
104 if (is_string($search) && !empty($search)) {
105 $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
106 } else {
107 $extensions = $this->extensionRepository->findAll();
108 }
109 $this->view->assign('extensions', $extensions)->assign('search', $search)->assign('availableAndInstalled', $availableAndInstalledExtensions);
110 }
111
112 /**
113 * Shows all versions of a specific extension
114 *
115 * @return void
116 */
117 public function showAllVersionsAction() {
118 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/notifications.js');
119 $extensions = array();
120 $extensionKey = '';
121 if ($this->request->hasArgument('allVersions') && $this->request->getArgument('allVersions') == 1 && $this->request->hasArgument('extensionKey') && is_string($this->request->getArgument('extensionKey'))) {
122 $extensionKey = $this->request->getArgument('extensionKey');
123 $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
124 } else {
125 $this->redirect('ter');
126 }
127 $this->view->assign('extensions', $extensions)->assign('extensionKey', $extensionKey);
128 }
129
130 /**
131 * Gets the search parameter either from the url or out
132 * of the session if present
133 *
134 * @return string
135 */
136 public function getSearchParam() {
137 $search = '';
138 if ($this->request->hasArgument('search') && is_string($this->request->getArgument('search'))) {
139 $search = $this->request->getArgument('search');
140 }
141 return $search;
142 }
143
144 /**
145 * Gets instance of template if exists or create a new one.
146 * Saves instance in viewHelperVariableContainer
147 *
148 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate $doc
149 */
150 public function getDocInstance() {
151 if (!isset($GLOBALS['SOBE']->doc)) {
152 $GLOBALS['SOBE']->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
153 $GLOBALS['SOBE']->doc->backPath = $GLOBALS['BACK_PATH'];
154 }
155 return $GLOBALS['SOBE']->doc;
156 }
157
158 }
159
160
161 ?>