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