summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-01-08 02:46:09 +0000
committerBharat Mediratta <bharat@menalto.com>2009-01-08 02:46:09 +0000
commit58c8b3b0315405094c448da6486354250914ea6f (patch)
tree6613a4a6a03ddadc287a6c8cc4d78dc6240c5dd9
parent8620c3fa01cb37506976a944f151d3058b587062 (diff)
module::event now takes an unlimited number of args
added module::incr_var() ftw.
-rw-r--r--core/helpers/module.php17
-rw-r--r--core/tests/Var_Test.php13
2 files changed, 29 insertions, 1 deletions
diff --git a/core/helpers/module.php b/core/helpers/module.php
index 498bf865..9bce7a44 100644
--- a/core/helpers/module.php
+++ b/core/helpers/module.php
@@ -204,7 +204,9 @@ class module_Core {
$class = "{$module->name}_event";
$function = str_replace(".", "_", $name);
if (method_exists($class, $function)) {
- call_user_func_array(array($class, $function), array(&$data));
+ $args = func_get_args();
+ array_shift($args);
+ call_user_func_array(array($class, $function), $args);
}
}
}
@@ -245,6 +247,19 @@ class module_Core {
}
/**
+ * Increment the value of a variable for this module
+ * @param string $module_name
+ * @param string $name
+ * @param string $increment (optional, default is 1)
+ */
+ public function incr_var($module_name, $name, $increment=1) {
+ Database::instance()->query(
+ "UPDATE `vars` SET `value` = `value` + $increment " .
+ "WHERE `module_name` = '$module_name' " .
+ "AND `name` = '$name'");
+ }
+
+ /**
* Remove a variable for this module.
* @param string $module_name
* @param string $name
diff --git a/core/tests/Var_Test.php b/core/tests/Var_Test.php
index de07ba52..7f356d30 100644
--- a/core/tests/Var_Test.php
+++ b/core/tests/Var_Test.php
@@ -33,4 +33,17 @@ class Var_Test extends Unit_Test_Case {
module::clear_var("core", "Parameter");
$this->assert_equal(null, module::get_var("core", "Parameter"));
}
+
+ public function incr_parameter_test() {
+ module::set_var("core", "Parameter", "original value");
+ module::incr_var("core", "Parameter");
+ $this->assert_equal("1", module::get_var("core", "Parameter"));
+
+ module::set_var("core", "Parameter", "2");
+ module::incr_var("core", "Parameter", "9");
+ $this->assert_equal("11", module::get_var("core", "Parameter"));
+
+ module::incr_var("core", "NonExistent", "9");
+ $this->assert_equal(null, module::get_var("core", "NonExistent"));
+ }
} \ No newline at end of file