From d77a34b3aa1eaa313d1055580bddd1cb38556fef Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 17 Aug 2010 15:24:03 -0300 Subject: Adding a subfield finder --- classes/helpers/CinisisHttpHelper.php | 37 ++++++++++++++++++++--- tests/subfield.php | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 tests/subfield.php diff --git a/classes/helpers/CinisisHttpHelper.php b/classes/helpers/CinisisHttpHelper.php index eae8a8d..5ff8984 100644 --- a/classes/helpers/CinisisHttpHelper.php +++ b/classes/helpers/CinisisHttpHelper.php @@ -5,23 +5,52 @@ */ class CinisisHttpHelper { /** - * Get a numeric argument. + * Get an argument. * * @param $name * Argument name. * + * @param $mixed + * Default value. + * * @return * Argument value. */ - static function get_numeric_arg($name) { + static function get_arg($name, $default = 1) { // Get the query parameter. if (isset($_GET[$name]) && ! empty($_GET[$name])) { - $arg = (int) $_GET[$name]; + $arg = $_GET[$name]; } else { - $arg = 1; + $arg = $default; } return $arg; } + + /** + * Get a numeric argument. + * + * @param $name + * Argument name. + * + * @return + * Argument value. + */ + static function get_numeric_arg($name) { + return (int) self::get_arg($name, 1); + } + + /** + * Get a string argument. + * + * @param $name + * Argument name. + * + * @return + * Argument value. + */ + static function get_textual_arg($name) { + return (string) self::get_arg($name, 'a'); + } } diff --git a/tests/subfield.php b/tests/subfield.php new file mode 100644 index 0000000..892f2b5 --- /dev/null +++ b/tests/subfield.php @@ -0,0 +1,55 @@ +form_input_text('entry', $entry); +$form .= $display->form_input_text('field', $field); +$form .= $display->form_input_text('subfield', $subfield); +$display->form($form, 'subfield.php'); + +// Get a db instance. +$isis = new CinisisDb(); + +// 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--; + + // Query database. + do { + $result = $isis->db->read(++$entry); + if ($entry == $entries) { + break; + } + } while (!isset($result[$field_name][0][$subfield_name])); + + // Navigation bar. + $display->navbar($entry, $entries, $repetition, '&field='. $field . '&subfield='. $subfield); + + // Format output. + echo "
\n";
+  echo "Selected field: $field: $field_name.\n";
+  echo "Selected subfield: $subfield: $subfield_name.\n";
+  echo "Showing entry $entry from $entries total entries.\n";
+  echo "Repetitions found: ". count($result[$field]) .".\n";
+  echo "\n";
+  print_r($result[$field_name]);
+  echo '
'; +} + +$display->footer(); +?> -- cgit v1.2.3