3 namespace Org\Mxchange\City\Command;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Controller\Controller;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
9 use Org\Mxchange\CoreFramework\Request\Requestable;
10 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
11 use Org\Mxchange\CoreFramework\Response\Responseable;
14 * A command for the login area (member/gamer area)
16 * @author Roland Haeder <webmaster@shipsimu.org>
18 * @copyright Copyright (c) 2015, 2016 City Developer Team
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.shipsimu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable {
39 private $actionName = '';
42 * Protected constructor
46 protected function __construct () {
47 // Call parent constructor
48 parent::__construct(__CLASS__);
52 * Creates an instance of this class
54 * @param $resolverInstance An instance of a command resolver class
55 * @return $commandInstance An instance a prepared command class
57 public static final function createCityHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
59 $commandInstance = new CityHtmlLoginAreaCommand();
61 // Set the application instance
62 $commandInstance->setResolverInstance($resolverInstance);
64 // Load general data like user status and such
65 $commandInstance->prepareCommand();
67 // Return the prepared instance
68 return $commandInstance;
72 * Prepares some general data which shall be displayed on every page
75 * @todo Add some stuff here: Some personal data, app/game related data
77 protected function prepareCommand () {
81 * Executes the given command with given request and response objects
83 * @param $requestInstance An instance of a class with an Requestable interface
84 * @param $responseInstance An instance of a class with an Responseable interface
87 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
88 // Get the action instance from registry
89 $actionInstance = GenericRegistry::getRegistry()->getInstance('action');
91 // Do we have an action here?
92 if ($actionInstance instanceof PerformableAction) {
93 // Execute the action (shall not output anything, see below why)
94 $actionInstance->execute($requestInstance, $responseInstance);
97 // Get the application instance
98 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
100 // Prepare a template instance
101 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
104 $templateInstance->assignConfigVariable('base_url');
106 // Assign all the application's data with template variables
107 $templateInstance->assignApplicationData();
109 // Load the master template
110 $masterTemplate = $applicationInstance->buildMasterTemplateName();
112 // Load header template
113 $templateInstance->loadCodeTemplate('header');
115 // Compile and assign it with a variable
116 $templateInstance->compileTemplate();
117 $templateInstance->assignTemplateWithVariable('header', 'header');
119 // Load footer template
120 $templateInstance->loadCodeTemplate('footer');
122 // Compile and assign it with a variable
123 $templateInstance->compileTemplate();
124 $templateInstance->assignTemplateWithVariable('footer', 'footer');
126 // Load the matching template
127 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
129 // Assign the template with the master template as a content ... ;)
130 $templateInstance->compileTemplate();
131 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
133 // Load main template
134 $templateInstance->loadCodeTemplate('login_main');
136 // Assign the main template with the master template as a content ... ;)
137 $templateInstance->compileTemplate();
138 $templateInstance->assignTemplateWithVariable('login_main', 'main_content');
140 // Load the master template
141 $templateInstance->loadCodeTemplate($masterTemplate);
144 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
146 // Construct the menu in every command. We could do this in BaseCommand class. But this means
147 // *every* command has a navigation system and that is want we don't want.
148 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
151 $menuInstance->renderMenu();
153 // Transfer it to the template engine instance
154 $menuInstance->transferContentToTemplateEngine($templateInstance);
157 * ... and all variables. This should be merged together in a pattern
158 * to make things easier. A cache mechanism should be added between
159 * these two calls to cache compiled templates.
161 $templateInstance->compileVariables();
163 // Get the content back from the template engine and put it in response class
164 $templateInstance->transferToResponse($responseInstance);
168 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
170 * @param $controllerInstance A controller instance
171 * @param $requestInstance An instance of a class with an Requestable interface
174 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
175 // Default is no action
176 $actionInstance = NULL;
179 $registryInstance = GenericRegistry::getRegistry();
181 // Get our application instance from the registry
182 $applicationInstance = $registryInstance->getInstance('application');
184 // Default action is the one from configuration
185 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_default_action');
187 // Get "action" from request
188 $actReq = $requestInstance->getRequestElement('action');
190 // Do we have a "action" parameter set?
191 if ((is_string($actReq)) && (!empty($actReq))) {
192 // Then use it with prefix
193 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
197 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName);
199 // Resolve the action
200 $actionInstance = $actionResolver->resolveAction();
202 // Add more action-specific filters
203 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
205 // Remember this action in registry
206 GenericRegistry::getRegistry()->addInstance('action', $actionInstance);