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