From 5ef8199dae8f49cf04888799f1257beef0d2a0e0 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 7 Jun 2016 18:17:39 -0700 Subject: Finish the config family --- Zotlabs/Lib/IConfig.php | 165 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 Zotlabs/Lib/IConfig.php (limited to 'Zotlabs/Lib/IConfig.php') diff --git a/Zotlabs/Lib/IConfig.php b/Zotlabs/Lib/IConfig.php new file mode 100644 index 000000000..28c9ab58e --- /dev/null +++ b/Zotlabs/Lib/IConfig.php @@ -0,0 +1,165 @@ + $family, 'k' => $key, 'v' => $value, 'sharing' => $sharing); + + if(is_null($idx)) + $item['iconfig'][] = $entry; + else + $item['iconfig'][$idx] = $entry; + return $value; + } + + if(intval($item)) + $iid = intval($item); + + if(! $iid) + return false; + + if(self::Get($item, $family, $key) === false) { + $r = q("insert into iconfig( iid, cat, k, v, sharing ) values ( %d, '%s', '%s', '%s', %d ) ", + intval($iid), + dbesc($family), + dbesc($key), + dbesc($dbvalue), + intval($sharing) + ); + } + else { + $r = q("update iconfig set v = '%s', sharing = %d where iid = %d and cat = '%s' and k = '%s' ", + dbesc($dbvalue), + intval($sharing), + intval($iid), + dbesc($family), + dbesc($key) + ); + } + + if(! $r) + return false; + + return $value; + } + + + + static public function Delete(&$item, $family, $key) { + + + $is_item = false; + $idx = null; + + if(is_array($item)) { + $is_item = true; + if(is_array($item['iconfig'])) { + for($x = 0; $x < count($item['iconfig']); $x ++) { + if($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) { + unset($item['iconfig'][$x]); + } + } + } + return true; + } + + if(intval($item)) + $iid = intval($item); + + if(! $iid) + return false; + + return q("delete from iconfig where iid = %d and cat = '%s' and k = '%s' ", + intval($iid), + dbesc($family), + dbesc($key) + ); + + } + +} \ No newline at end of file -- cgit v1.2.3