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