aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/IsisConnector.php66
-rw-r--r--classes/iterators/IsisItemIterator.php85
-rw-r--r--classes/iterators/IsisMainItemIterator.php (renamed from classes/iterators/IsisMainFieldIterator.php)4
-rw-r--r--classes/iterators/IsisNormalItemFilterIterator.php18
-rw-r--r--classes/iterators/IsisNormalSubfieldFilterIterator.php18
-rw-r--r--classes/iterators/IsisSubfieldIterator.php (renamed from classes/iterators/IsisFieldIterator.php)7
6 files changed, 166 insertions, 32 deletions
diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php
index da19fde..c82d479 100644
--- a/classes/IsisConnector.php
+++ b/classes/IsisConnector.php
@@ -47,7 +47,7 @@ class IsisConnector {
* @return
* Main field name.
*/
- public function getMainFieldName($field) {
+ public function getMainItemName($field) {
$key = $this->getFieldKey($field);
return $this->isis->db->main_field_name($key);
}
@@ -108,8 +108,8 @@ class IsisConnector {
* @return
* Field data.
*/
- public function getMainField($field, $row = 0) {
- $name = $this->getMainFieldName($field);
+ public function getMainItem($field, $row = 0) {
+ $name = $this->getMainItemName($field);
if (isset($this->result[$field['name']][$row][$name])) {
return $this->result[$field['name']][$row][$name];
@@ -125,9 +125,9 @@ class IsisConnector {
* @return
* Field data.
*/
- public function getMainFields($field) {
+ public function getMainItems($field) {
foreach (new IsisRowIterator($this, $field) as $row) {
- $values[$row] = $this->getMainField($field, $row);
+ $values[$row] = $this->getMainItem($field, $row);
}
return $values;
@@ -182,6 +182,58 @@ class IsisConnector {
}
/**
+ * Get both main field or subfields from a given field and row.
+ *
+ * @param $field
+ * field array.
+ *
+ * @param $item
+ * item name (field or subfield).
+ *
+ * @param $row
+ * row number.
+ *
+ * @return
+ * Item data.
+ */
+ public function getItem($field, $item, $row) {
+ $main_field = $this->getMainItemName($field);
+
+ if ($field == $main_field) {
+ return $this->getMainItem($field, $row);
+ }
+ else {
+ return $this->getSubfield($field, $item, $row);
+ }
+ }
+
+ /**
+ * Get all rows both main field or subfields from a given field.
+ *
+ * @param $field
+ * field array.
+ *
+ * @param $item
+ * item name (field or subfield).
+ *
+ * @param $row
+ * row number.
+ *
+ * @return
+ * Item data.
+ *
+ * @todo
+ * Rename to getItem?
+ */
+ public function getItems($field, $item) {
+ foreach (new IsisRowIterator($this, $field) as $row) {
+ $values[$row] = $this->getItem($field, $item, $row);
+ }
+
+ return $values;
+ }
+
+ /**
* Get the list of subfields from a given field.
*
* @param $field
@@ -582,7 +634,7 @@ class IsisConnector {
}
/**
- * Deal with special subfields.
+ * Deal with special items.
*
* @param $field
* Field data from ISIS database schema.
@@ -596,7 +648,7 @@ class IsisConnector {
* @return
* True if special subfield, false otherwise of special return type
*/
- public function specialSubfield($field, $subfield, $return = 'boolean') {
+ public function specialItem($field, $subfield, $return = 'boolean') {
if (isset($field['special'])) {
$field_key = $this->getFieldKey($field);
$subfield_key = $this->getSubfieldKey($field, $subfield);
diff --git a/classes/iterators/IsisItemIterator.php b/classes/iterators/IsisItemIterator.php
new file mode 100644
index 0000000..5c28b2c
--- /dev/null
+++ b/classes/iterators/IsisItemIterator.php
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * Isis field iterator. Iterates over a field for each result row.
+ */
+class IsisItemIterator implements Iterator
+{
+ private $keys;
+ private $fieldset;
+ private $row = 0;
+ private $rows = 0;
+ private $item = 0;
+ private $items = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param $class
+ * Instance of IsisConnector or child class.
+ *
+ * @param $field
+ * Field to iterate over.
+ *
+ * @param $main
+ * Control to which item the main field should be mapped to.
+ * By default no mapping is made.
+ */
+ public function __construct($class, $field, $main = false) {
+ $this->class = $class;
+ $this->field = $field;
+ $this->rows = $class->getRows($field);
+
+ // Handle subfields
+ $this->fieldset = $class->getSubfieldList($field);
+ $this->keys = array_keys($this->fieldset);
+ $this->items = count($this->keys);
+
+ // Sum up main item
+ $this->fieldset[] = $class->getMainItem($field);
+ $this->keys[] = $class->getMainItemName($field);
+ $this->items++;
+ }
+
+ /**
+ * Rewind the Iterator to the first element.
+ */
+ function rewind() {
+ $this->row = 0;
+ $this->item = 0;
+ }
+
+ /**
+ * Return the key of the current element.
+ */
+ function key() {
+ return $this->row;
+ }
+
+ /**
+ * Return the current element.
+ */
+ function current() {
+ return $this->fieldset[$this->keys[$this->item]];
+ }
+
+ /**
+ * Move forward to next element.
+ */
+ function next() {
+ if ($this->item >= $this->items) {
+ $this->item = 0;
+ ++$this->row;
+ }
+ else {
+ ++$this->item;
+ }
+ }
+
+ /**
+ * Check if there is a current element after calls to rewind() or next().
+ */
+ function valid() {
+ return $this->row <= $this->rows;
+ }
+}
diff --git a/classes/iterators/IsisMainFieldIterator.php b/classes/iterators/IsisMainItemIterator.php
index 5ec1cbc..02ab8d1 100644
--- a/classes/iterators/IsisMainFieldIterator.php
+++ b/classes/iterators/IsisMainItemIterator.php
@@ -7,7 +7,7 @@
* @todo
* Support for 'join_subfields'
*/
-class IsisMainFieldIterator implements Iterator
+class IsisMainItemIterator implements Iterator
{
private $class;
private $field;
@@ -50,7 +50,7 @@ class IsisMainFieldIterator implements Iterator
* Return the current element.
*/
function current() {
- $field = $this->class->getMainFieldName($this->field);
+ $field = $this->class->getMainItemName($this->field);
return $this->valueset[$this->row][$field];
}
diff --git a/classes/iterators/IsisNormalItemFilterIterator.php b/classes/iterators/IsisNormalItemFilterIterator.php
new file mode 100644
index 0000000..e59d7c6
--- /dev/null
+++ b/classes/iterators/IsisNormalItemFilterIterator.php
@@ -0,0 +1,18 @@
+<?php
+
+/**
+ * Isis normal subfield iterator. Filter out special subfields.
+ */
+class IsisNormalItemFilterIterator extends FilterIterator {
+
+ /**
+ * Filter out special subfields.
+ */
+ public function accept()
+ {
+ $field = $this->getInnerIterator()->field;
+ $class = $this->getInnerIterator()->class;
+ $item = $this->getInnerIterator()->current();
+ return !$class->specialItem($field, $item);
+ }
+}
diff --git a/classes/iterators/IsisNormalSubfieldFilterIterator.php b/classes/iterators/IsisNormalSubfieldFilterIterator.php
deleted file mode 100644
index 5a3f4ce..0000000
--- a/classes/iterators/IsisNormalSubfieldFilterIterator.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-/**
- * Isis normal subfield iterator. Filter out special subfields.
- */
-class IsisNormalSubfieldFilterIterator extends FilterIterator {
-
- /**
- * Filter out special subfields.
- */
- public function accept()
- {
- $field = $this->getInnerIterator()->field;
- $class = $this->getInnerIterator()->class;
- $subfield = $this->getInnerIterator()->current();
- return !$class->specialSubfield($field, $subfield);
- }
-}
diff --git a/classes/iterators/IsisFieldIterator.php b/classes/iterators/IsisSubfieldIterator.php
index 26c5e88..2e213cf 100644
--- a/classes/iterators/IsisFieldIterator.php
+++ b/classes/iterators/IsisSubfieldIterator.php
@@ -1,12 +1,9 @@
<?php
/**
- * Isis field iterator. Iterates over a field for each result row.
- *
- * @todo
- * Support for 'join_subfields'
+ * Isis subfield iterator. Iterates over subfields for each result row.
*/
-class IsisFieldIterator implements Iterator
+class IsisSubfieldIterator implements Iterator
{
private $keys;
private $fieldset;