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