3 namespace Org\Mxchange\City\Command;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Controller\Controller;
7 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
8 use Org\Mxchange\CoreFramework\Request\Requestable;
9 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
10 use Org\Mxchange\CoreFramework\Response\Responseable;
13 * A command for the login area (member/gamer area)
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2015, 2016 City Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable {
38 private $actionName = '';
41 * Protected constructor
45 protected function __construct () {
46 // Call parent constructor
47 parent::__construct(__CLASS__);
51 * Creates an instance of this class
53 * @param $resolverInstance An instance of a command resolver class
54 * @return $commandInstance An instance a prepared command class
56 public static final function createCityHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
58 $commandInstance = new CityHtmlLoginAreaCommand();
60 // Set the application instance
61 $commandInstance->setResolverInstance($resolverInstance);
63 // Load general data like user status and such
64 $commandInstance->prepareCommand();
66 // Return the prepared instance
67 return $commandInstance;
71 * Prepares some general data which shall be displayed on every page
74 * @todo Add some stuff here: Some personal data, app/game related data
76 protected function prepareCommand () {
80 * Executes the given command with given request and response objects
82 * @param $requestInstance An instance of a class with an Requestable interface
83 * @param $responseInstance An instance of a class with an Responseable interface
86 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
87 // Get the action instance from registry
88 $actionInstance = GenericRegistry::getRegistry()->getInstance('action');
90 // Do we have an action here?
91 if ($actionInstance instanceof PerformableAction) {
92 // Execute the action (shall not output anything, see below why)
93 $actionInstance->execute($requestInstance, $responseInstance);
96 // Get the application instance
97 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
99 // Prepare a template instance
100 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
103 $templateInstance->assignConfigVariable('base_url');
105 // Assign all the application's data with template variables
106 $templateInstance->assignApplicationData();
108 // Load the master template
109 $masterTemplate = $applicationInstance->buildMasterTemplateName();
111 // Load header template
112 $templateInstance->loadCodeTemplate('header');
114 // Compile and assign it with a variable
115 $templateInstance->compileTemplate();
116 $templateInstance->assignTemplateWithVariable('header', 'header');
118 // Load footer template
119 $templateInstance->loadCodeTemplate('footer');
121 // Compile and assign it with a variable
122 $templateInstance->compileTemplate();
123 $templateInstance->assignTemplateWithVariable('footer', 'footer');
125 // Load the matching template
126 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
128 // Assign the template with the master template as a content ... ;)
129 $templateInstance->compileTemplate();
130 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
132 // Load main template
133 $templateInstance->loadCodeTemplate('login_main');
135 // Assign the main template with the master template as a content ... ;)
136 $templateInstance->compileTemplate();
137 $templateInstance->assignTemplateWithVariable('login_main', 'main_content');
139 // Load the master template
140 $templateInstance->loadCodeTemplate($masterTemplate);
143 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
145 // Construct the menu in every command. We could do this in BaseCommand class. But this means
146 // *every* command has a navigation system and that is want we don't want.
147 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
150 $menuInstance->renderMenu();
152 // Transfer it to the template engine instance
153 $menuInstance->transferContentToTemplateEngine($templateInstance);
156 * ... and all variables. This should be merged together in a pattern
157 * to make things easier. A cache mechanism should be added between
158 * these two calls to cache compiled templates.
160 $templateInstance->compileVariables();
162 // Get the content back from the template engine and put it in response class
163 $templateInstance->transferToResponse($responseInstance);
167 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
169 * @param $controllerInstance A controller instance
170 * @param $requestInstance An instance of a class with an Requestable interface
173 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
174 // Default is no action
175 $actionInstance = NULL;
178 $registryInstance = GenericRegistry::getRegistry();
180 // Get our application instance from the registry
181 $applicationInstance = $registryInstance->getInstance('application');
183 // Default action is the one from configuration
184 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action');
186 // Get "action" from request
187 $actReq = $requestInstance->getRequestElement('action');
189 // Do we have a "action" parameter set?
190 if ((is_string($actReq)) && (!empty($actReq))) {
191 // Then use it with prefix
192 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
196 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName);
198 // Resolve the action
199 $actionInstance = $actionResolver->resolveAction();
201 // Add more action-specific filters
202 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
204 // Remember this action in registry
205 GenericRegistry::getRegistry()->addInstance('action', $actionInstance);