aboutsummaryrefslogtreecommitdiff
path: root/classes/IsisConnector.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/IsisConnector.php')
-rw-r--r--classes/IsisConnector.php448
1 files changed, 1 insertions, 447 deletions
diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php
index 09bb8ea..ff5a576 100644
--- a/classes/IsisConnector.php
+++ b/classes/IsisConnector.php
@@ -4,78 +4,7 @@
* IsisConnector: provides an easy interface to connect an
* application with Cinisis.
*/
-class IsisConnector {
- /**
- * Constructor.
- */
- public function __construct($config = null) {
- return $this->open($config);
- }
-
- /**
- * Open a database.
- *
- * @param $config
- * Config file or array.
- */
- public function open($config) {
- $this->isis = new Cinisis($config);
-
- if ($this->isis->db) {
- $this->entries = $this->isis->db->entries();
- $this->format = $this->isis->db->format;
- $this->fields = $this->format['fields'];
- }
- else {
- return FALSE;
- }
- }
-
- /**
- * Alias to $isis->db->read().
- *
- * @param $entry
- * Row number.
- *
- * @return
- * Resulting data.
- */
- public function read($entry) {
- // Always store the last result.
- $this->result = $this->isis->db->read($entry);
-
- // Return the result.
- return $this->result;
- }
-
- /**
- * Get the main field name.
- *
- * @param $field
- * Field data from ISIS database schema.
- *
- * @return
- * Main field name.
- */
- public function getMainItemName($field) {
- $key = $this->getFieldKey($field);
- return Cinisis::main_field_name($this->format, $key);
- }
-
- /**
- * Whether to join field and subfields in a single array.
- *
- * @return
- * Boolean.
- */
- public function joinSubfields() {
- if (Cinisis::join_subfields($this->format)) {
- return TRUE;
- }
-
- return FALSE;
- }
-
+class IsisConnector extends IsisMap {
/**
* Get all values of a given field.
*
@@ -251,322 +180,6 @@ class IsisConnector {
}
/**
- * Get the list of subfields from a given field.
- *
- * @param $field
- * Field array.
- */
- public function getSubfieldList($field) {
- if (isset($field['subfields'])) {
- return $field['subfields'];
- }
-
- return array();
- }
-
- /**
- * Determine which model field an ISIS db field should be mapped to.
- * When importing an ISIS database to another system, a mapping
- * provided in the database schema can be used to put the originating
- * entries (fields and subfields) in the right place at the destination
- * database.
- *
- * Map format:
- *
- * map:
- * type: relation
- *
- * map:
- * type: value
- * field: dest
- * subfields:
- * a: dest
- * b: dest
- *
- * Examples:
- *
- * map:
- * type: Performer
- *
- * map:
- * type: value
- * field: title
- * subfields:
- * a: subtitle
- *
- * @param $field
- * Field array.
- *
- * @param $subfield
- * Subfield name.
- *
- * @return
- * A map destination to the field or subfield.
- */
- public function getMap($field, $subfield = NULL) {
- if ($subfield == NULL) {
- if (isset($field['map']['main'])) {
- // Custom map provided for the main item.
- $dest = $this->mapName($field['map']['main']);
- }
- else {
- // Default map.
- $dest = $this->mapName($field['name']);
- }
- }
- else {
- $key = $this->getSubfieldKey($field, $subfield);
-
- if (isset($field['map']['subfields'][$key])) {
- // Custom map provided.
- $dest = $this->mapName($field['map']['subfields'][$key]);
- }
- else {
- // Default map.
- $dest = $this->mapName($subfield);
- }
- }
-
- return $dest;
- }
-
- /**
- * Get the mapping type of a given field.
- *
- * @param $field
- * Field array.
- *
- * @return
- * The mapping type.
- */
- public function getMapType($field) {
- return isset($field['map']['type']) ? $field['map']['type'] : FALSE;
- }
-
- /**
- * Guess a method name from a type.
- *
- * @param $type
- * Mapping type.
- *
- * @return
- * Method name.
- */
- static function methodName($type) {
- return 'import'. ucfirst($type);
- }
-
- /**
- * Check on an ISIS schema whether a field has a map.
- *
- * @param $field
- * Field array.
- *
- * @return
- * TRUE if field has a map, FALSE otherwise.
- */
- public function fieldHasMap($field) {
- if (isset($field['map']['main'])) {
- return TRUE;
- }
- return FALSE;
- }
-
- /**
- * Check on an ISIS schema whether a subfield has a map.
- *
- * @param $field
- * Field array.
- *
- * @param $subfield
- * Subfield name.
- *
- * @return
- * TRUE if subfield has a map, FALSE otherwise.
- */
- public function subfieldHasMap($field, $subfield) {
- if (isset($field['map']['subfields'])) {
- $key = $this->getSubfieldKey($field, $subfield);
- if (isset($field['map']['subfields'][$key])) {
- return TRUE;
- }
- }
- return FALSE;
- }
-
- /**
- * Get the key of a subfield entry.
- *
- * @param $field
- * Field array.
- *
- * @param $subfield
- * Subfield name.
- *
- * @return
- * Subfield key.
- */
- public function getSubfieldKey($field, $subfield) {
- $keys = array_flip($field['subfields']);
- if (isset($keys[$subfield])) {
- return $keys[$subfield];
- }
- }
-
- /**
- * Get the item key.
- *
- * @param $field
- * Field array.
- *
- * @param $item
- * Item name.
- *
- * @return
- * Item key.
- */
- public function getItemKey($field, $item) {
- if ($item == 'main') {
- return $item;
- }
- else {
- return $this->getSubfieldKey($field, $item);
- }
- }
-
- /**
- * Get the key of a field entry.
- *
- * @param $field
- * Field array.
- *
- * @return
- * Field key.
- */
- public function getFieldKey($field) {
- return array_search($field, $this->format['fields']);
- }
-
- /**
- * Get the array which defines a field.
- *
- * @param $field_key
- * Field key.
- *
- * @return
- * Field array.
- */
- public function getFieldArray($field_key) {
- if (isset($this->format['fields'][$field_key])) {
- return $this->format['fields'][$field_key];
- }
-
- return NULL;
- }
-
- /**
- * Remove brackets from strings whithin an array.
- *
- * @param $value
- * Array with bracketed strings.
- */
- public function removeBrackets($value) {
- $value = str_replace('<', '', $value);
- $value = str_replace('>', '', $value);
- return $value;
- }
-
- /**
- * Remove brackets from strings whithin an array.
- *
- * @param &$values
- * Array with bracketed strings.
- */
- public function removeBracketsFromArray(&$values) {
- foreach ($values as $key => $value) {
- $values[$key] = $this->removeBrackets($value);
- }
- }
-
- /**
- * Explode a bracketed string into values. Just strings
- * inside brackets are returned.
- *
- * @param $subject
- * Strings containing brackets.
- *
- * @return
- * Array of matched strings.
- */
- public function explodeBrackets($subject) {
- preg_match_all('/<[^<>]*>/', $subject, $values);
- return $this->filterBrackets($values[0]);
- }
-
- /**
- * Filter out brackets from strings.
- *
- * @param $values
- * String (or array filled with strings) to be filtered.
- *
- * @result
- * Filtered string or array.
- */
- public function filterBrackets($values) {
- if (is_array($values)) {
- foreach ($values as $key => $value) {
- $values[$key] = $this->filterBrackets($value);
- }
- }
- else {
- $values = preg_replace(array('/</', '/>/'), '', $values);
- }
-
- return $values;
- }
-
- /**
- * Check if a string has brackets.
- *
- * @param $value
- * String to be compared.
- *
- * @return
- * True if string has brackets, false otherwise.
- */
- public function hasBrackets($value) {
- if (strstr($value, '<') && strstr($value, '>')) {
- return TRUE;
- }
-
- return FALSE;
- }
-
- /**
- * Explode values from fields or subfields. Split values
- * inside brackets if needed, but then doesn't return any
- * value outside brackets.
- *
- * @param $value
- * String with values.
- *
- * @return
- * Array with values.
- */
- public function explodeValue($value) {
- if ($this->hasBrackets($value)) {
- return $this->explodeBrackets($value);
- }
- else {
- if (!is_array($value)) {
- $value = array($value);
- }
- }
-
- return $value;
- }
-
- /**
* Explode brackets for a given subfield, avoiding null entries.
*
* @param $field
@@ -624,32 +237,6 @@ class IsisConnector {
}
/**
- * Normalize field names.
- *
- * @param $name
- * Field name
- *
- * @return
- * Normalized field name
- */
- static function normalizeFieldName($name) {
- return ucfirst(preg_replace('/[^a-z0-9_]/', '', strtolower($name)));
- }
-
- /**
- * Build a map name.
- *
- * @param $name
- * Field name
- *
- * @return
- * Map name
- */
- static function mapName($name) {
- return 'set'. self::normalizeFieldName($name);
- }
-
- /**
* Check if a field result and row has a given subfield.
*
* @param $field
@@ -753,39 +340,6 @@ class IsisConnector {
}
/**
- * Get a subfield name.
- *
- * @param $field_key
- * Field key.
- *
- * @param $subfield_key
- * Subfield key.
- *
- * @return
- * Subfield name.
- */
- public function getSubfieldName($field_key, $subfield_key) {
- if (isset($this->format['fields'][$field_key]['subfields'][$subfield_key])) {
- return $this->format['fields'][$field_key]['subfields'][$subfield_key];
- }
-
- return FALSE;
- }
-
- /**
- * Get a field name.
- *
- * @param $field_key
- * Field key.
- *
- * @return
- * Field name.
- */
- public function getFieldName($field_key) {
- return $this->format['fields'][$field_key]['name'];
- }
-
- /**
* Check if a field and subfield match a given condition.
*
* @param $field