Commit c0fb39a7 authored by speedprogs_de's avatar speedprogs_de

added functionality to index and download action of the extension controller

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51666 735d13b6-9817-0410-8766-e36946ffe9aa
parent 80091116
......@@ -64,5 +64,18 @@
return Tx_Extbase_Utility_Localization::translate($label, $extensionKey, $arguments);
}
/**
* Send flash message and redirect to given action
*
* @param string $action Name of the action
* @param string $messageIdentifier Identifier of the message to send
* @return void
*/
protected function redirectWithMessage($action, $messageIdentifier) {
$this->flashMessageContainer->add($this->translate('msg.' . $messageIdentifier));
$this->redirect($action);
}
}
?>
\ No newline at end of file
......@@ -68,7 +68,28 @@
* @return void
*/
public function indexAction() {
// TODO: Implement functionality
// Get latest extensions
$latestCount = (!empty($this->settings['latestCount']) ? $this->settings['latestCount'] : 10);
$latestExtensions = $this->extensionRepository->findNewAndUpdated($latestCount);
$this->view->assign('latestExtensions', $latestExtensions);
// Get top rated extensions
$topRatedCount = (!empty($this->settings['topRatedCount']) ? $this->settings['topRatedCount'] : 10);
$topRatedExtensions = $this->extensionRepository->findTopRated($topRatedCount);
$this->view->assign('topRatedExtensions', $topRatedExtensions);
/*
// Get all categories
$categories = $this->categoryRepository->findAll();
$this->view->assign('categories', $categories);
// Get all tags
$tags = $this->tagRepository->findAll();
$this->view->assign('tags', $tags);
*/
// Get random authors
$randomAuthorCount = (!empty($this->settings['randomAuthorCount']) ? $this->settings['randomAuthorCount'] : 10);
$randomAuthors = $this->authorRepository->findRandom($randomAuthorCount);
$this->view->assign('randomAuthors', $randomAuthors);
}
......@@ -149,8 +170,7 @@
*/
public function createAction(Tx_TerFe2_Domain_Model_Extension $newExtension) {
$this->extensionRepository->add($newExtension);
$this->flashMessageContainer->add($this->translate('msg.extension_created'));
$this->redirect('index');
$this->redirectWithMessage('index', 'extension_created');
}
......@@ -187,20 +207,56 @@
*/
public function deleteAction(Tx_TerFe2_Domain_Model_Extension $extension) {
$this->extensionRepository->remove($extension);
$this->flashMessageContainer->add($this->translate('msg.extension_deleted'));
$this->redirect('index');
$this->redirectWithMessage('index', 'extension_deleted');
}
/**
* Check file hash and increment counter while downloading
* Check file hash, increment download counter and send file to client browser
*
* @param Tx_TerFe2_Domain_Model_Version $newVersion An existing version object
* @param string $format Format of the file output
* @return void
*/
public function downloadAction(Tx_TerFe2_Domain_Model_Version $version, $format = 't3x') {
// TODO: Implement functionality
// Get extension provider
$providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$provider = $providerManager->getProvider($version->getExtensionProvider());
// Get url to file
$fileUrl = $provider->getFileUrl($version, $format);
if (empty($fileUrl)) {
$this->redirectWithMessage('index', 'file_not_found');
}
// Check file hash
$fileHash = Tx_TerFe2_Utility_File::getFileHash($fileUrl);
if ($fileHash != $version->getFileHash()) {
$this->redirectWithMessage('index', 'file_hash_not_equal');
}
// Check session if user has already downloaded this file today
$extensionKey = $version->getExtension()->getExtKey();
$session = $this->objectManager->get('Tx_TerFe2_Persistence_Session');
$downloads = $session->get('downloads');
if (empty($downloads) || !in_array($extensionKey, $downloads)) {
// Add +1 to download counter and save immediately
$version->incrementDownloadCounter();
$persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();
// Add extension key to session
$downloads[] = $extensionKey;
$session->add('downloads', $downloads);
}
// Send file to browser
if (!Tx_TerFe2_Utility_File::transferFile($fileUrl)) {
$this->redirectWithMessage('index', 'could_not_transfer_file');
}
// Fallback
$this->redirect('index');
}
}
......
......@@ -55,6 +55,10 @@
* @return Tx_TerFe2_Provider_ProviderInterface Extension provider
*/
public function getProvider($name) {
if (empty($name)) {
throw new Exception('No empty name allowed for an extension provider');
}
$name = strtolower(trim($name));
if (!empty($this->providers[$name])) {
......
......@@ -44,6 +44,8 @@
'tx_terfe2_utility_array' => $extensionClassesPath . 'Utility/Array.php',
'tx_terfe2_utility_file' => $extensionClassesPath . 'Utility/File.php',
'tx_terfe2_utility_typoscript' => $extensionClassesPath . 'Utility/TypoScript.php',
'Tx_TerFe2_view_extension_listjson' => $extensionClassesPath . 'View/Extension/ListJson.php',
'Tx_TerFe2_view_extension_listlatestjson' => $extensionClassesPath . 'View/Extension/ListLatestJson.php',
'tx_terfe2_viewhelpers_cdataviewhelper' => $extensionClassesPath . 'ViewHelpers/CdataViewHelper.php',
'tx_terfe2_viewhelpers_chartviewhelper' => $extensionClassesPath . 'ViewHelpers/ChartViewHelper.php',
'tx_terfe2_viewhelpers_datetimeviewhelper' => $extensionClassesPath . 'ViewHelpers/DateTimeViewHelper.php',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment