aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/audit.php26
-rw-r--r--apps/csv.php2
-rw-r--r--apps/field.php21
-rw-r--r--apps/index.php2
-rw-r--r--apps/repetition.php21
-rw-r--r--apps/subfield.php24
-rw-r--r--classes/Cinisis.php (renamed from classes/CinisisDb.php)4
-rw-r--r--classes/IsisAudit.php38
-rw-r--r--classes/IsisConnector.php6
-rw-r--r--classes/IsisFinder.php103
-rw-r--r--classes/backends/BiblioIsisDb.php (renamed from classes/BiblioIsisDb.php)8
-rw-r--r--classes/backends/IsisDb.php (renamed from classes/IsisDb.php)0
-rw-r--r--classes/backends/MaleteDb.php (renamed from classes/MaleteDb.php)0
-rw-r--r--classes/backends/PhpIsisDb.php (renamed from classes/PhpIsisDb.php)2
-rw-r--r--classes/backends/SchemaDb.php (renamed from classes/SchemaDb.php)0
-rw-r--r--classes/helpers/CinisisDisplayHelper.php2
-rw-r--r--index.php5
-rw-r--r--samples/read.php2
-rw-r--r--samples/test.php2
19 files changed, 205 insertions, 63 deletions
diff --git a/apps/audit.php b/apps/audit.php
new file mode 100644
index 0000000..28237b0
--- /dev/null
+++ b/apps/audit.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Cinisis - Isis db reading tool.
+ */
+
+// Import requisites.
+require_once '../index.php';
+
+// Draw the document.
+$display = new CinisisDisplayHelper('Database audit');
+
+// Get a db instance.
+$isis = new IsisAudit();
+
+// Setup database and entry number.
+if ($isis) {
+ // Run audit.
+ $result = $isis->run();
+
+ // Format output.
+ echo "<pre>\n";
+ print_r($result);
+ echo '</pre>';
+}
+
+$display->footer();
diff --git a/apps/csv.php b/apps/csv.php
index e50249b..ae99ad0 100644
--- a/apps/csv.php
+++ b/apps/csv.php
@@ -56,7 +56,7 @@ function merge_fields($data, $field) {
require_once '../index.php';
// Get a db instance.
-$isis = new CinisisDb();
+$isis = new Cinisis();
// Test connection.
if ($isis->db) {
diff --git a/apps/field.php b/apps/field.php
index 13320e6..f34bffa 100644
--- a/apps/field.php
+++ b/apps/field.php
@@ -14,28 +14,19 @@ $field = CinisisHttpHelper::get_numeric_arg('field');
$display = new CinisisDisplayHelper('Field finder');
$form = $display->form_input_text('entry', $entry);
$form .= $display->form_input_text('field', $field);
-$display->form($form, 'field.php');
+$display->form($form, basename(__FILE__));
// Get a db instance.
-$isis = new CinisisDb();
+$isis = new IsisFinder();
// Setup database and entry number.
-if ($isis->db) {
- // Get the number of entries.
- $field_name = $isis->db->format['fields'][$field]['name'];
- $entries = $isis->db->entries();
- $entry--;
-
+if ($isis) {
// Query database.
- do {
- $result = $isis->db->read(++$entry);
- if ($entry == $entries) {
- break;
- }
- } while (!isset($result[$field_name]));
+ $field_name = $isis->getFieldName($field);
+ $result = $isis->nextField($entry, $field_name);
// Navigation bar.
- $display->navbar($entry, $entries, $repetition, '&field='. $field);
+ $display->navbar($entry, $isis->entries, $repetition, '&field='. $field);
// Format output.
echo "<pre>\n";
diff --git a/apps/index.php b/apps/index.php
index 54d7d0e..cd5e5bb 100644
--- a/apps/index.php
+++ b/apps/index.php
@@ -14,7 +14,7 @@ $display = new CinisisDisplayHelper('Isis Navigator');
$display->form($display->form_input_text('entry', $entry));
// Get a db instance.
-$isis = new CinisisDb();
+$isis = new Cinisis();
// Setup database and entry number.
if ($isis->db) {
diff --git a/apps/repetition.php b/apps/repetition.php
index 7c7f245..6b7f9de 100644
--- a/apps/repetition.php
+++ b/apps/repetition.php
@@ -14,28 +14,19 @@ $field = CinisisHttpHelper::get_numeric_arg('field');
$display = new CinisisDisplayHelper('Repetition finder');
$form = $display->form_input_text('entry', $entry);
$form .= $display->form_input_text('field', $field);
-$display->form($form, 'repetition.php');
+$display->form($form, basename(__FILE__));
// Get a db instance.
-$isis = new CinisisDb();
+$isis = new IsisFinder();
// Setup database and entry number.
-if ($isis->db) {
- // Get the number of entries.
- $field_name = $isis->db->format['fields'][$field]['name'];
- $entries = $isis->db->entries();
- $entry--;
-
+if ($isis) {
// Query database.
- do {
- $result = $isis->db->read(++$entry);
- if ($entry == $entries) {
- break;
- }
- } while (!isset($result[$field_name]) || count($result[$field_name]) < 2);
+ $field_name = $isis->getFieldName($field);
+ $result = $isis->nextRepetition($entry, $field_name);
// Navigation bar.
- $display->navbar($entry, $entries, $repetition, '&field='. $field);
+ $display->navbar($entry, $isis->entries, $repetition, '&field='. $field);
// Format output.
echo "<pre>\n";
diff --git a/apps/subfield.php b/apps/subfield.php
index 93de5a9..e3d5d75 100644
--- a/apps/subfield.php
+++ b/apps/subfield.php
@@ -16,32 +16,22 @@ $display = new CinisisDisplayHelper('Subfield finder');
$form = $display->form_input_text('entry', $entry);
$form .= $display->form_input_text('field', $field);
$form .= $display->form_input_text('subfield', $subfield);
-$display->form($form, 'subfield.php');
+$display->form($form, basename(__FILE__));
// Get a db instance.
-$isis = new CinisisDb();
+$isis = new IsisFinder();
// Setup database and entry number.
-if ($isis->db) {
- // Get the number of entries.
- $field_name = $isis->db->format['fields'][$field]['name'];
- $subfield_name = $isis->db->format['fields'][$field]['subfields'][$subfield];
- $entries = $isis->db->entries();
- $entry--;
-
+if ($isis) {
// Query database.
- do {
- $result = $isis->db->read(++$entry);
- if ($entry == $entries) {
- break;
- }
- } while (!isset($result[$field_name][0][$subfield_name]));
+ $field_name = $isis->getFieldName($field);
+ $subfield_name = $isis->getSubfieldName($field, $subfield);
+ $result = $isis->nextSubfield($entry, $field_name, $subfield_name);
// Navigation bar.
- $display->navbar($entry, $entries, $repetition, '&field='. $field . '&subfield='. $subfield);
+ $display->navbar($entry, $isis->entries, $repetition, '&field='. $field . '&subfield='. $subfield);
// Format output.
- $link = $display->entry_link($entry);
echo "<pre>\n";
echo "Selected field: $field: $field_name.\n";
echo "Selected subfield: $subfield: $subfield_name.\n";
diff --git a/classes/CinisisDb.php b/classes/Cinisis.php
index a016528..8771b21 100644
--- a/classes/CinisisDb.php
+++ b/classes/Cinisis.php
@@ -1,9 +1,9 @@
<?php
/**
- * CinisisDb main class.
+ * Cinisis main class.
*/
-class CinisisDb {
+class Cinisis {
/**
* @var $db
* Database resource.
diff --git a/classes/IsisAudit.php b/classes/IsisAudit.php
new file mode 100644
index 0000000..79cbe26
--- /dev/null
+++ b/classes/IsisAudit.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Methods for auditing an Isis database.
+ */
+class IsisAudit extends IsisFinder {
+ /**
+ * Run a standard audit procedure.
+ *
+ * @todo
+ * Test.
+ */
+ public function run() {
+ foreach ($this->format['fields'] as $field) {
+ $field_name = $this->getFieldName($field);
+ $repetition = $this->nextRepetition(null, $field_name);
+
+ // Check for repetitions.
+ if ($field['repeat'] && !$repetition)
+ {
+ echo "Field $field_name is configured for repetitions but no repetitions found.\n";
+ }
+ elseif (!$field['repeat'] && $repetition) {
+ echo "Field $field_name is not configured for repetitions but a repetition was found.\n";
+ }
+
+ // Check for subfields.
+ foreach ($field['subfields'] as $subfield) {
+ $subfield_name = $this->getSubfieldName($field, $subfield);
+ $next_subfield = $isis->nextSubfield(null, $field_name, $subfield_name);
+
+ if (!$next_subfield) {
+ echo "No occurrences found for field $field_name and subfield $subfield_name\n";
+ }
+ }
+ }
+ }
+}
diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php
index c8d8234..e0c87c2 100644
--- a/classes/IsisConnector.php
+++ b/classes/IsisConnector.php
@@ -19,7 +19,7 @@ class IsisConnector {
* Config file or array.
*/
public function open($config) {
- $this->isis = new CinisisDb($config);
+ $this->isis = new Cinisis($config);
if ($this->isis->db) {
$this->entries = $this->isis->db->entries();
@@ -59,7 +59,7 @@ class IsisConnector {
*/
public function getMainItemName($field) {
$key = $this->getFieldKey($field);
- return CinisisDb::main_field_name($this->format, $key);
+ return Cinisis::main_field_name($this->format, $key);
}
/**
@@ -69,7 +69,7 @@ class IsisConnector {
* Boolean.
*/
public function joinSubfields() {
- if (CinisisDb::join_subfields($this->format)) {
+ if (Cinisis::join_subfields($this->format)) {
return TRUE;
}
diff --git a/classes/IsisFinder.php b/classes/IsisFinder.php
new file mode 100644
index 0000000..36732b5
--- /dev/null
+++ b/classes/IsisFinder.php
@@ -0,0 +1,103 @@
+<?php
+
+/**
+ * Provides Isis Database search methods.
+ */
+class IsisFinder extends IsisConnector {
+ /**
+ * Find the next repetition of a field.
+ *
+ * @param $entry
+ * Start entry number to begin the search.
+ *
+ * @param $field
+ * Field name.
+ *
+ * @return
+ * Next repetition.
+ */
+ public function nextRepetition($entry = 1, $field) {
+ $entry--;
+
+ // Query database.
+ do {
+ $result = $this->read(++$entry);
+ if ($entry == $entries) {
+ break;
+ }
+ } while (!isset($result[$field]) || count($result[$field]) < 2);
+
+ if (!isset($result[$field]) || count($result[$field]) < 2) {
+ return FALSE;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Find the next occurrence of a field.
+ *
+ * @param $entry
+ * Start entry number to begin the search.
+ *
+ * @param $field
+ * Field name.
+ *
+ * @return
+ * Next occurrence.
+ */
+ public function nextField($entry = 1, $field) {
+ $entry--;
+
+ // Query database.
+ do {
+ $result = $this->read(++$entry);
+ if ($entry == $entries) {
+ break;
+ }
+ } while (!isset($result[$field]));
+
+ if (!isset($result[$field])) {
+ return FALSE;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Find the next occurrence of a subfield.
+ *
+ * @param $entry
+ * Start entry number to begin the search.
+ *
+ * @param $field
+ * Field name.
+ *
+ * @param $subfield
+ * Subfield name.
+ *
+ * @return
+ * Next occurrence.
+ *
+ * @todo
+ * The subfield might be in any now and not just
+ * in the first one.
+ */
+ public function nextSubfield($entry = 1, $field, $subfield) {
+ $entry--;
+
+ // Query database.
+ do {
+ $result = $this->read(++$entry);
+ if ($entry == $entries) {
+ break;
+ }
+ } while (!isset($result[$field][0][$subfield]));
+
+ if (!isset($result[$field][0][$subfield])) {
+ return FALSE;
+ }
+
+ return $result;
+ }
+}
diff --git a/classes/BiblioIsisDb.php b/classes/backends/BiblioIsisDb.php
index 9db0145..bb7f9f5 100644
--- a/classes/BiblioIsisDb.php
+++ b/classes/backends/BiblioIsisDb.php
@@ -70,7 +70,7 @@ class BiblioIsisDb implements IsisDb {
function backend($method = 'count', $args = NULL) {
// Setup the database.
$name = $this->format['db']['name'];
- $db = CinisisDb::file("$name/$name", 'db');
+ $db = Cinisis::file("$name/$name", 'db');
// Setup arguments.
if ($args != NULL) {
@@ -258,7 +258,7 @@ class BiblioIsisDb implements IsisDb {
}
else {
foreach ($name as $value) {
- $data[] = array(CinisisDb::main_field_name($this->format, $key) => $value);
+ $data[] = array(Cinisis::main_field_name($this->format, $key) => $value);
}
}
@@ -337,14 +337,14 @@ class BiblioIsisDb implements IsisDb {
}
// Join subfields and main field if needed.
- if (CinisisDb::join_subfields($this->format)) {
+ if (Cinisis::join_subfields($this->format)) {
if (isset($data[$entry]['subfields'])) {
$data[$entry] = $data[$entry]['subfields'];
}
if (isset($field)) {
unset($data[$entry]['field']);
- $data[$entry][CinisisDb::main_field_name($this->format, $key)] = $field;
+ $data[$entry][Cinisis::main_field_name($this->format, $key)] = $field;
}
}
}
diff --git a/classes/IsisDb.php b/classes/backends/IsisDb.php
index 4a2218a..4a2218a 100644
--- a/classes/IsisDb.php
+++ b/classes/backends/IsisDb.php
diff --git a/classes/MaleteDb.php b/classes/backends/MaleteDb.php
index 114995b..114995b 100644
--- a/classes/MaleteDb.php
+++ b/classes/backends/MaleteDb.php
diff --git a/classes/PhpIsisDb.php b/classes/backends/PhpIsisDb.php
index 41319cc..e69898e 100644
--- a/classes/PhpIsisDb.php
+++ b/classes/backends/PhpIsisDb.php
@@ -43,7 +43,7 @@ class PhpIsisDb implements IsisDb {
// Open the database.
$name = $schema['db']['name'];
- $this->db = isis_open(CinisisDb::file("$name/$name", 'db'));
+ $this->db = isis_open(Cinisis::file("$name/$name", 'db'));
}
/**
diff --git a/classes/SchemaDb.php b/classes/backends/SchemaDb.php
index db9ca30..db9ca30 100644
--- a/classes/SchemaDb.php
+++ b/classes/backends/SchemaDb.php
diff --git a/classes/helpers/CinisisDisplayHelper.php b/classes/helpers/CinisisDisplayHelper.php
index 325595d..48db6ea 100644
--- a/classes/helpers/CinisisDisplayHelper.php
+++ b/classes/helpers/CinisisDisplayHelper.php
@@ -188,7 +188,7 @@ class CinisisDisplayHelper {
/**
* Draws a line break element.
*/
- static function h3($text) {
+ static function br($text) {
echo "<br />";
}
diff --git a/index.php b/index.php
index 7aebd45..aff50a5 100644
--- a/index.php
+++ b/index.php
@@ -11,7 +11,10 @@ require_once 'contrib/spyc/spyc.php';
// Autoloader.
function cinisis_autoload($class) {
- if (strstr($class, 'Iterator')) {
+ if (strstr($class, 'Db')) {
+ require_once 'classes/backends/'. $class .'.php';
+ }
+ elseif (strstr($class, 'Iterator')) {
require_once 'classes/iterators/'. $class .'.php';
}
elseif (strstr($class, 'Helper')) {
diff --git a/samples/read.php b/samples/read.php
index 5a5be04..f0d2ba6 100644
--- a/samples/read.php
+++ b/samples/read.php
@@ -23,7 +23,7 @@ $configs = array(
foreach ($configs as $config) {
// Get a db instance.
- $isis = new CinisisDb($config);
+ $isis = new Cinisis($config);
// Test connection.
if ($isis->db) {
diff --git a/samples/test.php b/samples/test.php
index 2b1fe5c..184df7c 100644
--- a/samples/test.php
+++ b/samples/test.php
@@ -10,7 +10,7 @@ require_once '../index.php';
$display = new CinisisDisplayHelper('Isis Test');
// Get a db instance.
-$isis = new CinisisDb();
+$isis = new Cinisis();
// Test connection.
if ($isis->db) {