]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/factories/web/class_WebNewsFactory.php
A lot rewrites and fixes for weak redirect methods
[shipsimu.git] / inc / classes / main / factories / web / class_WebNewsFactory.php
index 032f3ceb8f0b830ac3e0f04ce58bae170fabb370..1dace4e9592cabd166f2636b95e1e96a40325cc6 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -21,7 +21,7 @@
  * 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 NewsFactory extends BaseFactory {
+class WebNewsFactory extends BaseFactory {
        /**
         * Instance of a request class
         */
@@ -35,9 +35,6 @@ class NewsFactory extends BaseFactory {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
-
-               // Set part description
-               $this->setObjectDescription("News-Fabrik f&uuml;r Webseiten");
        }
 
        /**
@@ -45,70 +42,40 @@ class NewsFactory extends BaseFactory {
         * request
         *
         * @param       $requestInstance        An instance of a request class
-        * @return      $factoryInstance        An instance of a NewsFactory class
+        * @return      $factoryInstance        An instance of a WebNewsFactory class
         */
        public final static function createFactoryByRequest (Requestable $requestInstance) {
-               // Generate the new instance
-               $factoryInstance = new NewsFactory();
-
-               // Get the element name from configuration
-               $element = FrameworkConfiguration::getInstance()->readConfig('app_selector_get');
+               // Set default news reader class
+               $configEntry = "news_reader_class";
 
-               // Analyze the request, first get the Uni* application name (short one from URL)
-               $appName = $requestInstance->getRequestElement($element);
+               // Get "page"
+               $page = $requestInstance->getRequestElement('page');
 
-               // Initialize some variables
-               $className = "";
-               $className2 = $appName;
+               // Is "page" used?
+               if (!empty($page)) {
+                       // Then add it
+                       $configEntry = sprintf("news_reader_%s_class", $page);
 
-               // Then construct the class name
-               foreach (array("_", "-") as $exp) {
-                       $array = explode($exp, $className2);
-                       foreach ($array as $el) {
-                               $className .= ucfirst(strtolower($el));
-                       }
+                       // Get "action"
+                       $action = $requestInstance->getRequestElement('action');
 
-                       // Copy it back and clear the class name
-                       $className2 = $className;
-                       $className = "";
-               }
+                       // Is it also there?
+                       if (!empty($action)) {
+                               // Then use both for config entry
+                               $configEntry = sprintf("news_reader_%s_%s_class", $page, $action);
+                       } // END - if
+               } // END - if
 
-               // After all is done, copy it back and add this class' name
-               $className = $className2 . $factoryInstance->__toString();
+               // Get the news reader class name from config
+               $className = $requestInstance->getConfigInstance()->readConfig($configEntry);
 
                // Once we have that name, try to load initialize it
-               $realFactoryInstance = ObjectFactory::createObjectByName($className);
+               $newsInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
 
-               // And assign it with the factory
-               $factoryInstance->setRealFactoryInstance($realFactoryInstance);
-
-               // Remember the request we have used for later usage
-               $factoryInstance->setRequestInstance($requestInstance);
+               // Initialize the reader
+               $newsInstance->initializeReader();
 
                // Return the prepared factory instance
-               return $factoryInstance;
-       }
-
-       /**
-        * Setter for the request instance
-        *
-        * @param       $requestInstance        An instance of a request object
-        * @return      void
-        */
-       public final function setRequestInstance (Requestable $requestInstance) {
-               $this->requestInstance = $requestInstance;
-       }
-
-       /**
-        * Creates a new object instance and returns it
-        *
-        * @return      $newsInstance   An instance of a news object
-        */
-       public function createNewsObject () {
-               // Ask the real factory class for doing this
-               $newsInstance = $this->getRealFactoryInstance()->createNewObject($this->requestInstance);
-
-               // And return it
                return $newsInstance;
        }
 }