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