Mage_Adminhtml_Block_Page_Menu Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Page_Menu:

Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 getCacheLifetime ()
 getCacheKey ()
 getMenuArray ()

Public Attributes

const CACHE_TAGS = 'BACKEND_MAINMENU'

Protected Member Functions

 _construct ()
 _getHelperValue (Varien_Simplexml_Element $child)
 _buildMenuArray (Varien_Simplexml_Element $parent=null, $path='', $level=0)
 _sortMenu ($a, $b)
 _checkDepends (Varien_Simplexml_Element $depends)
 _checkAcl ($resource)

Protected Attributes

 $_url


Detailed Description

Definition at line 34 of file Menu.php.


Member Function Documentation

_buildMenuArray ( Varien_Simplexml_Element parent = null,
path = '',
level = 0 
) [protected]

Definition at line 79 of file Menu.php.

00080     {
00081         if (is_null($parent)) {
00082             $parent = Mage::getConfig()->getNode('adminhtml/menu');
00083 //        $parent = Mage::getSingleton('adminhtml/config')->getNode('admin/menu');
00084 
00085         }
00086         $parentArr = array();
00087         $sortOrder = 0;
00088         foreach ($parent->children() as $childName=>$child) {
00089 
00090             $aclResource = 'admin/'.$path.$childName;
00091             if (!$this->_checkAcl($aclResource)) {
00092                 continue;
00093             }
00094 
00095             if ($child->depends && !$this->_checkDepends($child->depends)) {
00096                 continue;
00097             }
00098 
00099             $menuArr = array();
00100 
00101             $menuArr['label'] = $this->_getHelperValue($child);
00102 
00103             $menuArr['sort_order'] = $child->sort_order ? (int)$child->sort_order : $sortOrder;
00104 
00105             if ($child->action) {
00106                 $menuArr['url'] = $this->_url->getUrl((string)$child->action);
00107             } else {
00108                 $menuArr['url'] = '#';
00109                 $menuArr['click'] = 'return false';
00110             }
00111             #print_r($this->getActive().','.$path.$childName."<hr>");
00112             $menuArr['active'] = ($this->getActive()==$path.$childName)
00113                 || (strpos($this->getActive(), $path.$childName.'/')===0);
00114 
00115             $menuArr['level'] = $level;
00116 
00117             if ($child->children) {
00118                 $menuArr['children'] = $this->_buildMenuArray($child->children, $path.$childName.'/', $level+1);
00119             }
00120             $parentArr[$childName] = $menuArr;
00121 
00122             $sortOrder++;
00123         }
00124 
00125         uasort($parentArr, array($this, '_sortMenu'));
00126 
00127         while (list($key, $value) = each($parentArr)) {
00128             $last = $key;
00129         }
00130         if (isset($last)) {
00131             $parentArr[$last]['last'] = true;
00132         }
00133 
00134         return $parentArr;
00135     }

_checkAcl ( resource  )  [protected]

Definition at line 172 of file Menu.php.

00173     {
00174         try {
00175             $res =  Mage::getSingleton('admin/session')->isAllowed($resource);
00176         } catch (Exception $e) {
00177             return false;
00178         }
00179         return $res;
00180     }

_checkDepends ( Varien_Simplexml_Element depends  )  [protected]

Definition at line 142 of file Menu.php.

00143     {
00144         if ($depends->module) {
00145             $modulesConfig = Mage::getConfig()->getNode('modules');
00146             foreach ($depends->module as $module) {
00147                 if (!$modulesConfig->$module || !$modulesConfig->$module->is('active')) {
00148                     return false;
00149                 }
00150             }
00151         }
00152 
00153         if ($depends->config) {
00154             foreach ($depends->config as $path) {
00155                 if (!Mage::getStoreConfigFlag((string)$path)) {
00156                     return false;
00157                 }
00158             }
00159         }
00160 
00161         return true;
00162     }

_construct (  )  [protected]

Internal constructor, that is called from real constructor

Please override this one instead of overriding real __construct constructor

Please override this one instead of overriding real __construct constructor

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 39 of file Menu.php.

00040     {
00041         parent::_construct();
00042         $this->setTemplate('page/menu.phtml');
00043         $this->_url = Mage::getModel('adminhtml/url');
00044         $this->setCacheTags(array(self::CACHE_TAGS));
00045     }

_getHelperValue ( Varien_Simplexml_Element child  )  [protected]

Definition at line 64 of file Menu.php.

00065     {
00066         $helperName         = 'adminhtml';
00067         $titleNodeName      = 'title';
00068         $childAttributes    = $child->attributes();
00069         if (isset($childAttributes['module'])) {
00070             $helperName     = (string)$childAttributes['module'];
00071         }
00072 //        if (isset($childAttributes['translate'])) {
00073 //            $titleNodeName  = (string)$childAttributes['translate'];
00074 //        }
00075 
00076         return Mage::helper($helperName)->__((string)$child->$titleNodeName);
00077     }

_sortMenu ( a,
b 
) [protected]

Definition at line 137 of file Menu.php.

00138     {
00139         return $a['sort_order']<$b['sort_order'] ? -1 : ($a['sort_order']>$b['sort_order'] ? 1 : 0);
00140     }

getCacheKey (  ) 

Get Key for caching block content

Returns:
string

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 52 of file Menu.php.

00053     {
00054         // getting roles for current user, for now one role per user
00055         $id = Mage::getSingleton('admin/session')->getUser()->getId();
00056         return 'admin_top_nav_'.$this->getActive().'_'.$id.'_'.Mage::app()->getLocale()->getLocaleCode();
00057     }

getCacheLifetime (  ) 

Get block cache life time

Returns:
int

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 47 of file Menu.php.

00048     {
00049         return 86400;
00050     }

getMenuArray (  ) 

Definition at line 59 of file Menu.php.

00060     {
00061         return $this->_buildMenuArray();
00062     }


Member Data Documentation

$_url [protected]

Definition at line 36 of file Menu.php.

const CACHE_TAGS = 'BACKEND_MAINMENU'

Definition at line 37 of file Menu.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:22:53 2009 for Magento by  doxygen 1.5.8