Failed attempts for governments added
[shipsimu.git] / application / ship-simu / main / commands / web / government / class_WebGovernmentFailedStartupCommand.php
1 <?php
2 /**
3  * A command for a failed startup request. This may happen when the user
4  * "knows" the correct URL but government refuses to pay.
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.ship-simu.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 class WebGovernmentFailedStartupCommand extends BaseCommand implements Commandable {
26         /**
27          * Protected constructor
28          *
29          * @return      void
30          */
31         protected function __construct () {
32                 // Call parent constructor
33                 parent::__construct(__CLASS__);
34         }
35
36         /**
37          * Creates an instance of this class
38          *
39          * @param       $resolverInstance       An instance of a command resolver class
40          * @return      $commandInstance        An instance a prepared command class
41          */
42         public final static function createWebGovernmentFailedStartupCommand (CommandResolver $resolverInstance) {
43                 // Get new instance
44                 $commandInstance = new WebGovernmentFailedStartupCommand();
45
46                 // Set the application instance
47                 $commandInstance->setResolverInstance($resolverInstance);
48
49                 // Return the prepared instance
50                 return $commandInstance;
51         }
52
53         /**
54          * Executes the given command with given request and response objects
55          *
56          * @param       $requestInstance        An instance of a class with an Requestable interface
57          * @param       $responseInstance       An instance of a class with an Responseable interface
58          * @return      void
59          * @todo        0% done
60          */
61         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
62                 // Get the action instance from registry
63                 $actionInstance = Registry::getRegistry()->getInstance('action');
64
65                 // Do we have an action here?
66                 if ($actionInstance instanceof PerformableAction) {
67                         // Execute the action (shall not output anything, see below why)
68                         $actionInstance->execute($requestInstance, $responseInstance);
69                 } // END - if
70
71                 // Get the application instance
72                 $appInstance = $this->getResolverInstance()->getApplicationInstance();
73
74                 // Prepare a template instance
75                 $templateInstance = $this->prepareTemplateInstance($appInstance);
76
77                 // Assign base URL
78                 $templateInstance->assignConfigVariable('base_url');
79
80                 // Assign all the application's data with template variables
81                 $templateInstance->assignApplicationData($appInstance);
82
83                 // Load the master template
84                 $masterTemplate = $appInstance->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 main template
101                 $templateInstance->loadCodeTemplate('government_failed_main');
102
103                 // Assign the main template with the master template as a content ... ;)
104                 $templateInstance->compileTemplate();
105                 $templateInstance->assignTemplateWithVariable('government_failed_main', 'content');
106
107                 // Load the master template
108                 $templateInstance->loadCodeTemplate($masterTemplate);
109
110                 // Set title
111                 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($requestInstance->getRequestElement('page') . '_' . $requestInstance->getRequestElement('failed') . '_title'));
112
113                 // Construct the menu in every command. We could do this in BaseCommand class. But this means
114                 // *every* command has a navigation system and that is want we don't want.
115                 $menuInstance = ObjectFactory::createObjectByConfiguredName('government_failed_area_menu_class', array($appInstance));
116
117                 // ... and all variables. This should be merged together in a pattern
118                 // to make things easier. A cache mechanism should be added between
119                 // these two calls to cache compiled templates.
120                 $templateInstance->compileVariables();
121
122                 // Get the content back from the template engine and put it in response class
123                 $templateInstance->transferToResponse($responseInstance);
124         }
125
126         /**
127          * Adds extra filters to the given controller instance
128          *
129          * @param       $controllerInstance             A controller instance
130          * @param       $requestInstance                An instance of a class with an Requestable interface
131          * @return      void
132          * @todo        Maybe we need some filters here?
133          */
134         public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
135                 // Empty for now
136         }
137 }
138
139 // [EOF]
140 ?>