7fa4cef4ca3423245e6b61772a766a183d1879d7
[core.git] / inc / main / classes / menu / class_BaseMenu.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Menu;
4
5 // Import framework stuff
6 use CoreFramework\Object\BaseFrameworkSystem;
7
8 /**
9  * A general menu system class
10  *
11  * @author              Roland Haeder <webmaster@shipsimu.org>
12  * @version             0.0.0
13  * @copyright   Copyright (c) 2007 - 2009 Roland Haeder, this is free software
14  * @license             GNU GPL 3.0 or any newer version
15  * @link                http://www.shipsimu.org
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30 class BaseMenu extends BaseFrameworkSystem {
31         /**
32          * Protected constructor
33          *
34          * @param       $className      Name of the class
35          * @return      void
36          */
37         protected function __construct ($className) {
38                 // Call parent constructor
39                 parent::__construct($className);
40         }
41
42         /**
43          * Renders the menu by loading the base template and a menu-specific
44          * template.
45          *
46          * @return      void
47          */
48         public function renderMenu () {
49                 // Initialize the menu system by preparing it's template instance
50                 $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this));
51
52                 // Set it for later use
53                 $this->setTemplateInstance($templateInstance);
54
55                 // Load the menu template for all
56                 $templateInstance->loadMenuTemplate('generic_menu_entries');
57
58                 // Get the 'command' from request instance
59                 $command = $this->getApplicationInstance()->getRequestInstance()->getRequestElement('command');
60
61                 // If page is empty, choose default
62                 if (empty($command)) {
63                         // Use default page as none has been specified
64                         $command = $this->getConfigInstance()->getConfigEntry('default_' . $this->getApplicationInstance()->getAppShortName() . '_' . self::getResponseTypeFromSystem() . '_command');
65                 } // END - if
66
67                 // Load the menu template for this page
68                 try {
69                         $templateInstance->loadMenuTemplate($command . '_menu_entries');
70                 } catch (FileNotFoundException $e) {
71                         // Log exception @TODO Maybe to intrusive?
72                         self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Exception caught: ' . $e->__toString() . ', with message: ' . $e->getMessage());
73                 }
74
75                 // Render template data here
76                 $templateInstance->renderXmlContent();
77                 //exit(__METHOD__ . ':!OK');
78         }
79
80         /**
81          * Transfers the rendered menu to a given template engine by assigning
82          * the rendered content with a template variable.
83          *
84          * @param       $templateInstance       An instance of a CompileableTemplate class
85          * @return      void
86          */
87         public function transferContentToTemplateEngine (CompileableTemplate $templateInstance) {
88                 // Assign menu content to variable
89                 $templateInstance->assignVariable('menu', $this->getTemplateInstance()->getMenuContent());
90                 //* DEBUG */ $templateInstance->debugInstance();
91         }
92
93 }