From 1d960150de785261da282e1505360e97ee144493 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 30 Mar 2010 12:01:20 -0300 Subject: Adding PhpIsis implementation of IsisDb --- classes/MaleteDb.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ classes/PhpIsisDb.php | 51 ++++++++++++++++++++++++++++++++++++++++++++ classes/SchemaDb.php | 29 ++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 classes/MaleteDb.php create mode 100644 classes/PhpIsisDb.php create mode 100644 classes/SchemaDb.php (limited to 'classes') diff --git a/classes/MaleteDb.php b/classes/MaleteDb.php new file mode 100644 index 0000000..9e8684f --- /dev/null +++ b/classes/MaleteDb.php @@ -0,0 +1,58 @@ +format = $schema; + + // Setup $fdt used by malete. + foreach ($schema['fields'] as $field => $info) { + $this->fdt[$field] = $info['name']; + } + + // Open a database connection. + $this->db = new Isis_Db($this->fdt, $schema['db']['name'], new Isis_Server()); + if (!$this->db->srv->sock) { + return FALSE; + } + } + + public function read($id) { + if (!is_numeric($id)) { + return FALSE; + } + $results = $this->db->read($id); + return $this->tag($results); + } + + public function rows() { + } + + public function default_schema() { + return SchemaDb::default_schema(); + } + + // Tag results of a db query. + function tag($results) { + foreach ($results->val as $key => $value) { + $field = $results->tag[$key]; + $name = $this->format['fields'][$field]['name']; + + // Handles field repetition. + if ($this->format['fields'][$field]['repeat']) { + $data[$name][] = $value; + } + else { + $data[$name] = $value; + } + } + return $data; + } +} diff --git a/classes/PhpIsisDb.php b/classes/PhpIsisDb.php new file mode 100644 index 0000000..4e1aaf0 --- /dev/null +++ b/classes/PhpIsisDb.php @@ -0,0 +1,51 @@ +format = $schema; + + // Setup $fdt used by malete. + foreach ($schema['fields'] as $field => $info) { + $this->fdt[$field] = $info['name']; + } + + // Open the database. + $name = $schema['db']['name']; + $this->db = isis_open("db/$name/$name"); + } + + public function read($id) { + $results = isis_search('$', $this->db); + if (!isis_data_seek($results, $id)) { + return FALSE; + } + + return $this->tag(isis_fetch_array($results)); + } + + public function rows() { + return isis_last_mfn($this->db); + } + + public function default_schema() { + return SchemaDb::default_schema(); + } + + // Tag results of a db query. + function tag($results) { + foreach ($results as $key => $value) { + if ($key != 'mfn') { + $name = $this->format['fields'][$key]['name']; + $data[$name] = $value; + } + } + return $data; + } +} diff --git a/classes/SchemaDb.php b/classes/SchemaDb.php new file mode 100644 index 0000000..ac5a40e --- /dev/null +++ b/classes/SchemaDb.php @@ -0,0 +1,29 @@ + array( + 'name' => 'dbname', + 'charset' => 'charset', + ), + 'fields' => array( + 1 => array( + 'name' => 'field_name', + 'size' => 1000, + 'format' => 'numeric', + 'repeat' => TRUE, + 'subfields' => array( + 'a' => 'test', + 'b' => 'test2', + ), + ), + ), + ); + + return $schema; + } +} -- cgit v1.2.3