From 7e5935d5325a7bc20fb5603a76a5af4d7df499a9 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 10 Dec 2008 19:44:58 +0000 Subject: Create a module parameter table. This will be useful if a module wants to store information, but is not enough to warrant a table of its own --- core/helpers/core_installer.php | 10 ++++++++++ core/helpers/module.php | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'core/helpers') diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index 052b9cb5..95d46597 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -82,6 +82,15 @@ class core_installer { UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE `parameters` ( + `id` int(9) NOT NULL auto_increment, + `module_id` int(9), + `name` char(255) NOT NULL, + `value` text, + PRIMARY KEY (`id`), + UNIQUE KEY(`module_id`, `name`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + foreach (array("albums", "resizes") as $dir) { @mkdir(VARPATH . $dir); } @@ -115,6 +124,7 @@ class core_installer { $db->query("DROP TABLE IF EXISTS `permissions`;"); $db->query("DROP TABLE IF EXISTS `items`;"); $db->query("DROP TABLE IF EXISTS `modules`;"); + $db->query("DROP TABLE IF EXISTS `parameters`;"); system("/bin/rm -rf " . VARPATH . "albums"); system("/bin/rm -rf " . VARPATH . "resizes"); } diff --git a/core/helpers/module.php b/core/helpers/module.php index c841ca94..cc1823b4 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -88,4 +88,28 @@ class module_Core { } catch (Exception $e) { } } + + public function get_parameter($module_name, $name, $default_value=null) { + $module = ORM::factory("module")->where("name", $module_name)->find(); + $parameter = ORM::factory("parameter") + ->where("module_id", $module->id) + ->where("name", $name) + ->find(); + return $parameter->loaded ? $parameter->value : $default_value; + } + + public function set_parameter($module_name, $name, $value) { + $module = ORM::factory("module")->where("name", $module_name)->find(); + $parameter = ORM::factory("parameter") + ->where("module_id", $module->id) + ->where("name", $name) + ->find(); + if (!$parameter->loaded) { + $parameter = ORM::factory("parameter"); + $parameter->module_id = $module->id; + $parameter->name = $name; + } + $parameter->value = $value; + $parameter->save(); + } } -- cgit v1.2.3