3 * A command for the login area (member/gamer area)
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.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__);
41 * Creates an instance of this class
43 * @param $resolverInstance An instance of a command resolver class
44 * @return $commandInstance An instance a prepared command class
46 public static final function createWebLoginAreaCommand (CommandResolver $resolverInstance) {
48 $commandInstance = new WebLoginAreaCommand();
50 // Set the application instance
51 $commandInstance->setResolverInstance($resolverInstance);
53 // Load general data like user status and such
54 $commandInstance->prepareCommand();
56 // Return the prepared instance
57 return $commandInstance;
61 * Prepares some general data which shall be displayed on every page
64 * @todo Add some stuff here: Some personal data, app/game related data
66 protected function prepareCommand () {
70 * Executes the given command with given request and response objects
72 * @param $requestInstance An instance of a class with an Requestable interface
73 * @param $responseInstance An instance of a class with an Responseable interface
76 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
77 // Get the action instance from registry
78 $actionInstance = Registry::getRegistry()->getInstance('action');
80 // Do we have an action here?
81 if ($actionInstance instanceof PerformableAction) {
82 // Execute the action (shall not output anything, see below why)
83 $actionInstance->execute($requestInstance, $responseInstance);
86 // Get the application instance
87 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
89 // Prepare a template instance
90 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
93 $templateInstance->assignConfigVariable('base_url');
95 // Assign all the application's data with template variables
96 $templateInstance->assignApplicationData($applicationInstance);
98 // Load the master template
99 $masterTemplate = $applicationInstance->buildMasterTemplateName();
101 // Load header template
102 $templateInstance->loadCodeTemplate('header');
104 // Compile and assign it with a variable
105 $templateInstance->compileTemplate();
106 $templateInstance->assignTemplateWithVariable('header', 'header');
108 // Load footer template
109 $templateInstance->loadCodeTemplate('footer');
111 // Compile and assign it with a variable
112 $templateInstance->compileTemplate();
113 $templateInstance->assignTemplateWithVariable('footer', 'footer');
115 // Load the matching template
116 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
118 // Assign the template with the master template as a content ... ;)
119 $templateInstance->compileTemplate();
120 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
122 // Load main template
123 $templateInstance->loadCodeTemplate('login_main');
125 // Assign the main template with the master template as a content ... ;)
126 $templateInstance->compileTemplate();
127 $templateInstance->assignTemplateWithVariable('login_main', 'content');
129 // Load the master template
130 $templateInstance->loadCodeTemplate($masterTemplate);
133 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
135 // Construct the menu in every command. We could do this in BaseCommand class. But this means
136 // *every* command has a navigation system and that is want we don't want.
137 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
140 $menuInstance->renderMenu();
142 // Transfer it to the template engine instance
143 $menuInstance->transferContentToTemplateEngine($templateInstance);
146 * ... and all variables. This should be merged together in a pattern
147 * to make things easier. A cache mechanism should be added between
148 * these two calls to cache compiled templates.
150 $templateInstance->compileVariables();
152 // Get the content back from the template engine and put it in response class
153 $templateInstance->transferToResponse($responseInstance);
157 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
159 * @param $controllerInstance A controller instance
160 * @param $requestInstance An instance of a class with an Requestable interface
163 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
164 // Default is no action
165 $actionInstance = NULL;
168 $registryInstance = Registry::getRegistry();
170 // Get our application instance from the registry
171 $applicationInstance = $registryInstance->getInstance('application');
173 // Default action is the one from configuration
174 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action');
176 // Get "action" from request
177 $actReq = $requestInstance->getRequestElement('action');
179 // Do we have a "action" parameter set?
180 if ((is_string($actReq)) && (!empty($actReq))) {
181 // Then use it with prefix
182 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
185 // Get application instance
186 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
189 $actionResolver = WebActionResolver::createWebActionResolver($this->actionName, $applicationInstance);
191 // Resolve the action
192 $actionInstance = $actionResolver->resolveAction();
194 // Add more action-specific filters
195 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
197 // Remember this action in registry
198 Registry::getRegistry()->addInstance('action', $actionInstance);