Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This class defines a menu item that will be used with Zend_Navigation to generate a menu
- *
- * @author Joel Lord
- * @since 20 mai 2012
- *
- */
- class ZARD_Object_Module_Multimodmenu {
- /**
- * Instance of the class
- * @var ZARD_Object_Module_Multimodmenu
- */
- private static $instance;
- /**
- * Name of the module
- * @var Zend_Navigation_Container
- */
- private static $_menu;
- /**
- * Holds the ACL helper
- * @var Zend_Controller_Action_Helper_Abstract
- */
- protected $_acl;
- /**
- * id of the menu item
- * @var string
- */
- public $id;
- /**
- * Label to be displayed
- * @var string
- */
- public $label;
- /**
- * Parent menu (moduleName_id)
- * @var string
- */
- public $parent;
- /**
- * Module to be called
- * @var string
- */
- public $module;
- /**
- * Controller to be called
- * @var string
- */
- public $controller;
- /**
- * Action to be called
- * @var string
- */
- public $action;
- /**
- * External URL if link should be outside the site
- * @var string
- */
- public $extUrl;
- /**
- * Where should the item appear in the menu
- * @var int
- */
- public $order;
- /**
- * Options used to build the url
- * @var array string
- */
- public $params;
- private function __construct() {
- }
- /**
- * get an Instance of the multimodmenu
- * Singleton pattern
- * @return Zend_Object_Module_Multimodmenu
- */
- public static function getInstance() {
- if(!isset(self::$instance)) {
- self::$instance = new ZARD_Object_Module_Multimodmenu();
- self::$_menu = new Zend_Navigation();
- }
- return self::$instance;
- }
- /**
- * This function adds a menu item to the menu and flushes all vars
- */
- public function addItem() {
- //Check for privileges before adding the menu item
- //Load the $acl helper
- if(!Zend_Controller_Action_HelperBroker::hasHelper('IsAllowed'))
- Zend_Controller_Action_HelperBroker::addHelper(new ZARD_Helper_IsAllowed());
- $acl = Zend_Controller_Action_HelperBroker::getStaticHelper('IsAllowed');
- //Check the rights
- if(!$this->module && !$this->controller && !$this->action) {
- //No module/controller/action triplet entered, this is a submenu
- $submenu = true;
- } else {
- //Check if user has the rights to view this menu item
- $allowed = $acl->isAllowed($this->module, $this->controller, $this->action);
- }
- if($allowed || $submenu) {
- //Prepare the item depeping if the item is an external link or internal
- if($this->extUrl) {
- $item = new Zend_Navigation_Page_Uri();
- $item->setUri($this->extUrl);
- } else {
- $item = new Zend_Navigation_Page_Mvc();
- $item->setModule($this->module);
- $item->setController($this->controller);
- $item->setAction($this->action);
- }
- //Set the label, the id and the order
- $item->setLabel($this->label);
- $item->setId($this->id);
- $item->setOrder($this->order);
- $item->setParams($this->params);
- //Add to submenu if needed
- $submenu = self::$_menu->findBy('id', $this->parent, false);
- if($submenu) {
- $submenu->addPage($item);
- } else {
- self::$_menu->addPage($item);
- }
- }
- //Flush all vars
- $this->id = null;
- $this->label = null;
- $this->parent = null;
- $this->module = null;
- $this->controller = null;
- $this->action = null;
- $this->extUrl = null;
- $this->order = null;
- $this->params = null;
- }
- /**
- * This method returns the menu
- * @return Zend_Navigation_Container
- */
- public function getMenu() {
- return self::$_menu;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement