|
From: <gem...@li...> - 2012-06-28 14:17:55
|
Revision: 796
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=796&view=rev
Author: matijsdejong
Date: 2012-06-28 14:17:45 +0000 (Thu, 28 Jun 2012)
Log Message:
-----------
Container menu items are in a class of their own
Allows empty privilege: container only shown when one of the sub items is allowed
Modified Paths:
--------------
trunk/library/classes/Gems/Menu/MenuAbstract.php
trunk/library/classes/Gems/Menu/SubMenuItem.php
trunk/library/classes/Gems/Menu.php
Added Paths:
-----------
trunk/library/classes/Gems/Menu/ContainerItem.php
Added: trunk/library/classes/Gems/Menu/ContainerItem.php
===================================================================
--- trunk/library/classes/Gems/Menu/ContainerItem.php (rev 0)
+++ trunk/library/classes/Gems/Menu/ContainerItem.php 2012-06-28 14:17:45 UTC (rev 796)
@@ -0,0 +1,130 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Menu
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * A container item is one that gathers multiple sub menu
+ * items, but does not have it's own controller/action pair
+ * but selects the first sub item instead.
+ *
+ * @package Gems
+ * @subpackage Menu
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5.5
+ */
+class Gems_Menu_ContainerItem extends Gems_Menu_SubMenuItem
+{
+ /**
+ * Returns a Zend_Navigation creation array for this menu item, with
+ * sub menu items in 'pages'
+ *
+ * @param Gems_Menu_ParameterCollector $source
+ * @return array
+ */
+ protected function _toNavigationArray(Gems_Menu_ParameterCollector $source)
+ {
+ $result = parent::_toNavigationArray($source);
+
+ // Get any missing MVC keys from children, even when invisible
+ if ($requiredIndices = $this->notSet('controller', 'action')) {
+
+ if (isset($result['pages'])) {
+ $firstChild = null;
+ $order = 0;
+ foreach ($result['pages'] as $page) {
+ if ($page['allowed']) {
+ if ($page['order'] < $order || $order == 0) {
+ $firstChild = $page;
+ $order = $page['order'];
+ }
+ }
+ }
+
+ if (null === $firstChild) {
+ // No children are visible and required mvc properties
+ // are missing: ergo this page is not visible.
+ $result['visible'] = false;
+
+ // Use first (invisible) child as firstChild
+ $firstChild = reset($result['pages']);
+ }
+ } else {
+ // Use '/' slash as default to ensure any not visible
+ // menu items points to another existing item that is
+ // active.
+ $firstChild = array_fill_keys($requiredIndices, '/');
+ }
+
+ foreach ($requiredIndices as $key) {
+ $result[$key] = $firstChild[$key];
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * Set the visibility of the menu item and any sub items in accordance
+ * with the specified user role.
+ *
+ * @param Zend_Acl $acl
+ * @param string $userRole
+ * @return Gems_Menu_MenuAbstract (continuation pattern)
+ */
+ protected function applyAcl(Zend_Acl $acl, $userRole)
+ {
+ parent::applyAcl($acl, $userRole);
+
+ if ($this->isVisible()) {
+ $this->set('allowed', false);
+ $this->set('visible', false);
+
+ if ($this->_subItems) {
+ foreach ($this->_subItems as $item) {
+
+ if ($item->get('visible', true)) {
+ $this->set('allowed', true);
+ $this->set('visible', true);
+
+ return $this;
+ }
+ }
+ }
+ }
+ return $this;
+ }
+}
Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php
===================================================================
--- trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-06-28 10:08:16 UTC (rev 795)
+++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-06-28 14:17:45 UTC (rev 796)
@@ -92,6 +92,13 @@
}
}
+ /**
+ * Returns a Zend_Navigation creation array for this menu item, with
+ * sub menu items in 'pages'
+ *
+ * @param Gems_Menu_ParameterCollector $source
+ * @return array
+ */
protected function _toNavigationArray(Gems_Menu_ParameterCollector $source)
{
if ($this->_subItems) {
@@ -105,9 +112,9 @@
if (($this instanceof Gems_Menu_SubMenuItem) &&
(! $this->notSet('controller', 'action')) &&
isset($page['params'])) {
+
$params = $page['params'];
- // TODO: ugly! Make beautiful!
- unset($params['reset']);
+ unset($params['reset']); // Ignore this setting
if (count($params)) {
$class = '';
@@ -116,13 +123,6 @@
}
if ((null !== $lastParams) && ($lastParams !== $params)) {
- // $pages[$i++] = array('type' => 'uri');
- /* $l = $i - 1;
- if (isset($pages[$l]['class'])) {
- $pages[$l]['class'] .= ' breakAfter';
- } else {
- $pages[$l]['class'] = 'breakAfter';
- } // */
$class .= 'breakBefore';
} else {
$class = trim($class);
@@ -231,7 +231,24 @@
$other['privilege'] = $privilege;
}
- return $this->add($other);
+ // Process parameters.
+ $defaults = array(
+ 'visible' => (boolean) $label, // All menu containers are initally visible unless stated otherwise or specified without label
+ 'allowed' => true, // Same as with visible, need this for t_oNavigationArray()
+ 'order' => 10 * (count($this->_subItems) + 1),
+ );
+
+ foreach ($defaults as $key => $value) {
+ if (! isset($other[$key])) {
+ $other[$key] = $value;
+ }
+ }
+
+ $page = new Gems_Menu_ContainerItem($this->escort, $this, $other);
+
+ $this->_subItems[] = $page;
+
+ return $page;
}
/**
@@ -355,7 +372,7 @@
// MUtil_Echo::track($infoPage->_toNavigationArray(array($this->escort->request)));
} else {
if ($this->escort instanceof Gems_Project_Tracks_StandAloneSurveysInterface) {
- $infoPage = $this->addContainer($label, 'pr.project');
+ $infoPage = $this->addContainer($label);
$tracksPage = $infoPage->addPage($this->_('Tracks'), 'pr.project', 'project-tracks');
$tracksPage->addAutofilterAction();
@@ -469,7 +486,15 @@
return $setup;
}
- public function applyAcl(Zend_Acl $acl, $userRole)
+ /**
+ * Set the visibility of the menu item and any sub items in accordance
+ * with the specified user role.
+ *
+ * @param Zend_Acl $acl
+ * @param string $userRole
+ * @return Gems_Menu_MenuAbstract (continuation pattern)
+ */
+ protected function applyAcl(Zend_Acl $acl, $userRole)
{
if ($this->_subItems) {
$anyVisible = false;
@@ -498,12 +523,12 @@
}
}
- // Do not show a 'container' menu item (that depends for controller
+ /*/ Do not show a 'container' menu item (that depends for controller
// on it's children) when no sub item is allowed.
if ((! $anyVisible) && $this->notSet('controller', 'action')) {
$this->set('allowed', false);
$this->set('visible', false);
- }
+ } // */
}
return $this;
Modified: trunk/library/classes/Gems/Menu/SubMenuItem.php
===================================================================
--- trunk/library/classes/Gems/Menu/SubMenuItem.php 2012-06-28 10:08:16 UTC (rev 795)
+++ trunk/library/classes/Gems/Menu/SubMenuItem.php 2012-06-28 14:17:45 UTC (rev 796)
@@ -253,6 +253,13 @@
}
}
+ /**
+ * Returns a Zend_Navigation creation array for this menu item, with
+ * sub menu items in 'pages'
+ *
+ * @param Gems_Menu_ParameterCollector $source
+ * @return array
+ */
protected function _toNavigationArray(Gems_Menu_ParameterCollector $source)
{
$result = $this->_itemOptions;
@@ -270,41 +277,6 @@
$result['pages'] = parent::_toNavigationArray($source);
}
- // Get any missing MVC keys from children, even when invisible
- if ($requiredIndices = $this->notSet('controller', 'action')) {
-
- if (isset($result['pages'])) {
- $firstChild = null;
- $order = 0;
- foreach ($result['pages'] as $page) {
- if ($page['allowed']) {
- if ($page['order'] < $order || $order == 0) {
- $firstChild = $page;
- $order = $page['order'];
- }
- }
- }
-
- if (null === $firstChild) {
- // No children are visible and required mvc properties
- // are missing: ergo this page is not visible.
- $result['visible'] = false;
-
- // Use first (invisible) child as firstChild
- $firstChild = reset($result['pages']);
- }
- } else {
- // Use '/' slash as default to ensure any not visible
- // menu items points to another existing item that is
- // active.
- $firstChild = array_fill_keys($requiredIndices, '/');
- }
-
- foreach ($requiredIndices as $key) {
- $result[$key] = $firstChild[$key];
- }
- }
-
return $result;
}
Modified: trunk/library/classes/Gems/Menu.php
===================================================================
--- trunk/library/classes/Gems/Menu.php 2012-06-28 10:08:16 UTC (rev 795)
+++ trunk/library/classes/Gems/Menu.php 2012-06-28 14:17:45 UTC (rev 796)
@@ -89,7 +89,7 @@
$this->loadProjectMenu();
$this->setOnlyActiveBranchVisible();
- $this->applyAcl($escort->acl, $escort->session->user_role);
+ $this->applyAcl($escort->acl, $escort->getLoader()->getCurrentUser()->getRole());
}
private function _findPath($request)
@@ -589,10 +589,10 @@
$this->addMailSetupMenu($this->_('Mail'));
// EXPORT DATA
- $this->addContainer('Export data', 'pr.export', array('controller'=>'export', 'action'=>'index'));
+ $this->addPage('Export data', 'pr.export', 'export', 'index');
// EXPORT TO HTML
- $this->addContainer($this->_('Export respondent'), 'pr.export-html', array('controller' => 'respondent-export', 'action'=>'index'));
+ $this->addPage($this->_('Export respondent'), 'pr.export-html', 'respondent-export', 'index');
// OTHER ITEMS
$this->addLogonOffToken();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|