|
From: <gem...@li...> - 2011-11-07 15:30:30
|
Revision: 188
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=188&view=rev
Author: mennodekker
Date: 2011-11-07 15:30:23 +0000 (Mon, 07 Nov 2011)
Log Message:
-----------
Allow optional parameters in a menuItem
Further improvements for #34
Modified Paths:
--------------
trunk/library/classes/Gems/Menu/SubMenuItem.php
trunk/library/classes/Gems/Upgrades.php
trunk/library/classes/Gems/UpgradesAbstract.php
Modified: trunk/library/classes/Gems/Menu/SubMenuItem.php
===================================================================
--- trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-11-07 13:48:32 UTC (rev 187)
+++ trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-11-07 15:30:23 UTC (rev 188)
@@ -127,8 +127,8 @@
private function _applyParameterSource($source, $paramFunction, array &$parameters)
{
// Fill in required parameters
- if ($this->_requiredParameters) {
- foreach ($this->_requiredParameters as $param => $name) {
+ if ($this->_parameters && is_array($this->_parameters)) {
+ foreach ($this->_parameters as $param => $name) {
$default = isset($parameters[$param]) ? $parameters[$param] : null;
@@ -491,18 +491,35 @@
$params = MUtil_Ra::pairs(func_get_args());
if (true === $this->_parameters) {
- $this->_parameters = new MUtil_Lazy_ArrayWrap();
+ $this->_parameters = array();
}
foreach ($params as $param => $name) {
if (is_int($param)) {
$param = $name;
}
$this->_requiredParameters[$param] = $name;
- $this->_parameters[$param] = MUtil_Lazy::L($name);
+ $this->_parameters[$param] = $name;
}
return $this;
}
+ public function addOptionalParameters($arrayOrKey1 = null, $altName1 = null)
+ {
+ $params = MUtil_Ra::pairs(func_get_args());
+
+ if (true === $this->_parameters) {
+ $this->_parameters = array();
+ }
+ foreach ($params as $param => $name) {
+ if (is_int($param)) {
+ $param = $name;
+ }
+ //$this->_requiredParameters[$param] = $name;
+ $this->_parameters[$param] = $name;
+ }
+ return $this;
+ }
+
public function addParameters($arrayOrKey1 = null, $key2 = null)
{
$param = MUtil_Ra::args(func_get_args());
Modified: trunk/library/classes/Gems/Upgrades.php
===================================================================
--- trunk/library/classes/Gems/Upgrades.php 2011-11-07 13:48:32 UTC (rev 187)
+++ trunk/library/classes/Gems/Upgrades.php 2011-11-07 15:30:23 UTC (rev 188)
@@ -55,7 +55,7 @@
//Now set the context
$this->setContext('gems');
//And add our patches
- $this->register('Upgrade143to15');
+ $this->register('Upgrade143to15', 'Upgrade from 1.43 to 1.5');
}
Modified: trunk/library/classes/Gems/UpgradesAbstract.php
===================================================================
--- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-07 13:48:32 UTC (rev 187)
+++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-07 15:30:23 UTC (rev 188)
@@ -148,17 +148,26 @@
$to = $this->getMaxLevel($context);
}
if(is_null($from)) {
- $from = $this->getLevel($context);
+ $from = $this->getNextLevel();
+
+ if ($from > $to) {
+ $this->addMessage($this->_('Already at max. level.'));
+ return $to;
+ }
}
- $from = max(1, $from);
+ $from = max(1, intval($from));
+ $to = intval($to);
$this->addMessage(sprintf($this->_('Trying upgrade for %s from level %s to level %s'), $context, $from, $to));
$success = false;
- for($level = $from; $level<=$to; $level++) {
- if (isset($this->_upgradeStack[$context][$level]) && is_callable($this->_upgradeStack[$context][$level])) {
- $this->addMessage(sprintf($this->_('Trying upgrade for %s to level %s'), $context, $level));
- if (call_user_func($this->_upgradeStack[$context][$level])) {
+ $upgrades = $this->_upgradeStack[$context];
+ ksort($upgrades);
+ $this->_upgradeStack[$context] = $upgrades;
+ foreach($this->_upgradeStack[$context] as $level => $upgrade) {
+ if (($level > $from && $level <= $to)) {
+ $this->addMessage(sprintf($this->_('Trying upgrade for %s to level %s: %s'), $context, $level, $this->_upgradeStack[$context][$level]['info']));
+ if (call_user_func($upgrade['upgrade'])) {
$success = $level;
$this->addMessage('OK');
} else {
@@ -209,6 +218,38 @@
}
}
+ /**
+ * Get the next level for a given level and context
+ *
+ * When context is null, it will get the current context
+ * When level is null, it will get the current level
+ *
+ * @param type $level
+ * @param type $context
+ * @return type
+ */
+ public function getNextLevel($context = null, $level = null) {
+ if (is_null($context)) {
+ $context = $this->getContext();
+ }
+ if (is_null($level)) {
+ $level = $this->getLevel($context);
+ }
+
+ //Get all the levels
+ $currentContext = $this->_upgradeStack[$context];
+ ksort($currentContext);
+ $levels = array_keys($this->_upgradeStack[$context]);
+ //Find the index of the current one
+ $current = array_search($level, $levels);
+
+ //And if it is present, return the next level
+ if (isset($levels[$current++])) return $levels[$current++];
+
+ //Else return current level +1 (doesn't exist anyway)
+ return $level++;
+ }
+
public function getMessages()
{
return $this->_messages;
@@ -251,7 +292,7 @@
}
}
- public function register($callback, $index = null, $context = null)
+ public function register($callback, $info = null, $index = null, $context = null)
{
if (is_string($callback)) {
$callback = array(get_class($this), $callback);
@@ -275,7 +316,8 @@
$index++;
}
- $this->_upgradeStack[$context][$index] = $callback;
+ $this->_upgradeStack[$context][$index]['upgrade'] = $callback;
+ $this->_upgradeStack[$context][$index]['info'] = $info;
return true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|