3 namespace Org\Mxchange\City\Command;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Controller\Controller;
7 use Org\Mxchange\CoreFramework\Request\Requestable;
8 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
9 use Org\Mxchange\CoreFramework\Response\Responseable;
12 * A command for the login area (member/gamer area)
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 * @copyright Copyright (c) 2015, 2016 City Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.shipsimu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable {
37 private $actionName = '';
40 * Protected constructor
44 protected function __construct () {
45 // Call parent constructor
46 parent::__construct(__CLASS__);
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 static final function createCityHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
57 $commandInstance = new CityHtmlLoginAreaCommand();
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
73 * @todo Add some stuff here: Some personal data, app/game related data
75 protected function prepareCommand () {
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 // Do we have an action here?
90 if ($actionInstance instanceof PerformableAction) {
91 // Execute the action (shall not output anything, see below why)
92 $actionInstance->execute($requestInstance, $responseInstance);
95 // Get the application instance
96 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
98 // Prepare a template instance
99 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
102 $templateInstance->assignConfigVariable('base_url');
104 // Assign all the application's data with template variables
105 $templateInstance->assignApplicationData($applicationInstance);
107 // Load the master template
108 $masterTemplate = $applicationInstance->buildMasterTemplateName();
110 // Load header template
111 $templateInstance->loadCodeTemplate('header');
113 // Compile and assign it with a variable
114 $templateInstance->compileTemplate();
115 $templateInstance->assignTemplateWithVariable('header', 'header');
117 // Load footer template
118 $templateInstance->loadCodeTemplate('footer');
120 // Compile and assign it with a variable
121 $templateInstance->compileTemplate();
122 $templateInstance->assignTemplateWithVariable('footer', 'footer');
124 // Load the matching template
125 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
127 // Assign the template with the master template as a content ... ;)
128 $templateInstance->compileTemplate();
129 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
131 // Load main template
132 $templateInstance->loadCodeTemplate('login_main');
134 // Assign the main template with the master template as a content ... ;)
135 $templateInstance->compileTemplate();
136 $templateInstance->assignTemplateWithVariable('login_main', 'main_content');
138 // Load the master template
139 $templateInstance->loadCodeTemplate($masterTemplate);
142 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
144 // Construct the menu in every command. We could do this in BaseCommand class. But this means
145 // *every* command has a navigation system and that is want we don't want.
146 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
149 $menuInstance->renderMenu();
151 // Transfer it to the template engine instance
152 $menuInstance->transferContentToTemplateEngine($templateInstance);
155 * ... and all variables. This should be merged together in a pattern
156 * to make things easier. A cache mechanism should be added between
157 * these two calls to cache compiled templates.
159 $templateInstance->compileVariables();
161 // Get the content back from the template engine and put it in response class
162 $templateInstance->transferToResponse($responseInstance);
166 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
168 * @param $controllerInstance A controller instance
169 * @param $requestInstance An instance of a class with an Requestable interface
172 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
173 // Default is no action
174 $actionInstance = NULL;
177 $registryInstance = Registry::getRegistry();
179 // Get our application instance from the registry
180 $applicationInstance = $registryInstance->getInstance('application');
182 // Default action is the one from configuration
183 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action');
185 // Get "action" from request
186 $actReq = $requestInstance->getRequestElement('action');
188 // Do we have a "action" parameter set?
189 if ((is_string($actReq)) && (!empty($actReq))) {
190 // Then use it with prefix
191 $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
194 // Get application instance
195 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
198 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName, $applicationInstance);
200 // Resolve the action
201 $actionInstance = $actionResolver->resolveAction();
203 // Add more action-specific filters
204 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
206 // Remember this action in registry
207 Registry::getRegistry()->addInstance('action', $actionInstance);