inc/classes/main/points/.htaccess -text
inc/classes/main/points/class_UserPoints.php -text
inc/classes/main/reader/.htaccess -text
+inc/classes/main/reader/class_ConsoleNewsReader.php -text
inc/classes/main/reader/class_DefaultNewsReader.php -text
inc/classes/main/registration/.htaccess -text
inc/classes/main/registration/class_BaseRegistration.php -text
*/
public final static function createFactoryByRequest (Requestable $requestInstance) {
// Set default news reader class
- $configEntry = "news_reader_class";
+ $configEntry = 'news_reader_class';
// Get "page"
$page = $requestInstance->getRequestElement('page');
--- /dev/null
+<?php
+/**
+ * A default news reader class reads news from database layer
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Clean up a little
+ $this->removeNumberFormaters();
+ $this->removeSystemArray();
+ }
+
+ /**
+ * Creates an instance of this reader by a provided request instance
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $readerInstance An instance of this reader class
+ */
+ public final static function createDefaultNewsReader (Requestable $requestInstance) {
+ // Get a new instance
+ $readerInstance = new DefaultNewsReader();
+
+ // Set request instance
+ $readerInstance->setRequestInstance($requestInstance);
+
+ // Return prepared instance
+ return $readerInstance;
+ }
+
+ /**
+ * Initializes this reader class by pre-fetching news depending on 'page'
+ * (outside or login area), which amount of news and how much to skip
+ *
+ * @return void
+ */
+ public function initializeReader () {
+ // Get 'page' for saving some calls
+ $page = $this->getRequestInstance()->getRequestElement('page');
+
+ // First get a wrapper instance
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('news_db_wrapper_class');
+
+ // Next create a searchable criteria instance
+ $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add the page as criteria to it at lease
+ $criteriaInstance->addCriteria('page', $page);
+
+ // Add limitation from config
+ $criteriaInstance->setLimit($this->getConfigInstance()->readConfig('news_' . $page . '_limit'));
+
+ // Get a resultInstance back from the database
+ $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+ // Save that resultInstance in this class
+ $this->setResultInstance($resultInstance);
+ }
+}
+
+// [EOF]
+?>
}
/**
- * Initializes this reader class by pre-fetching news depending on "page"
+ * Initializes this reader class by pre-fetching news depending on 'page'
* (outside or login area), which amount of news and how much to skip
*
* @return void
*/
public function initializeReader () {
- // Get "page" for saving some calls
+ // Get 'page' for saving some calls
$page = $this->getRequestInstance()->getRequestElement('page');
// First get a wrapper instance
$criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Add the page as criteria to it at lease
- $criteriaInstance->addCriteria("page", $page);
+ $criteriaInstance->addCriteria('page', $page);
// Add limitation from config
- $criteriaInstance->setLimit($this->getConfigInstance()->readConfig("news_{$page}_limit"));
+ $criteriaInstance->setLimit($this->getConfigInstance()->readConfig('news_' . $page . '_limit'));
// Get a resultInstance back from the database
$resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
$commandInstance = null;
// This goes fine so let's resolve the command
- $commandName = $requestInstance->getRequestElement('page');
+ $commandName = $requestInstance->getRequestElement('command');
// Is the command empty? Then fall back to default command
if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_console_command');
return $this->controllerName;
}
+ /**
+ * "Loads" a given controller and instances it if not yet cached. If the
+ * controller was not found one of the default controllers will be used
+ * depending on wether news shall be displayed.
+ *
+ * @param $controllerName A controller name we shall look for
+ * @return $controllerInstance A loaded controller instance
+ * @throws InvalidControllerException Thrown if even the requested
+ * controller class is missing (bad!)
+ */
+ protected function loadController ($controllerName) {
+ // Cache default command
+ $defaultController = $this->getConfigInstance()->readConfig('default_' . strtolower($this->getControllerPrefix()) . '_command');
+
+ // Init controller instance
+ $controllerInstance = null;
+
+ // Default controller
+ $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+
+ // Generate the class name
+ //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
+ if ($controllerName != $defaultController) {
+ // Create controller class name
+ $className = $this->getControllerPrefix() . '' . $this->convertToClassName($controllerName) . 'Controller';
+
+ // ... and set it
+ $this->setClassName($className);
+ } else {
+ // No news at main command or non-news command
+ $this->setClassName($this->getControllerPrefix() . 'DefaultNewsController');
+ }
+ //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
+
+ // Is this class loaded?
+ if (!class_exists($this->getClassName())) {
+ // Throw an exception here
+ throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ } // END - if
+
+ // Set default resolver config name
+ $resolverConfigEntry = '';
+
+ // Try to read a config entry for our resolver including controller name... ;-)
+ try {
+ // Create the resolver name
+ $resolverConfigEntry = sprintf("%s_cmd_%s_resolver_class", strtolower($this->getControllerPrefix(), strtolower($controllerName));
+
+ // Get the config, this will throw an exception if there is no special command resolver
+ $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
+ } catch (ConfigEntryNotFoundException $e) {
+ // Use default resolver entry
+ // @TODO Maybe we need to log this?
+ $resolverConfigEntry = $this->getControllerPrefix() . '_cmd_resolver_class';
+ }
+
+ // Initiate the resolver and controller
+ $resolverInstance = ObjectFactory::createObjectByConfiguredName(
+ $resolverConfigEntry,
+ array(
+ $controllerName,
+ $this->getApplicationInstance()
+ )
+ );
+ $controllerInstance = ObjectFactory::createObjectByName(
+ $this->getClassName(),
+ array($resolverInstance)
+ );
+
+ // Return the result
+ return $controllerInstance;
+ }
+
/**
* Checks wether the given controller is valid
*
// Return the maybe resolved instance
return $controllerInstance;
}
-
- /**
- * "Loads" a given controller and instances it if not yet cached. If the
- * controller was not found one of the default controllers will be used
- * depending on wether news shall be displayed.
- *
- * @param $controllerName A controller name we shall look for
- * @return $controllerInstance A loaded controller instance
- * @throws InvalidControllerException Thrown if even the requested
- * controller class is missing (bad!)
- */
- private function loadController ($controllerName) {
- // Cache default command
- $defaultController = $this->getConfigInstance()->readConfig('default_console_command');
-
- // Init controller instance
- $controllerInstance = null;
-
- // Default controller
- $this->setClassName('ConsoleDefaultNewsController');
-
- // Generate the class name
- //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
- if ($controllerName != $defaultController) {
- // Create controller class name
- $className = 'Console' . $this->convertToClassName($controllerName) . 'Controller';
-
- // ... and set it
- $this->setClassName($className);
- } else {
- // No news at main command or non-news command
- $this->setClassName('ConsoleDefaultNewsController');
- }
- //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
-
- // Is this class loaded?
- if (!class_exists($this->getClassName())) {
- // Throw an exception here
- throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
-
- // Set default resolver config name
- $resolverConfigEntry = '';
-
- // Try to read a config entry for our resolver including controller name... ;-)
- try {
- // Create the resolver name
- $resolverConfigEntry = sprintf("console_cmd_%s_resolver_class", strtolower($controllerName));
-
- // Get the config, this will throw an exception if there is no special command resolver
- $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
- } catch (ConfigEntryNotFoundException $e) {
- // Use default resolver entry
- // @TODO Maybe we need to log this?
- $resolverConfigEntry = 'console_cmd_resolver_class';
- }
-
- // Initiate the resolver and controller
- $resolverInstance = ObjectFactory::createObjectByConfiguredName(
- $resolverConfigEntry,
- array(
- $controllerName,
- $this->getApplicationInstance()
- )
- );
- $controllerInstance = ObjectFactory::createObjectByName(
- $this->getClassName(),
- array($resolverInstance)
- );
-
- // Return the result
- return $controllerInstance;
- }
}
// [EOF]
// Return the maybe resolved instance
return $controllerInstance;
}
-
- /**
- * "Loads" a given controller and instances it if not yet cached. If the
- * controller was not found one of the default controllers will be used
- * depending on wether news shall be displayed.
- *
- * @param $controllerName A controller name we shall look for
- * @return $controllerInstance A loaded controller instance
- * @throws InvalidControllerException Thrown if even the requested
- * controller class is missing (bad!)
- */
- private function loadController ($controllerName) {
- // Cache default command
- $defaultController = $this->getConfigInstance()->readConfig('default_image_command');
-
- // Init controller instance
- $controllerInstance = null;
-
- // Default controller
- $this->setClassName($defaultController);
-
- // Generate the class name
- //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
- if ($controllerName != $defaultController) {
- // Create controller class name
- $className = 'Image' . $this->convertToClassName($controllerName) . 'Controller';
-
- // ... and set it
- $this->setClassName($className);
- } // END - if
- //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
-
- // Is this class loaded?
- if (!class_exists($this->getClassName())) {
- // Class not found, so or throw an exception
- throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
-
- // Initiate the resolver and controller
- $resolverInstance = ObjectFactory::createObjectByConfiguredName(
- 'image_cmd_resolver_class',
- array(
- $controllerName,
- $this->getApplicationInstance()
- )
- );
- $controllerInstance = ObjectFactory::createObjectByName(
- $this->getClassName(),
- array($resolverInstance)
- );
-
- // Return the result
- return $controllerInstance;
- }
}
// [EOF]
// Return the maybe resolved instance
return $controllerInstance;
}
-
- /**
- * "Loads" a given controller and instances it if not yet cached. If the
- * controller was not found one of the default controllers will be used
- * depending on wether news shall be displayed.
- *
- * @param $controllerName A controller name we shall look for
- * @return $controllerInstance A loaded controller instance
- * @throws InvalidControllerException Thrown if even the requested
- * controller class is missing (bad!)
- */
- private function loadController ($controllerName) {
- // Cache default command
- $defaultController = $this->getConfigInstance()->readConfig('default_web_command');
-
- // Init controller instance
- $controllerInstance = null;
-
- // Default controller
- $this->setClassName('WebDefaultNewsController');
-
- // Generate the class name
- //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
- if ($controllerName != $defaultController) {
- // Create controller class name
- $className = 'Web' . $this->convertToClassName($controllerName) . 'Controller';
-
- // ... and set it
- $this->setClassName($className);
- } else {
- // No news at home page or non-news page
- $this->setClassName('WebDefaultNewsController');
- }
- //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
-
- // Is this class loaded?
- if (!class_exists($this->getClassName())) {
- // Throw an exception here
- throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
-
- // Set default resolver config name
- $resolverConfigEntry = '';
-
- // Try to read a config entry for our resolver including controller name... ;-)
- try {
- // Create the resolver name
- $resolverConfigEntry = sprintf("web_cmd_%s_resolver_class", strtolower($controllerName));
-
- // Get the config, this will throw an exception if there is no special command resolver
- $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
- } catch (ConfigEntryNotFoundException $e) {
- // Use default resolver entry
- // @TODO Maybe we need to log this?
- $resolverConfigEntry = 'web_cmd_resolver_class';
- }
-
- // Initiate the resolver and controller
- $resolverInstance = ObjectFactory::createObjectByConfiguredName(
- $resolverConfigEntry,
- array(
- $controllerName,
- $this->getApplicationInstance()
- )
- );
- $controllerInstance = ObjectFactory::createObjectByName(
- $this->getClassName(),
- array($resolverInstance)
- );
-
- // Return the result
- return $controllerInstance;
- }
}
// [EOF]