3 namespace Org\Mxchange\CoreFramework\Menu;
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;
16 * A general menu system class
18 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
37 abstract class BaseMenu extends BaseFrameworkSystem {
39 use CompileableTemplateTrait;
42 * Protected constructor
44 * @param $className Name of the class
47 protected function __construct (string $className) {
48 // Call parent constructor
49 parent::__construct($className);
53 * Renders the menu by loading the base template and a menu-specific
58 public function renderMenu () {
59 // Initialize the menu system by preparing it's template instance
60 $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', [$this]);
62 // Set it for later use
63 $this->setTemplateInstance($templateInstance);
65 // Load the menu template for all
66 $templateInstance->loadMenuTemplate('generic_menu_entries');
68 // Get the 'command' from request instance
69 $command = FrameworkBootstrap::getRequestInstance()->getRequestElement('command');
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');
77 // Load the menu template for this page
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());
85 // Render template data here
86 $templateInstance->renderXmlContent();
87 //exit(__METHOD__ . ':!OK');
91 * Transfers the rendered menu to a given template engine by assigning
92 * the rendered content with a template variable.
94 * @param $templateInstance An instance of a CompileableTemplate class
97 public function transferContentToTemplateEngine (CompileableTemplate $templateInstance) {
98 // Assign menu content to variable
99 $templateInstance->assignVariable('menu', $this->getTemplateInstance()->getMenuContent());
100 //* DEBUG */ $templateInstance->debugInstance();