Continued:
[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 use CoreFramework\Template\CompileableTemplate;
8
9 /**
10  * A general menu system class
11  *
12  * @author              Roland Haeder <webmaster@shipsimu.org>
13  * @version             0.0.0
14  * @copyright   Copyright (c) 2007 - 2009 Roland Haeder, this is free software
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 BaseMenu extends BaseFrameworkSystem {
32         /**
33          * Protected constructor
34          *
35          * @param       $className      Name of the class
36          * @return      void
37          */
38         protected function __construct ($className) {
39                 // Call parent constructor
40                 parent::__construct($className);
41         }
42
43         /**
44          * Renders the menu by loading the base template and a menu-specific
45          * template.
46          *
47          * @return      void
48          */
49         public function renderMenu () {
50                 // Initialize the menu system by preparing it's template instance
51                 $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this));
52
53                 // Set it for later use
54                 $this->setTemplateInstance($templateInstance);
55
56                 // Load the menu template for all
57                 $templateInstance->loadMenuTemplate('generic_menu_entries');
58
59                 // Get the 'command' from request instance
60                 $command = $this->getApplicationInstance()->getRequestInstance()->getRequestElement('command');
61
62                 // If page is empty, choose default
63                 if (empty($command)) {
64                         // Use default page as none has been specified
65                         $command = $this->getConfigInstance()->getConfigEntry('default_' . $this->getApplicationInstance()->getAppShortName() . '_' . self::getResponseTypeFromSystem() . '_command');
66                 } // END - if
67
68                 // Load the menu template for this page
69                 try {
70                         $templateInstance->loadMenuTemplate($command . '_menu_entries');
71                 } catch (FileNotFoundException $e) {
72                         // Log exception @TODO Maybe to intrusive?
73                         self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Exception caught: ' . $e->__toString() . ', with message: ' . $e->getMessage());
74                 }
75
76                 // Render template data here
77                 $templateInstance->renderXmlContent();
78                 //exit(__METHOD__ . ':!OK');
79         }
80
81         /**
82          * Transfers the rendered menu to a given template engine by assigning
83          * the rendered content with a template variable.
84          *
85          * @param       $templateInstance       An instance of a CompileableTemplate class
86          * @return      void
87          */
88         public function transferContentToTemplateEngine (CompileableTemplate $templateInstance) {
89                 // Assign menu content to variable
90                 $templateInstance->assignVariable('menu', $this->getTemplateInstance()->getMenuContent());
91                 //* DEBUG */ $templateInstance->debugInstance();
92         }
93
94 }