diff options
author | Silvio <silvio@devlet.com.br> | 2010-08-18 15:22:43 -0300 |
---|---|---|
committer | Silvio <silvio@devlet.com.br> | 2010-08-18 15:22:43 -0300 |
commit | ad8d8568b683e6935bec64abe88f79bf31706dd7 (patch) | |
tree | 43d00493cf8676acbcf4bec74bf44c717107ecd6 /classes | |
parent | 219aa7f6b4a19b723b0c25683801b1b5d502e9f4 (diff) | |
download | cinisis-ad8d8568b683e6935bec64abe88f79bf31706dd7.tar.gz cinisis-ad8d8568b683e6935bec64abe88f79bf31706dd7.tar.bz2 |
Adding audit and finder classes, cleanup and organization
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Cinisis.php (renamed from classes/CinisisDb.php) | 4 | ||||
-rw-r--r-- | classes/IsisAudit.php | 38 | ||||
-rw-r--r-- | classes/IsisConnector.php | 6 | ||||
-rw-r--r-- | classes/IsisFinder.php | 103 | ||||
-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.php | 2 |
10 files changed, 152 insertions, 11 deletions
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 />"; } |