]> git.mxchange.org Git - core.git/blob - inc/main/classes/commands/html/class_HtmlConfirmCommand.php
01cee1902c40f8bacfab6242c1586f5c4b98a017
[core.git] / inc / main / classes / commands / html / class_HtmlConfirmCommand.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Command\Guest;
4
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;
12
13 /**
14  * A command for the confirmation link handling
15  *
16  * @author              Roland Haeder <webmaster@shipsimu.org>
17  * @version             0.0.0
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
21  *
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.
26  *
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.
31  *
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/>.
34  */
35 class HtmlConfirmCommand extends BaseCommand implements Commandable {
36         /**
37          * Protected constructor
38          *
39          * @return      void
40          */
41         protected function __construct () {
42                 // Call parent constructor
43                 parent::__construct(__CLASS__);
44         }
45
46         /**
47          * Creates an instance of this class
48          *
49          * @param       $resolverInstance       An instance of a command resolver class
50          * @return      $commandInstance        An instance a prepared command class
51          */
52         public static final function createHtmlConfirmCommand (CommandResolver $resolverInstance) {
53                 // Get new instance
54                 $commandInstance = new HtmlConfirmCommand();
55
56                 // Set the application instance
57                 $commandInstance->setResolverInstance($resolverInstance);
58
59                 // Return the prepared instance
60                 return $commandInstance;
61         }
62
63         /**
64          * Executes the given command with given request and response objects
65          *
66          * @param       $requestInstance        An instance of a class with an Requestable interface
67          * @param       $responseInstance       An instance of a class with an Responseable interface
68          * @return      void
69          */
70         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
71                 // Get the application instance
72                 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
73
74                 // Prepare a template instance
75                 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
76
77                 // Assign application data with template engine
78                 $templateInstance->assignApplicationData($applicationInstance);
79
80                 // Assign base URL
81                 $templateInstance->assignConfigVariable('base_url');
82
83                 // Load the master template
84                 $masterTemplate = $applicationInstance->buildMasterTemplateName();
85
86                 // Load header template
87                 $templateInstance->loadCodeTemplate('header');
88
89                 // Compile and assign it with a variable
90                 $templateInstance->compileTemplate();
91                 $templateInstance->assignTemplateWithVariable('header', 'header');
92
93                 // Load footer template
94                 $templateInstance->loadCodeTemplate('footer');
95
96                 // Compile and assign it with a variable
97                 $templateInstance->compileTemplate();
98                 $templateInstance->assignTemplateWithVariable('footer', 'footer');
99
100                 // Load the home template
101                 $templateInstance->loadCodeTemplate('confirm_link');
102
103                 // Assign the home template with the master template as a content ... ;)
104                 $templateInstance->assignTemplateWithVariable('confirm_link', 'main_content');
105
106                 // Load the master template
107                 $templateInstance->loadCodeTemplate($masterTemplate);
108
109                 // Set title
110                 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_confirm_link_title'));
111
112                 // Get user instance
113                 try {
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');
118                 }
119
120                 // Set username
121                 $templateInstance->assignVariable('username', $userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USERNAME));
122
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));
126
127                 // Render the menu
128                 $menuInstance->renderMenu();
129
130                 // Transfer it to the template engine instance
131                 $menuInstance->transferContentToTemplateEngine($templateInstance);
132
133                 /*
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.
137                  */
138                 $templateInstance->compileVariables();
139
140                 // Get the content back from the template engine and put it in response class
141                 $templateInstance->transferToResponse($responseInstance);
142         }
143
144         /**
145          * Adds extra filters to the given controller instance
146          *
147          * @param       $controllerInstance             A controller instance
148          * @param       $requestInstance                An instance of a class with an Requestable interface
149          * @return      void
150          */
151         public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
152                 // Empty for now
153         }
154
155 }