From 1f0a5aa6b243e2b8bba66fc62bd029e2fa801e4b Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 8 Apr 2010 11:55:02 -0300 Subject: Sorting out folder schene --- classes/CinisisDb.php | 41 +++++++++- classes/PhpIsisDb.php | 4 +- index.php | 27 +------ tests/index.php | 216 +++++--------------------------------------------- tests/malete.php | 181 ++++++++++++++++++++++++++++++++++++++++++ tests/phpisis.php | 30 +++++++ 6 files changed, 275 insertions(+), 224 deletions(-) create mode 100644 tests/malete.php create mode 100644 tests/phpisis.php diff --git a/classes/CinisisDb.php b/classes/CinisisDb.php index 3dead27..eb09f9e 100644 --- a/classes/CinisisDb.php +++ b/classes/CinisisDb.php @@ -23,16 +23,16 @@ class CinisisDb { * Optional parameter to set alternative config file or array * with configuration. */ - function __construct($config = 'config/config.yaml') { + function __construct($config = NULL) { try { // Check main configuration. - $config = $this->parse($config); + $config = $this->parse($this->file($config)); // Set database implementation. $this->implementation = $config['implementation'] .'Db'; // Check database schema. - $schema = $this->parse('schemas/'. $config['database'] .'.yaml', $this->implementation); + $schema = $this->parse($this->file($config['database'] .'.yaml', 'schemas'), $this->implementation); } catch (Exception $e) { echo __CLASS__ .' caught exception: ', $e->getMessage(), "\n"; return FALSE; @@ -106,4 +106,39 @@ class CinisisDb { return $config; } + + /** + * Get library base folder. + * + * @return + * Return base folder. + */ + public function base() { + global $cinisis_basedir; + return $cinisis_basedir; + } + + /** + * Get a file path. + * + * @param $config + * Config file name (either relative to the library or absolute). + * + * @param $section + * Config file section (ignored for absolute files). + * + * @return + * Return the assembled file path. + */ + public function file($config = NULL, $section = 'config') { + // Check for NULL or relative config path. + if ($config == NULL) { + $config = "$section/config.yaml"; + } + elseif (substr($config, 0, 1) != '/') { + $config = "$section/$config"; + } + + return call_user_func(array(__CLASS__, 'base')) .'/'. $config; + } } diff --git a/classes/PhpIsisDb.php b/classes/PhpIsisDb.php index a6b3c7e..c568743 100644 --- a/classes/PhpIsisDb.php +++ b/classes/PhpIsisDb.php @@ -32,7 +32,7 @@ class PhpIsisDb implements IsisDb { // Open the database. $name = $schema['db']['name']; - $this->db = isis_open("db/$name/$name"); + $this->db = isis_open(CinisisDb::file("$name/$name", 'db')); } /** @@ -57,7 +57,7 @@ class PhpIsisDb implements IsisDb { $data = $this->tag(isis_fetch_array($results)); // Charset conversion. - array_walk_recursive($data, array('PhpIsisDb', 'charset')); + array_walk_recursive($data, array(__CLASS__, 'charset')); // Return the result. return $data; diff --git a/index.php b/index.php index e93d0eb..b045be7 100644 --- a/index.php +++ b/index.php @@ -20,30 +20,7 @@ function cinisis_autoload($class) { // Register autoloader. spl_autoload_register("cinisis_autoload"); -// Get a db instance. -$isis = new CinisisDb(); +// Reference to the base path. +$cinisis_basedir = dirname(__FILE__); ?> - - - - - - - -db) { - $result = $isis->db->read(1); - $rows = $isis->db->rows(); - - // Format output. - echo '
';
-  echo "Rows: $rows\n";
-  print_r($result);
-  echo '
'; -} - -?> - diff --git a/tests/index.php b/tests/index.php index 195fbbc..0f7b243 100644 --- a/tests/index.php +++ b/tests/index.php @@ -1,207 +1,35 @@ - -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...

+// Import Malete Library. +require_once '../index.php'; -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

-db) { + $result = $isis->db->read(1); + $rows = $isis->db->rows(); - echo ''; + // Format output. + echo '
';
+  echo "Rows: $rows\n";
+  print_r($result);
+  echo '
'; +} - $result = isis_search('$', $db); - while ($record = isis_fetch_flat_array($result) ) { - print (" \n"); - for ($i=0; $i\n". - " \n". - " \n". - " \n"); - } - } - echo '
MFN: $record[mfn]
$tag".htmlspecialchars($value)."
'; ?> - + diff --git a/tests/malete.php b/tests/malete.php new file mode 100644 index 0000000..03451f2 --- /dev/null +++ b/tests/malete.php @@ -0,0 +1,181 @@ + + +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}; +?> + +

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 + +?> + + diff --git a/tests/phpisis.php b/tests/phpisis.php new file mode 100644 index 0000000..d04fbd9 --- /dev/null +++ b/tests/phpisis.php @@ -0,0 +1,30 @@ + + +

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