From 2ec3b3c05e535ffacb1e10a64aa62ad057499d47 Mon Sep 17 00:00:00 2001 From: Silvio Date: Mon, 16 Aug 2010 15:37:31 -0300 Subject: Adding helper classes and repetition finder --- classes/helpers/CinisisDisplayHelper.php | 53 ++++++++++++++++++++++++++++++++ classes/helpers/CinisisHttpHelper.php | 15 +++++++++ index.php | 3 ++ tests/index.php | 48 ++++++----------------------- tests/read.php | 14 +++------ tests/repetition.php | 45 +++++++++++++++++++++++++++ tests/test.php | 14 +++------ 7 files changed, 135 insertions(+), 57 deletions(-) create mode 100644 classes/helpers/CinisisDisplayHelper.php create mode 100644 classes/helpers/CinisisHttpHelper.php create mode 100644 tests/repetition.php 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 @@ +header(); + $this->title($title); + } + + function title($title) { + echo "

$title

\n"; + } + + function header() { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + + function footer() { + echo ''; + } + + function form($content, $action = 'index.php', $method = 'get') { + echo '
'; + echo $content; + echo ''; + echo '
'; + echo '
'; + } + + function form_input_text($name) { + return ucfirst($name) .': '; + } + + function navbar($entry, $entries, $action = 'index.php') { + // First / prev links. + if ($entry != 1) { + $prev = $entry - 1; + echo 'first '; + echo '< prev '; + } + + // Next / last links. + if ($entry < $entries) { + $next = $entry + 1; + echo 'next > '; + echo 'last'; + } + } +} 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 @@ + - - - - - - - - -
-Entry: - -
-
-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 'first '; - echo '< prev '; - } - - // Next / last links. - if ($entry < $entries) { - $next = $entry + 1; - echo 'next > '; - echo 'last'; - } + $display->navbar($entry, $entries); // Format output. echo "
\n";
@@ -68,5 +38,5 @@ if ($isis->db) {
   echo '
'; } +$display->footer(); ?> - 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 @@ */ ?> - - - - - - + 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 @@ +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 "
\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 '
'; +} + +$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 @@ */ ?> - - - - - - - + +