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