3 namespace Org\Mxchange\CoreFramework\Menu;
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\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;
15 * A general menu system class
17 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
36 abstract class BaseMenu extends BaseFrameworkSystem {
38 use CompileableTemplateTrait;
41 * Protected constructor
43 * @param $className Name of the class
46 protected function __construct (string $className) {
47 // Call parent constructor
48 parent::__construct($className);
52 * Renders the menu by loading the base template and a menu-specific
57 public function renderMenu () {
58 // Initialize the menu system by preparing it's template instance
59 $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this));
61 // Set it for later use
62 $this->setTemplateInstance($templateInstance);
64 // Load the menu template for all
65 $templateInstance->loadMenuTemplate('generic_menu_entries');
67 // Get the 'command' from request instance
68 $command = FrameworkBootstrap::getRequestInstance()->getRequestElement('command');
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');
76 // Load the menu template for this page
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());
84 // Render template data here
85 $templateInstance->renderXmlContent();
86 //exit(__METHOD__ . ':!OK');
90 * Transfers the rendered menu to a given template engine by assigning
91 * the rendered content with a template variable.
93 * @param $templateInstance An instance of a CompileableTemplate class
96 public function transferContentToTemplateEngine (CompileableTemplate $templateInstance) {
97 // Assign menu content to variable
98 $templateInstance->assignVariable('menu', $this->getTemplateInstance()->getMenuContent());
99 //* DEBUG */ $templateInstance->debugInstance();