]> git.mxchange.org Git - core.git/blob - framework/main/classes/menu/class_BaseMenu.php
Continued:
[core.git] / framework / main / classes / menu / class_BaseMenu.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Menu;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
9 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
10 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
11 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
12
13 /**
14  * A general menu system class
15  *
16  * @author              Roland Haeder <webmaster@shipsimu.org>
17  * @version             0.0.0
18  * @copyright   Copyright (c) 2007 - 2009 Roland Haeder, this is free software
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 abstract class BaseMenu extends BaseFrameworkSystem {
36
37         /**
38          * Template engine instance
39          */
40         private $templateInstance = NULL;
41
42         /**
43          * Protected constructor
44          *
45          * @param       $className      Name of the class
46          * @return      void
47          */
48         protected function __construct (string $className) {
49                 // Call parent constructor
50                 parent::__construct($className);
51         }
52
53         /**
54          * Setter for template engine instances
55          *
56          * @param       $templateInstance       An instance of a CompileableTemplate class
57          * @return      void
58          */
59         protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
60                 $this->templateInstance = $templateInstance;
61         }
62
63         /**
64          * Getter for template engine instances
65          *
66          * @return      $templateInstance       An instance of a CompileableTemplate class
67          */
68         public final function getTemplateInstance () {
69                 return $this->templateInstance;
70         }
71
72         /**
73          * Renders the menu by loading the base template and a menu-specific
74          * template.
75          *
76          * @return      void
77          */
78         public function renderMenu () {
79                 // Initialize the menu system by preparing it's template instance
80                 $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this));
81
82                 // Set it for later use
83                 $this->setTemplateInstance($templateInstance);
84
85                 // Load the menu template for all
86                 $templateInstance->loadMenuTemplate('generic_menu_entries');
87
88                 // Get the 'command' from request instance
89                 $command = FrameworkBootstrap::getRequestInstance()->getRequestElement('command');
90
91                 // If page is empty, choose default
92                 if (empty($command)) {
93                         // Use default page as none has been specified
94                         $command = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_' . GenericRegistry::getRegistry()->getInstance('application')->getAppShortName() . '_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command');
95                 } // END - if
96
97                 // Load the menu template for this page
98                 try {
99                         $templateInstance->loadMenuTemplate($command . '_menu_entries');
100                 } catch (FileNotFoundException $e) {
101                         // Log exception @TODO Maybe to intrusive?
102                         self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-MENU: Exception caught: ' . $e->__toString() . ', with message: ' . $e->getMessage());
103                 }
104
105                 // Render template data here
106                 $templateInstance->renderXmlContent();
107                 //exit(__METHOD__ . ':!OK');
108         }
109
110         /**
111          * Transfers the rendered menu to a given template engine by assigning
112          * the rendered content with a template variable.
113          *
114          * @param       $templateInstance       An instance of a CompileableTemplate class
115          * @return      void
116          */
117         public function transferContentToTemplateEngine (CompileableTemplate $templateInstance) {
118                 // Assign menu content to variable
119                 $templateInstance->assignVariable('menu', $this->getTemplateInstance()->getMenuContent());
120                 //* DEBUG */ $templateInstance->debugInstance();
121         }
122
123 }