3 namespace CoreFramework\Command\Guest;
5 // Import framework stuff
6 use CoreFramework\Command\BaseCommand;
7 use CoreFramework\Factory\ObjectFactory;
8 use CoreFramework\Generic\NullPointerException;
9 use CoreFramework\Registry\Generic\Registry;
10 use CoreFramework\Request\Requestable;
11 use CoreFramework\Response\Responseable;
14 * A command for the confirmation link handling
16 * @author Roland Haeder <webmaster@shipsimu.org>
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core 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 HtmlConfirmCommand extends BaseCommand implements Commandable {
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
47 * Creates an instance of this class
49 * @param $resolverInstance An instance of a command resolver class
50 * @return $commandInstance An instance a prepared command class
52 public static final function createHtmlConfirmCommand (CommandResolver $resolverInstance) {
54 $commandInstance = new HtmlConfirmCommand();
56 // Set the application instance
57 $commandInstance->setResolverInstance($resolverInstance);
59 // Return the prepared instance
60 return $commandInstance;
64 * Executes the given command with given request and response objects
66 * @param $requestInstance An instance of a class with an Requestable interface
67 * @param $responseInstance An instance of a class with an Responseable interface
70 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
71 // Get the application instance
72 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
74 // Prepare a template instance
75 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
77 // Assign application data with template engine
78 $templateInstance->assignApplicationData($applicationInstance);
81 $templateInstance->assignConfigVariable('base_url');
83 // Load the master template
84 $masterTemplate = $applicationInstance->buildMasterTemplateName();
86 // Load header template
87 $templateInstance->loadCodeTemplate('header');
89 // Compile and assign it with a variable
90 $templateInstance->compileTemplate();
91 $templateInstance->assignTemplateWithVariable('header', 'header');
93 // Load footer template
94 $templateInstance->loadCodeTemplate('footer');
96 // Compile and assign it with a variable
97 $templateInstance->compileTemplate();
98 $templateInstance->assignTemplateWithVariable('footer', 'footer');
100 // Load the home template
101 $templateInstance->loadCodeTemplate('confirm_link');
103 // Assign the home template with the master template as a content ... ;)
104 $templateInstance->assignTemplateWithVariable('confirm_link', 'main_content');
106 // Load the master template
107 $templateInstance->loadCodeTemplate($masterTemplate);
110 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_confirm_link_title'));
114 $userInstance = Registry::getRegistry()->getInstance('user');
115 } catch (NullPointerException $e) {
116 // Not found user, e.g. when the user is somehow invalid
117 $responseInstance->redirectToConfiguredUrl('html_cmd_user_is_null');
121 $templateInstance->assignVariable('username', $userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USERNAME));
123 // Construct the menu in every command. We could do this in BaseCommand class. But this means
124 // *every* command has a navigation system and that is want we don't want.
125 $menuInstance = ObjectFactory::createObjectByConfiguredName('confirm_menu_class', array($applicationInstance));
128 $menuInstance->renderMenu();
130 // Transfer it to the template engine instance
131 $menuInstance->transferContentToTemplateEngine($templateInstance);
134 * ... and all variables. This should be merged together in a pattern
135 * to make things easier. A cache mechanism should be added between
136 * these two calls to cache compiled templates.
138 $templateInstance->compileVariables();
140 // Get the content back from the template engine and put it in response class
141 $templateInstance->transferToResponse($responseInstance);
145 * Adds extra filters to the given controller instance
147 * @param $controllerInstance A controller instance
148 * @param $requestInstance An instance of a class with an Requestable interface
151 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {