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 +++++++ index.php | 18 +++-- interface.php | 21 +++++ isis.php | 117 ---------------------------- test.php | 207 -------------------------------------------------- tests/index.php | 207 ++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 378 insertions(+), 330 deletions(-) create mode 100644 classes/MaleteDb.php create mode 100644 classes/PhpIsisDb.php create mode 100644 classes/SchemaDb.php create mode 100644 interface.php delete mode 100644 isis.php delete mode 100644 test.php create mode 100644 tests/index.php 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; + } +} diff --git a/index.php b/index.php index 423485e..62a58dd 100644 --- a/index.php +++ b/index.php @@ -1,20 +1,26 @@ read(4); echo '
';
diff --git a/interface.php b/interface.php
new file mode 100644
index 0000000..5ba5a55
--- /dev/null
+++ b/interface.php
@@ -0,0 +1,21 @@
+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 fields($id = NULL) {
-  }
-
-  public function subfields($id = NULL) {
-  }
-
-  public function read($id) {
-    if (!is_numeric($id)) {
-      return FALSE;
-    }
-    $results = $this->db->read($id);
-    return $this->tag($results);
-  }
-
-  public function rows() {
-  }
-
-  /**
-   * Schema format example.
-   */
-  public function default_schema() {
-    $schema = array(
-      'db'             => array(
-        'name'         => 'dbname',
-      ),
-      'fields'         => array(
-        1              => array(
-          'name'       => 'field_name',
-          'size'       => 1000,
-          'format'     => 'numeric',
-          'repeat'     => TRUE,
-          'subfields'  => array(
-            'a'        => 'test',
-            'b'        => 'test2',
-          ),
-        ),
-      ),
-    );
-
-    return $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;
-  }
-}
-
-/**
- * PHP-Isis implementation of IsisDb.
- */
-class PhpIsis implements IsisDb {
-}
diff --git a/test.php b/test.php
deleted file mode 100644
index 195fbbc..0000000
--- a/test.php
+++ /dev/null
@@ -1,207 +0,0 @@
-
-
-Query
-
-  1,
-		  'Data'                 =>  2,
-		  'Titulo'               =>  3,
-		  'Autor'                =>  4,
-		  'Assuntos primarios'   =>  5,
-		  'Assuntos secundarios' =>  6,
-		  'Ilustrado'            =>  7,
-		  'Caderno'              =>  8,
-		  'Pagina'               =>  9,
-		  'Arquivo digital'      => 10,
-		  'Forma documento'      => 11,
-		  'Local de publicacao'  => 12,
-		  'Observacoes'          => 13,
-		  'Descritores imagem'   => 14,
-		  'Termo geografico'     => 16,
-		  'Coluna'               => 17,
-		  'Recorte'              => 19,
-		  'Alimentador'          => 20,
-		  'Tema Anuario'         => 21,
-    );
-
-  $fdt_tupi = array(
-		  'cod.titulo'                  => 1,
-		  'postopo'                     => 2,
-		  'num.entrada'                 => 3,
-		  'num.tombo'                   => 4,
-		  'datain'                      => 5,
-		  'dataex'                      => 6,
-		  'acervo (DIF ou PRE)'         => 7,
-		  'cadarq'                      => 10,
-		  'caddep'                      => 11,
-		  'cadddl'                      => 12,
-		  'outarq'                      => 13,
-		  'categorias'                  => 15,
-		  'presok'                      => 16,
-		  'roteiro de locução'          => 17,
-		  'mat.acervo'                  => 18,
-		  'mat.orig'                    => 19,
-		  'titulo'                      => 20,
-		  'outros titulos'              => 22,
-		  'data/série'                  => 24,
-		  'conteudo/sinopse'            => 25,
-		  'descritores'                 => 26,
-		  'descritores secundários'     => 27,
-		  'identidades'                 => 28,
-		  'ndxlib'                      => 29,
-		  'materiais'                   => 40,
-		  'materiais'                   => 41,
-		  'materiais'                   => 42,
-		  'materiais'                   => 43,
-		  'materiais'                   => 44,
-		  'materiais'                   => 45,
-		  'mat'                         => 46,
-		  'mat'                         => 47,
-		  'mat'                         => 48,
-		  'mat'                         => 49,
-		  'mat'                         => 50,
-		  'mat'                         => 51,
-		  'mat'                         => 52,
-		  'mat'                         => 53,
-		  'mat'                         => 54,
-		  'mat'                         => 55,
-		  'evol.estado tec.'            => 56,
-		  'movimentacao'                => 57,
-		  'movimentacao'                => 58,
-		  'obsmat'                      => 59,
-		  'producao*'                   => 60,
-		  'dir.arte*'                   => 61,
-		  'fotografia*'                 => 62,
-		  'musica*'                     => 63,
-		  'som*'                        => 64,
-		  'montagem*'                   => 65,
-		  'direcao*'                    => 66,
-		  'arg/roteiro*'                => 67,
-		  'distribuicao*'               => 68,
-		  'colab./outros'               => 69,
-		  'producao1'                   => 70,
-		  'dir.arte1'                   => 71,
-		  'fotografia1'                 => 72,
-		  'musica1'                     => 73,
-		  'som1'                        => 74,
-		  'montagem1'                   => 75,
-		  'producao2(res.p/expandir)'   => 80,
-		  'dir.arte2(res.p/expandir)'   => 81,
-		  'fotografia2(res.p/expandir)' => 82,
-		  'musica2(res.p/expandir)'     => 83,
-		  'som2(res.p/expandir)'        => 84,
-		  'loc.prod.lan'                => 85,
-		  'dat.prod.lan'                => 86,
-		  'lab/est/locacoes'            => 87,
-		  'premios'                     => 88,
-		  'fontes'                      => 89,
-		  'certificados'                => 95,
-		  'examinador'                  => 98,
-		  'observações'                 => 99,
-		  'termos geográficos'          => 165,
-		  'quicktime'                   => 900,
-		  'revisão'                     => 901,
-		  'vídeo'                       => 902,
-    );
-
-  //$db   = 'tupi';
-  $db   = 'anu10';
-  $fdt  = ${'fdt_'. $db};
-  $yaml = Spyc::YAMLDump($fdt);
-?>
-
-

server

- -srv->sock) { - echo "could not contact server\n"; - } - else { - //print_r($db); -?> - -

number of records...

- -num_recs($query); - echo "got ",count($recs), " terms for '$query'
\n"; -?> - -

terms beginning with...

- -terms(strtoupper($query)); - echo "got ",count($terms), " terms for '$query'
\n"; - foreach ($terms as $t) { - list($cnt, $term) = explode("\t", $t); - echo "'$term'($cnt) "; - } - echo "
\n"; -?> - -

query reading records

- -query(strtoupper($query)); - echo "got ",count($recs), " records for '$query'
\n"; - foreach ($recs as $r) { - echo "
---\n", $r->toString(), "---\n
\n"; - } -?> - -

query reading a record

- -read(6); - echo "
---\n", $r->toString(), "---\n

\n"; - echo '
';
-    //print_r($r);
-    //print_r($r->val[8]);
-    //print_r(preg_split('/\t/', $r->val[7]));
-    //print_r(array_flip($fdt_anu10));
-    echo '
'; - } // end else could contact server - -?> - -

Testing pecl-isis

-'; - - $result = isis_search('$', $db); - while ($record = isis_fetch_flat_array($result) ) { - print (" MFN: $record[mfn]\n"); - for ($i=0; $i\n". - " $tag\n". - " ".htmlspecialchars($value)."\n". - " \n"); - } - } - echo ''; -?> - diff --git a/tests/index.php b/tests/index.php new file mode 100644 index 0000000..195fbbc --- /dev/null +++ b/tests/index.php @@ -0,0 +1,207 @@ + + +Query + + 1, + 'Data' => 2, + 'Titulo' => 3, + 'Autor' => 4, + 'Assuntos primarios' => 5, + 'Assuntos secundarios' => 6, + 'Ilustrado' => 7, + 'Caderno' => 8, + 'Pagina' => 9, + 'Arquivo digital' => 10, + 'Forma documento' => 11, + 'Local de publicacao' => 12, + 'Observacoes' => 13, + 'Descritores imagem' => 14, + 'Termo geografico' => 16, + 'Coluna' => 17, + 'Recorte' => 19, + 'Alimentador' => 20, + 'Tema Anuario' => 21, + ); + + $fdt_tupi = array( + 'cod.titulo' => 1, + 'postopo' => 2, + 'num.entrada' => 3, + 'num.tombo' => 4, + 'datain' => 5, + 'dataex' => 6, + 'acervo (DIF ou PRE)' => 7, + 'cadarq' => 10, + 'caddep' => 11, + 'cadddl' => 12, + 'outarq' => 13, + 'categorias' => 15, + 'presok' => 16, + 'roteiro de locução' => 17, + 'mat.acervo' => 18, + 'mat.orig' => 19, + 'titulo' => 20, + 'outros titulos' => 22, + 'data/série' => 24, + 'conteudo/sinopse' => 25, + 'descritores' => 26, + 'descritores secundários' => 27, + 'identidades' => 28, + 'ndxlib' => 29, + 'materiais' => 40, + 'materiais' => 41, + 'materiais' => 42, + 'materiais' => 43, + 'materiais' => 44, + 'materiais' => 45, + 'mat' => 46, + 'mat' => 47, + 'mat' => 48, + 'mat' => 49, + 'mat' => 50, + 'mat' => 51, + 'mat' => 52, + 'mat' => 53, + 'mat' => 54, + 'mat' => 55, + 'evol.estado tec.' => 56, + 'movimentacao' => 57, + 'movimentacao' => 58, + 'obsmat' => 59, + 'producao*' => 60, + 'dir.arte*' => 61, + 'fotografia*' => 62, + 'musica*' => 63, + 'som*' => 64, + 'montagem*' => 65, + 'direcao*' => 66, + 'arg/roteiro*' => 67, + 'distribuicao*' => 68, + 'colab./outros' => 69, + 'producao1' => 70, + 'dir.arte1' => 71, + 'fotografia1' => 72, + 'musica1' => 73, + 'som1' => 74, + 'montagem1' => 75, + 'producao2(res.p/expandir)' => 80, + 'dir.arte2(res.p/expandir)' => 81, + 'fotografia2(res.p/expandir)' => 82, + 'musica2(res.p/expandir)' => 83, + 'som2(res.p/expandir)' => 84, + 'loc.prod.lan' => 85, + 'dat.prod.lan' => 86, + 'lab/est/locacoes' => 87, + 'premios' => 88, + 'fontes' => 89, + 'certificados' => 95, + 'examinador' => 98, + 'observações' => 99, + 'termos geográficos' => 165, + 'quicktime' => 900, + 'revisão' => 901, + 'vídeo' => 902, + ); + + //$db = 'tupi'; + $db = 'anu10'; + $fdt = ${'fdt_'. $db}; + $yaml = Spyc::YAMLDump($fdt); +?> + +

server

+ +srv->sock) { + echo "could not contact server\n"; + } + else { + //print_r($db); +?> + +

number of records...

+ +num_recs($query); + echo "got ",count($recs), " terms for '$query'
\n"; +?> + +

terms beginning with...

+ +terms(strtoupper($query)); + echo "got ",count($terms), " terms for '$query'
\n"; + foreach ($terms as $t) { + list($cnt, $term) = explode("\t", $t); + echo "'$term'($cnt) "; + } + echo "
\n"; +?> + +

query reading records

+ +query(strtoupper($query)); + echo "got ",count($recs), " records for '$query'
\n"; + foreach ($recs as $r) { + echo "
---\n", $r->toString(), "---\n
\n"; + } +?> + +

query reading a record

+ +read(6); + echo "
---\n", $r->toString(), "---\n

\n"; + echo '
';
+    //print_r($r);
+    //print_r($r->val[8]);
+    //print_r(preg_split('/\t/', $r->val[7]));
+    //print_r(array_flip($fdt_anu10));
+    echo '
'; + } // end else could contact server + +?> + +

Testing pecl-isis

+'; + + $result = isis_search('$', $db); + while ($record = isis_fetch_flat_array($result) ) { + print (" MFN: $record[mfn]\n"); + for ($i=0; $i\n". + " $tag\n". + " ".htmlspecialchars($value)."\n". + " \n"); + } + } + echo ''; +?> + -- cgit v1.2.3