aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/helpers/CinisisDisplayHelper.php53
-rw-r--r--classes/helpers/CinisisHttpHelper.php15
-rw-r--r--index.php3
-rw-r--r--tests/index.php48
-rw-r--r--tests/read.php14
-rw-r--r--tests/repetition.php45
-rw-r--r--tests/test.php14
7 files changed, 135 insertions, 57 deletions
diff --git a/classes/helpers/CinisisDisplayHelper.php b/classes/helpers/CinisisDisplayHelper.php
new file mode 100644
index 0000000..16d458e
--- /dev/null
+++ b/classes/helpers/CinisisDisplayHelper.php
@@ -0,0 +1,53 @@
+<?php
+
+class CinisisDisplayHelper {
+ function __construct($title) {
+ $this->header();
+ $this->title($title);
+ }
+
+ function title($title) {
+ echo "<h1>$title</h1>\n";
+ }
+
+ function header() {
+ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
+ echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">';
+ echo '<head>';
+ echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
+ echo '</head>';
+ echo '<body>';
+ }
+
+ function footer() {
+ echo '</body>';
+ }
+
+ function form($content, $action = 'index.php', $method = 'get') {
+ echo '<form action="'. $action .'" method="'. $method .'">';
+ echo $content;
+ echo '<input type="submit" />';
+ echo '</form>';
+ echo '<br />';
+ }
+
+ function form_input_text($name) {
+ return ucfirst($name) .': <input name="'. $name .'" type="text" />';
+ }
+
+ function navbar($entry, $entries, $action = 'index.php') {
+ // First / prev links.
+ if ($entry != 1) {
+ $prev = $entry - 1;
+ echo '<a href="'. $action .'?entry=1">first</a> ';
+ echo '<a href="'. $action .'?entry='. $prev .'">&lt; prev</a> ';
+ }
+
+ // Next / last links.
+ if ($entry < $entries) {
+ $next = $entry + 1;
+ echo '<a href="'. $action .'?entry='. $next .'">next &gt;</a> ';
+ echo '<a href="'. $action .'?entry='. $entries .'">last</a>';
+ }
+ }
+}
diff --git a/classes/helpers/CinisisHttpHelper.php b/classes/helpers/CinisisHttpHelper.php
new file mode 100644
index 0000000..34ff349
--- /dev/null
+++ b/classes/helpers/CinisisHttpHelper.php
@@ -0,0 +1,15 @@
+<?php
+
+class CinisisHttpHelper {
+ static function get_numeric_arg($name) {
+ // Get the query parameter.
+ if (isset($_GET[$name]) && ! empty($_GET[$name])) {
+ $arg = (int) $_GET[$name];
+ }
+ else {
+ $arg = 1;
+ }
+
+ return $arg;
+ }
+}
diff --git a/index.php b/index.php
index 3a946af..7aebd45 100644
--- a/index.php
+++ b/index.php
@@ -14,6 +14,9 @@ function cinisis_autoload($class) {
if (strstr($class, 'Iterator')) {
require_once 'classes/iterators/'. $class .'.php';
}
+ elseif (strstr($class, 'Helper')) {
+ require_once 'classes/helpers/'. $class .'.php';
+ }
else {
require_once 'classes/'. $class .'.php';
}
diff --git a/tests/index.php b/tests/index.php
index ae12134..50c36f6 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -2,33 +2,16 @@
/**
* Cinisis - Isis db reading tool.
*/
-?>
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
-
-<form action="index.php" method="get">
-Entry: <input name="entry" type="text" />
-<input type="submit" />
-</form>
-<br />
-<?php
-
-// Import Cinisis Library.
+// Import requisites.
require_once '../index.php';
-// Get the query parameter.
-if (isset($_GET["entry"]) && ! empty($_GET["entry"])) {
- $entry = (int) $_GET["entry"];
-}
-else {
- $entry = 1;
-}
+// Draw the document.
+$display = new CinisisDisplayHelper('Isis Navigator');
+$display->form($display->form_input_text('entry'));
+
+// Get entry number.
+$entry = CinisisHttpHelper::get_numeric_arg('entry');
// Get a db instance.
$isis = new CinisisDb();
@@ -45,20 +28,7 @@ if ($isis->db) {
// Query database.
$result = $isis->db->read($entry);
-
- // First / prev links.
- if ($entry != 1) {
- $prev = $entry - 1;
- echo '<a href="index.php?entry=1">first</a> ';
- echo '<a href="index.php?entry='. $prev .'">&lt; prev</a> ';
- }
-
- // Next / last links.
- if ($entry < $entries) {
- $next = $entry + 1;
- echo '<a href="index.php?entry='. $next .'">next &gt;</a> ';
- echo '<a href="index.php?entry='. $entries .'">last</a>';
- }
+ $display->navbar($entry, $entries);
// Format output.
echo "<pre>\n";
@@ -68,5 +38,5 @@ if ($isis->db) {
echo '</pre>';
}
+$display->footer();
?>
-</body>
diff --git a/tests/read.php b/tests/read.php
index 1235c25..5281335 100644
--- a/tests/read.php
+++ b/tests/read.php
@@ -4,20 +4,16 @@
*/
?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
+<?php
+// Import requisites.
+require_once '../index.php';
+require_once 'includes/header.inc.php';
+?>
<table><tr>
<?php
-// Import Cinisis Library.
-require_once '../index.php';
-
$configs = array(
0 => array(
'implementation' => 'PhpIsis',
diff --git a/tests/repetition.php b/tests/repetition.php
new file mode 100644
index 0000000..7555016
--- /dev/null
+++ b/tests/repetition.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Cinisis - Isis db reading tool.
+ */
+
+// Import requisites.
+require_once '../index.php';
+
+// Draw the document.
+$display = new CinisisDisplayHelper('Repetition finder');
+$display->form($display->form_input_text('code'), 'repetition.php');
+
+// Get field code.
+$code = CinisisHttpHelper::get_numeric_arg('code');
+
+// Get a db instance.
+$isis = new CinisisDb();
+
+// Setup database and entry number.
+if ($isis->db) {
+ // Get the number of entries.
+ $field = $isis->db->format['fields'][$code]['name'];
+ $entries = $isis->db->entries();
+ $entry = 1;
+
+ // Query database.
+ do {
+ $result = $isis->db->read($entry++);
+ if ($entry == $entries) {
+ break;
+ }
+ } while (!isset($result[$field]) || count($result[$field]) < 2);
+
+ // Format output.
+ echo "<pre>\n";
+ echo "Showing entry $entry from $entries total entries.\n";
+ echo "Selected field: $field.\n";
+ echo "Repetitions found: ". count($result[$field]) ."\n";
+ echo "\n";
+ print_r($result);
+ echo '</pre>';
+}
+
+$display->footer();
+?>
diff --git a/tests/test.php b/tests/test.php
index ebd465f..fd2ac99 100644
--- a/tests/test.php
+++ b/tests/test.php
@@ -4,17 +4,13 @@
*/
?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
-
<?php
-
-// Import Cinisis Library.
+// Import requisites.
require_once '../index.php';
+require_once 'includes/header.inc.php';
+?>
+
+<?php
// Get a db instance.
$isis = new CinisisDb();