689ece383cf68bf0f591c5c6a95355aea6b0dd4e
[core.git] / framework / main / classes / commands / html / class_HtmlConfirmCommand.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Command\Guest;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Command\BaseCommand;
7 use Org\Mxchange\CoreFramework\Command\Commandable;
8 use Org\Mxchange\CoreFramework\Controller\Controller;
9 use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseWrapper;
10 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
11 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
12 use Org\Mxchange\CoreFramework\Registry\Registry;
13 use Org\Mxchange\CoreFramework\Request\Requestable;
14 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
15 use Org\Mxchange\CoreFramework\Response\Responseable;
16
17 /**
18  * A command for the confirmation link handling
19  *
20  * @author              Roland Haeder <webmaster@shipsimu.org>
21  * @version             0.0.0
22 <<<<<<< HEAD:framework/main/classes/commands/html/class_HtmlConfirmCommand.php
23  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
24 =======
25  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
26 >>>>>>> Some updates::inc/main/classes/commands/html/class_HtmlConfirmCommand.php
27  * @license             GNU GPL 3.0 or any newer version
28  * @link                http://www.shipsimu.org
29  *
30  * This program is free software: you can redistribute it and/or modify
31  * it under the terms of the GNU General Public License as published by
32  * the Free Software Foundation, either version 3 of the License, or
33  * (at your option) any later version.
34  *
35  * This program is distributed in the hope that it will be useful,
36  * but WITHOUT ANY WARRANTY; without even the implied warranty of
37  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38  * GNU General Public License for more details.
39  *
40  * You should have received a copy of the GNU General Public License
41  * along with this program. If not, see <http://www.gnu.org/licenses/>.
42  */
43 class HtmlConfirmCommand extends BaseCommand implements Commandable {
44         /**
45          * Protected constructor
46          *
47          * @return      void
48          */
49         protected function __construct () {
50                 // Call parent constructor
51                 parent::__construct(__CLASS__);
52         }
53
54         /**
55          * Creates an instance of this class
56          *
57          * @param       $resolverInstance       An instance of a command resolver class
58          * @return      $commandInstance        An instance a prepared command class
59          */
60         public static final function createHtmlConfirmCommand (CommandResolver $resolverInstance) {
61                 // Get new instance
62                 $commandInstance = new HtmlConfirmCommand();
63
64                 // Set the application instance
65                 $commandInstance->setResolverInstance($resolverInstance);
66
67                 // Return the prepared instance
68                 return $commandInstance;
69         }
70
71         /**
72          * Executes the given command with given request and response objects
73          *
74          * @param       $requestInstance        An instance of a class with an Requestable interface
75          * @param       $responseInstance       An instance of a class with an Responseable interface
76          * @return      void
77          */
78         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
79                 // Get the application instance
80                 $applicationInstance = Registry::getRegistry()->getInstance('app');
81
82                 // Prepare a template instance
83                 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
84
85                 // Assign application data with template engine
86                 $templateInstance->assignApplicationData($applicationInstance);
87
88                 // Assign base URL
89                 $templateInstance->assignConfigVariable('base_url');
90
91                 // Load the master template
92                 $masterTemplate = $applicationInstance->buildMasterTemplateName();
93
94                 // Load header template
95                 $templateInstance->loadCodeTemplate('header');
96
97                 // Compile and assign it with a variable
98                 $templateInstance->compileTemplate();
99                 $templateInstance->assignTemplateWithVariable('header', 'header');
100
101                 // Load footer template
102                 $templateInstance->loadCodeTemplate('footer');
103
104                 // Compile and assign it with a variable
105                 $templateInstance->compileTemplate();
106                 $templateInstance->assignTemplateWithVariable('footer', 'footer');
107
108                 // Load the home template
109                 $templateInstance->loadCodeTemplate('confirm_link');
110
111                 // Assign the home template with the master template as a content ... ;)
112                 $templateInstance->assignTemplateWithVariable('confirm_link', 'main_content');
113
114                 // Load the master template
115                 $templateInstance->loadCodeTemplate($masterTemplate);
116
117                 // Set title
118                 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_confirm_link_title'));
119
120                 // Get user instance
121                 try {
122                         $userInstance = Registry::getRegistry()->getInstance('user');
123                 } catch (NullPointerException $e) {
124                         // Not found user, e.g. when the user is somehow invalid
125                         $responseInstance->redirectToConfiguredUrl('html_cmd_user_is_null');
126                 }
127
128                 // Set username
129                 $templateInstance->assignVariable('username', $userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USERNAME));
130
131                 // Construct the menu in every command. We could do this in BaseCommand class. But this means
132                 // *every* command has a navigation system and that is want we don't want.
133                 $menuInstance = ObjectFactory::createObjectByConfiguredName('confirm_menu_class', array($applicationInstance));
134
135                 // Render the menu
136                 $menuInstance->renderMenu();
137
138                 // Transfer it to the template engine instance
139                 $menuInstance->transferContentToTemplateEngine($templateInstance);
140
141                 /*
142                  * ... and all variables. This should be merged together in a pattern
143                  * to make things easier. A cache mechanism should be added between
144                  * these two calls to cache compiled templates.
145                  */
146                 $templateInstance->compileVariables();
147
148                 // Get the content back from the template engine and put it in response class
149                 $templateInstance->transferToResponse($responseInstance);
150         }
151
152         /**
153          * Adds extra filters to the given controller instance
154          *
155          * @param       $controllerInstance             A controller instance
156          * @param       $requestInstance                An instance of a class with an Requestable interface
157          * @return      void
158          */
159         public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
160                 // Empty for now
161         }
162
163 }