3 namespace CoreFramework\Command\Guest;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Registry\Generic\Registry;
10 * A command for the confirmation link handling
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class HtmlConfirmCommand extends BaseCommand implements Commandable {
33 * Protected constructor
37 protected function __construct () {
38 // Call parent constructor
39 parent::__construct(__CLASS__);
43 * Creates an instance of this class
45 * @param $resolverInstance An instance of a command resolver class
46 * @return $commandInstance An instance a prepared command class
48 public static final function createHtmlConfirmCommand (CommandResolver $resolverInstance) {
50 $commandInstance = new HtmlConfirmCommand();
52 // Set the application instance
53 $commandInstance->setResolverInstance($resolverInstance);
55 // Return the prepared instance
56 return $commandInstance;
60 * Executes the given command with given request and response objects
62 * @param $requestInstance An instance of a class with an Requestable interface
63 * @param $responseInstance An instance of a class with an Responseable interface
66 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
67 // Get the application instance
68 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
70 // Prepare a template instance
71 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
73 // Assign application data with template engine
74 $templateInstance->assignApplicationData($applicationInstance);
77 $templateInstance->assignConfigVariable('base_url');
79 // Load the master template
80 $masterTemplate = $applicationInstance->buildMasterTemplateName();
82 // Load header template
83 $templateInstance->loadCodeTemplate('header');
85 // Compile and assign it with a variable
86 $templateInstance->compileTemplate();
87 $templateInstance->assignTemplateWithVariable('header', 'header');
89 // Load footer template
90 $templateInstance->loadCodeTemplate('footer');
92 // Compile and assign it with a variable
93 $templateInstance->compileTemplate();
94 $templateInstance->assignTemplateWithVariable('footer', 'footer');
96 // Load the home template
97 $templateInstance->loadCodeTemplate('confirm_link');
99 // Assign the home template with the master template as a content ... ;)
100 $templateInstance->assignTemplateWithVariable('confirm_link', 'main_content');
102 // Load the master template
103 $templateInstance->loadCodeTemplate($masterTemplate);
106 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_confirm_link_title'));
110 $userInstance = Registry::getRegistry()->getInstance('user');
111 } catch (NullPointerException $e) {
112 // Not found user, e.g. when the user is somehow invalid
113 $responseInstance->redirectToConfiguredUrl('html_cmd_user_is_null');
117 $templateInstance->assignVariable('username', $userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USERNAME));
119 // Construct the menu in every command. We could do this in BaseCommand class. But this means
120 // *every* command has a navigation system and that is want we don't want.
121 $menuInstance = ObjectFactory::createObjectByConfiguredName('confirm_menu_class', array($applicationInstance));
124 $menuInstance->renderMenu();
126 // Transfer it to the template engine instance
127 $menuInstance->transferContentToTemplateEngine($templateInstance);
130 * ... and all variables. This should be merged together in a pattern
131 * to make things easier. A cache mechanism should be added between
132 * these two calls to cache compiled templates.
134 $templateInstance->compileVariables();
136 // Get the content back from the template engine and put it in response class
137 $templateInstance->transferToResponse($responseInstance);
141 * Adds extra filters to the given controller instance
143 * @param $controllerInstance A controller instance
144 * @param $requestInstance An instance of a class with an Requestable interface
147 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {