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