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