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\Object\BaseFrameworkSystem;
10 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
11 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
14 * A general menu system class
16 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
35 abstract class BaseMenu extends BaseFrameworkSystem {
37 * Protected constructor
39 * @param $className Name of the class
42 protected function __construct ($className) {
43 // Call parent constructor
44 parent::__construct($className);
48 * Renders the menu by loading the base template and a menu-specific
53 public function renderMenu () {
54 // Initialize the menu system by preparing it's template instance
55 $templateInstance = ObjectFactory::createObjectByConfiguredName('menu_template_class', array($this));
57 // Set it for later use
58 $this->setTemplateInstance($templateInstance);
60 // Load the menu template for all
61 $templateInstance->loadMenuTemplate('generic_menu_entries');
63 // Get the 'command' from request instance
64 $command = FrameworkBootstrap::getRequestInstance()->getRequestElement('command');
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');
72 // Load the menu template for this page
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());
80 // Render template data here
81 $templateInstance->renderXmlContent();
82 //exit(__METHOD__ . ':!OK');
86 * Transfers the rendered menu to a given template engine by assigning
87 * the rendered content with a template variable.
89 * @param $templateInstance An instance of a CompileableTemplate class
92 public function transferContentToTemplateEngine (CompileableTemplate $templateInstance) {
93 // Assign menu content to variable
94 $templateInstance->assignVariable('menu', $this->getTemplateInstance()->getMenuContent());
95 //* DEBUG */ $templateInstance->debugInstance();