Commit 4b437fcf authored by speedprogs_de's avatar speedprogs_de

fixed comments, added extension manager provider, added abstract controller,...

fixed comments, added extension manager provider, added abstract controller, added abstract repository

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51398 735d13b6-9817-0410-8766-e36946ffe9aa
parent afade191
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract controller
*/
abstract class Tx_TerFe2_Controller_AbstractController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* Pre-parse TypoScript setup
*
* @return void
*/
public function initializeAction() {
// Pre-parse settings
$this->settings = Tx_TerFe2_Utility_TypoScript::parse($this->settings);
// Initialize the controller
$this->initialize();
}
/**
* Override in concrete controller to initialize it
*
* @return void
*/
protected function initialize() {
}
/**
* Translate a label
*
* @param string $label Label to translate
* @param array $arguments Optional arguments array
* @return string Translated label
*/
protected function translate($label, array $arguments = array()) {
$extensionKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extensionKey, $arguments);
}
}
?>
\ No newline at end of file
......@@ -25,12 +25,8 @@
/**
* Controller for the Author object
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Controller_AuthorController extends Tx_Extbase_MVC_Controller_ActionController {
class Tx_TerFe2_Controller_AuthorController extends Tx_TerFe2_Controller_AbstractController {
/**
* @var Tx_TerFe2_Domain_Repository_AuthorRepository
......@@ -39,15 +35,12 @@
/**
* Initializes the current action
* Initializes the controller
*
* @return void
*/
protected function initializeAction() {
protected function initialize() {
$this->authorRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_AuthorRepository');
// Pre-parse TypoScript setup
$this->settings = Tx_TerFe2_Utility_TypoScript::parse($this->settings);
}
......
......@@ -25,12 +25,8 @@
/**
* Controller for the Category object
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Controller_CategoryController extends Tx_Extbase_MVC_Controller_ActionController {
class Tx_TerFe2_Controller_CategoryController extends Tx_TerFe2_Controller_AbstractController {
/**
* @var Tx_TerFe2_Domain_Repository_CategoryRepository
......@@ -39,15 +35,12 @@
/**
* Initializes the current action
* Initializes the controller
*
* @return void
*/
protected function initializeAction() {
protected function initialize() {
$this->categoryRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_CategoryRepository');
// Pre-parse TypoScript setup
$this->settings = Tx_TerFe2_Utility_TypoScript::parse($this->settings);
}
......
......@@ -3,7 +3,6 @@
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
* and Thomas Loeffler <loeffler@spooner-web.de>, Spooner Web
*
* All rights reserved
*
......@@ -26,12 +25,8 @@
/**
* Controller for the Extension object
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Controller_ExtensionController extends Tx_Extbase_MVC_Controller_ActionController {
class Tx_TerFe2_Controller_ExtensionController extends Tx_TerFe2_Controller_AbstractController {
/**
* @var Tx_TerFe2_Domain_Repository_ExtensionRepository
......@@ -55,18 +50,15 @@
/**
* Initializes the current action
* Initializes the controller
*
* @return void
*/
protected function initializeAction() {
protected function initialize() {
$this->extensionRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_ExtensionRepository');
$this->categoryRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_CategoryRepository');
$this->tagRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_TagRepository');
$this->authorRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_AuthorRepository');
// Pre-parse TypoScript setup
$this->settings = Tx_TerFe2_Utility_TypoScript::parse($this->settings);
}
......@@ -76,25 +68,25 @@
* @return void
*/
public function indexAction() {
// Get latest extensions
// 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
// 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
// Get all categories
$categories = $this->categoryRepository->findAll();
$this->view->assign('categories', $categories);
// Get all tags
// Get all tags
$tags = $this->tagRepository->findAll();
$this->view->assign('tags', $tags);
// Get random authors
// Get random authors
$randomAuthorCount = (!empty($this->settings['randomAuthorCount']) ? $this->settings['randomAuthorCount'] : 10);
$randomAuthors = $this->authorRepository->findRandom($randomAuthorCount);
$this->view->assign('randomAuthors', $randomAuthors);
......@@ -229,7 +221,7 @@
* @return void
*/
public function createVersionAction(Tx_TerFe2_Domain_Model_Extension $extension, Tx_TerFe2_Domain_Model_Version $newVersion) {
// Get file hash
// Get file hash
$fileName = t3lib_div::getFileAbsFileName($newVersion->getFilename());
$fileHash = Tx_TerFe2_Utility_Files::getFileHash($fileName);
......@@ -254,39 +246,39 @@
* @return void
*/
public function downloadAction(Tx_TerFe2_Domain_Model_Version $version, $format = 't3x') {
// Load Extension Provider
// Load Extension Provider
$objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
$extensionProvider = $objectManager->get('Tx_TerFe2_ExtensionProvider_ExtensionProvider');
// Get URL to file
// Get URL to file
$urlToFile = $extensionProvider->getExtensionFile($version);
if (empty($urlToFile)) {
$this->flashMessageContainer->add($this->translate('msg.file_not_found'));
$this->redirect('index');
}
// Check file hash
// Check file hash
$fileHash = Tx_TerFe2_Utility_Files::getFileHash($urlToFile);
if ($fileHash != $version->getFileHash()) {
$this->flashMessageContainer->add($this->translate('msg.file_hash_not_equal'));
$this->redirect('index');
}
// Check session if user has already downloaded this file today
// Check session if user has already downloaded this file today
$extensionKey = $version->getExtension()->getExtKey();
Tx_TerFe2_Utility_Session::load();
if (!Tx_TerFe2_Utility_Session::hasDownloaded($extensionKey)) {
// Add +1 to download counter
// Add +1 to download counter
$version->incrementDownloadCounter();
$persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();
// Add extension key to session
// Add extension key to session
Tx_TerFe2_Utility_Session::addDownload($extensionKey);
Tx_TerFe2_Utility_Session::save();
}
// Send file to browser
// Send file to browser
$newFileName = $extensionProvider->getExtensionFileName($version, $format);
if (strcasecmp($format, 'zip')) {
$urlToFile = Tx_TerFe2_Utility_Zip::convertT3xToZip($urlToFile);
......
......@@ -25,12 +25,8 @@
/**
* Controller for the Tag object
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Controller_TagController extends Tx_Extbase_MVC_Controller_ActionController {
class Tx_TerFe2_Controller_TagController extends Tx_TerFe2_Controller_AbstractController {
/**
* @var Tx_TerFe2_Domain_Repository_TagRepository
......@@ -45,15 +41,12 @@
/**
* Initializes the current action
* Initializes the controller
*
* @return void
*/
protected function initializeAction() {
protected function initialize() {
$this->tagRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_TagRepository');
// Pre-parse TypoScript setup
$this->settings = Tx_TerFe2_Utility_TypoScript::parse($this->settings);
}
......
......@@ -25,10 +25,6 @@
/**
* Author of an extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Author extends Tx_Extbase_DomainObject_AbstractEntity {
......
......@@ -25,10 +25,6 @@
/**
* Frontend category of the extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Category extends Tx_Extbase_DomainObject_AbstractValueObject {
......
......@@ -25,10 +25,6 @@
/**
* User experience with an extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Experience extends Tx_Extbase_DomainObject_AbstractValueObject {
......
......@@ -3,7 +3,6 @@
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
* and Thomas Loeffler <loeffler@spooner-web.de>, Spooner Web
*
* All rights reserved
*
......@@ -26,65 +25,61 @@
/**
* Extension container
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Extension extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* extKey
* Extension key
* @var string
* @validate NotEmpty
*/
protected $extKey;
/**
* forgeLink
* Link to forge project
* @var string
*/
protected $forgeLink;
/**
* hudsonLink
* Link to hudson
* @var string
*/
protected $hudsonLink;
/**
* lastUpdate
* Last update
* @var DateTime
*/
protected $lastUpdate;
/**
* categories
* Categories
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Category>
*/
protected $categories;
/**
* tags
* Tags
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Tag>
*/
protected $tags;
/**
* versions
* Versions
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_TerFe2_Domain_Model_Version>
* @lazy
*/
protected $versions;
/**
* lastVersion
* Last version
* @var Tx_TerFe2_Domain_Model_Version
*/
protected $lastVersion;
/**
* frontendUser
* Frontend user
* @var Tx_Extbase_Domain_Model_FrontendUser
*/
protected $frontendUser;
......@@ -306,7 +301,7 @@
$curVersionNumber = (int) $this->lastVersion->getVersionNumber();
$newVersionNumber = (int) $lastVersion->getVersionNumber();
// Add lastVersion only if newer
// Add lastVersion only if newer
if ($newVersionNumber > $curVersionNumber) {
$this->lastVersion = $lastVersion;
}
......
......@@ -25,10 +25,6 @@
/**
* Any type of media associated to an extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Media extends Tx_Extbase_DomainObject_AbstractEntity {
......
......@@ -3,7 +3,6 @@
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
* and Thomas Loeffler <loeffler@spooner-web.de>, Spooner Web
*
* All rights reserved
*
......@@ -26,10 +25,6 @@
/**
* Any type of relation of an extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Relation extends Tx_Extbase_DomainObject_AbstractValueObject {
......@@ -48,7 +43,7 @@
protected $softwareType;
/**
* extension key, php, mysql or something else
* Extension key, php, mysql or something else
* @var string
* @validate NotEmpty
*/
......
......@@ -25,10 +25,6 @@
/**
* Tag for the extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Tag extends Tx_Extbase_DomainObject_AbstractValueObject {
......
......@@ -3,7 +3,6 @@
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
* and Thomas Loeffler <loeffler@spooner-web.de>, Spooner Web
*
* All rights reserved
*
......@@ -26,10 +25,6 @@
/**
* Single version of an extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Model_Version extends Tx_Extbase_DomainObject_AbstractEntity {
......
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract repository
*/
abstract class Tx_TerFe2_Domain_Repository_AbstractRepository extends Tx_Extbase_Persistence_Repository {
/**
* Returns random objects from db
*
* @param integer $limit Limit of the results
* @return Tx_Extbase_Persistence_QueryResult Query result
*/
public function findRandom($limit) {
$query = $this->createQuery();
$query->setLimit((int) $limit);
// Workaround for random ordering until Extbase doesn't support this yet
// See: http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2010-July/005870.html
$backend = $this->objectManager->get('Tx_Extbase_Persistence_Storage_Typo3DbBackend');
$parameters = array();
$statementParts = $backend->parseQuery($query, $parameters);
$statementParts['orderings'][] = ' RAND()';
$statement = $backend->buildQuery($statementParts, $parameters);
$query->statement($statement, $parameters);
return $query->execute();
}
}
?>
\ No newline at end of file
......@@ -25,33 +25,8 @@
/**
* Repository for Tx_TerFe2_Domain_Model_Author
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Repository_AuthorRepository extends Tx_Extbase_Persistence_Repository {
/**
* Returns random authors
*
* @param integer $randomAuthorCount Count of authors
* @return array An array of extensions
*/
public function findRandom($randomAuthorCount) {
$query = $this->createQuery();
$query->setLimit((int) $randomAuthorCount);
// Workaround for random ordering until Extbase doesn't support this
// See: http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2010-July/005870.html
$backend = $this->objectManager->get('Tx_Extbase_Persistence_Storage_Typo3DbBackend');
$parameters = array();
$statementParts = $backend->parseQuery($query, $parameters);
$statementParts['orderings'][] = ' RAND()';
$statement = $backend->buildQuery($statementParts, $parameters);
$query->statement($statement, $parameters);
class Tx_TerFe2_Domain_Repository_AuthorRepository extends Tx_TerFe2_Domain_Repository_AbstractRepository {
return $query->execute();
}
}
?>
\ No newline at end of file
......@@ -25,12 +25,8 @@
/**
* Repository for Tx_TerFe2_Domain_Model_Category
*
* @version $Id$
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_TerFe2_Domain_Repository_CategoryRepository extends Tx_Extbase_Persistence_Repository {
class Tx_TerFe2_Domain_Repository_CategoryRepository extends Tx_TerFe2_Domain_Repository_AbstractRepository {
}
?>
\ No newline at end of file
......@@ -3,7 +3,6 @@
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
* and Thomas Loeffler <loeffler@spooner-web.de>, Spooner Web
*
* All rights reserved
*
......@@ -26,12 +25,8 @@
/**
* Repository for Tx_TerFe2_Domain_Model_Extension
*
* @version $Id$
* @copyright Copyright belongs to the respective authors