]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/commands/web/class_WebLoginAreaCommand.php
Logout procedure basicly finished, login area splitted in main and action-dependent...
[shipsimu.git] / inc / classes / main / commands / web / class_WebLoginAreaCommand.php
index d5f45ec598d9ab404eb4048ad41e4896bf862a03..ac26849836c375393d5161fe223512a607b89242 100644 (file)
@@ -32,7 +32,7 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable {
                parent::__construct(__CLASS__);
 
                // Set special description
-               $this->setObjectDescription("Command for the "home" page");
+               $this->setObjectDescription("Command for the "login area" page");
 
                // Create unique ID number
                $this->generateUniqueId();
@@ -54,10 +54,22 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable {
                // Set the application instance
                $commandInstance->setResolverInstance($resolverInstance);
 
+               // Load general data like user status and such
+               $commandInstance->prepareCommand();
+
                // Return the prepared instance
                return $commandInstance;
        }
 
+       /**
+        * Prepares some general data which shall be displayed on every page
+        *
+        * @return      void
+        */
+       protected function prepareCommand () {
+               /* @TODO Add some stuff here: Some personal data, app/game related data */
+       }
+
        /**
         * Executes the given command with given request and response objects
         *
@@ -67,14 +79,34 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable {
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Default action is the one from configuration
+               $actionClass = sprintf("login_%s_action_class", $this->getConfigInstance()->readConfig('login_default_action'));
                $action = sprintf("login_%s", $this->getConfigInstance()->readConfig('login_default_action'));
 
+               // Get "action" from request
+               $actReq = $requestInstance->getRequestElement('action');
+
+               // Do we have a "action" parameter set?
+               if (is_string($actReq)) {
+                       // Then use it with prefix
+                       $actionClass = sprintf("login_%s_action_class", $actReq);
+                       $action = sprintf("login_%s", $actReq);
+               } // END - if
+
+               // Get an action instance
+               $actionInstance = ObjectFactory::createObjectByConfiguredName($actionClass);
+
+               // Execute the action (shall not output anything, see below why)
+               $actionInstance->execute($requestInstance, $responseInstance);
+
                // Get the application instance
                $appInstance = $this->getResolverInstance()->getApplicationInstance();
 
                // Prepare a template instance
                $templateInstance = $this->prepareTemplateEngine($appInstance);
 
+               // Assign all the application's data with template variables
+               $templateInstance->assignApplicationData($appInstance);
+
                // Load the master template
                $masterTemplate = $appInstance->getMasterTemplate();
 
@@ -92,28 +124,26 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable {
                $templateInstance->compileTemplate();
                $templateInstance->assignTemplateWithVariable("footer", "footer");
 
-               // Get "action" from request
-               $actReq = $requestInstance->getRequestElement("action");
-
-               // Do we have a "action" parameter set?
-               if (is_string($actReq)) {
-                       // Then use it with prefix
-                       $action = sprintf("login_%s", $actReq);
-               } // END - if
-
-               // TODO Do the action somewhere here
-
                // Load the matching template
                $templateInstance->loadCodeTemplate($action);
 
                // Assign the template with the master template as a content ... ;)
-               $templateInstance->assignTemplateWithVariable($action, "content");
+               $templateInstance->assignTemplateWithVariable($action, "login_content");
+
+               // Load main template
+               $templateInstance->loadCodeTemplate("login_main");
+
+               // Assign the main template with the master template as a content ... ;)
+               $templateInstance->assignTemplateWithVariable("login_main", "content");
 
                // Load the master template
                $templateInstance->loadCodeTemplate($masterTemplate);
 
                // Set title
-               $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('login_{$action}_title'));
+               $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($action."_title"));
+
+               // Assign base URL
+               $templateInstance->assignConfigVariable('base_url');
 
                // ... and all variables. This should be merged together in a pattern
                // to make things easier. A cache mechanism should be added between