3 * A command for the login area (member/gamer area)
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class WebLoginAreaCommand extends BaseCommand implements Commandable {
28 private $actionName = "";
31 * Protected constructor
35 protected function __construct () {
36 // Call parent constructor
37 parent::__construct(__CLASS__);
39 // Set special description
40 $this->setObjectDescription("Command for the "login area" page");
42 // Create unique ID number
43 $this->generateUniqueId();
46 $this->removeSystemArray();
50 * Creates an instance of this class
52 * @param $resolverInstance An instance of a command resolver class
53 * @return $commandInstance An instance a prepared command class
55 public final static function createWebLoginAreaCommand (CommandResolver $resolverInstance) {
57 $commandInstance = new WebLoginAreaCommand();
59 // Set the application instance
60 $commandInstance->setResolverInstance($resolverInstance);
62 // Load general data like user status and such
63 $commandInstance->prepareCommand();
65 // Return the prepared instance
66 return $commandInstance;
70 * Prepares some general data which shall be displayed on every page
74 protected function prepareCommand () {
75 /* @TODO Add some stuff here: Some personal data, app/game related data */
79 * Executes the given command with given request and response objects
81 * @param $requestInstance An instance of a class with an Requestable interface
82 * @param $responseInstance An instance of a class with an Responseable interface
85 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
86 // Get the action instance from registry
87 $actionInstance = Registry::getRegistry()->getInstance('action');
89 // Execute the action (shall not output anything, see below why)
90 $actionInstance->execute($requestInstance, $responseInstance);
92 // Get the application instance
93 $appInstance = $this->getResolverInstance()->getApplicationInstance();
95 // Prepare a template instance
96 $templateInstance = $this->prepareTemplateEngine($appInstance);
99 $templateInstance->assignConfigVariable('base_url');
101 // Assign all the application's data with template variables
102 $templateInstance->assignApplicationData($appInstance);
104 // Load the master template
105 $masterTemplate = $appInstance->getMasterTemplate();
107 // Load header template
108 $templateInstance->loadCodeTemplate("header");
110 // Compile and assign it with a variable
111 $templateInstance->compileTemplate();
112 $templateInstance->assignTemplateWithVariable("header", "header");
114 // Load footer template
115 $templateInstance->loadCodeTemplate("footer");
117 // Compile and assign it with a variable
118 $templateInstance->compileTemplate();
119 $templateInstance->assignTemplateWithVariable("footer", "footer");
121 // Load the matching template
122 $templateInstance->loadCodeTemplate($this->actionName);
124 // Assign the template with the master template as a content ... ;)
125 $templateInstance->compileTemplate();
126 $templateInstance->assignTemplateWithVariable($this->actionName, "login_content");
128 // Load main template
129 $templateInstance->loadCodeTemplate("login_main");
131 // Assign the main template with the master template as a content ... ;)
132 $templateInstance->compileTemplate();
133 $templateInstance->assignTemplateWithVariable("login_main", "content");
135 // Load the master template
136 $templateInstance->loadCodeTemplate($masterTemplate);
139 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName."_title"));
141 // ... and all variables. This should be merged together in a pattern
142 // to make things easier. A cache mechanism should be added between
143 // these two calls to cache compiled templates.
144 //$templateInstance->debugInstance();
145 $templateInstance->compileVariables();
147 // Get the content back from the template engine and put it in the response class
148 $templateInstance->transferToResponse($responseInstance);
152 * Adds extra filters to the given controller instance
154 * @param $controllerInstance A controller instance
155 * @param $requestInstance An instance of a class with an Requestable interface
158 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
159 // Default is no action
160 $actionInstance = null;
162 // Default action is the one from configuration
163 $this->actionName = sprintf("login_%s", $this->getConfigInstance()->readConfig('login_default_action'));
165 // Get "action" from request
166 $actReq = $requestInstance->getRequestElement('action');
168 // Do we have a "action" parameter set?
169 if ((is_string($actReq)) && (!empty($actReq))) {
170 // Then use it with prefix
171 $this->actionName = sprintf("login_%s", $actReq);
174 // Get application instance
175 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
177 // Try to get an action resolver for the given action
180 $actionResolver = WebActionResolver::createWebActionResolver($this->actionName, $applicationInstance);
182 // Resolve the action
183 $actionInstance = $actionResolver->resolveAction();
185 // Add more action-specific filters
186 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
188 // Remember this action in registry
189 Registry::getRegistry()->addInstance('action', $actionInstance);
190 } catch (InvalidActionException $e) {
191 // Silently ignored because no special action was found