Author: mcantelon
Date: Mon Jan 16 18:58:24 2012
New Revision: 10690

Log:
Documented CLI import logic for creating Qubit objects and did minor 
refactoring.

Modified:
   trunk/lib/QubitFlatfileImport.class.php

Modified: trunk/lib/QubitFlatfileImport.class.php
==============================================================================
--- trunk/lib/QubitFlatfileImport.class.php     Mon Jan 16 18:27:21 2012        
(r10689)
+++ trunk/lib/QubitFlatfileImport.class.php     Mon Jan 16 18:58:24 2012        
(r10690)
@@ -38,7 +38,7 @@
     $this->variableColumns = array();
     $this->arrayColumns    = array();
 
-    $allowedOptions = array(
+    $allowedProperties = array(
       'errorLog',
       'className',
       'rowInitLogic',
@@ -58,7 +58,7 @@
       'arrayColumns'
     );
 
-    $this->setPropertiesFromArray($this, $options, $allowedOptions);
+    $this->setPropertiesFromArray($this, $options, $allowedProperties);
 
     // initialize bookkeeping of rows processed
     $this->status = ($options['status']) ? $options['status'] : $this->status;
@@ -68,14 +68,26 @@
     $this->rowStatusVars = array();
   }
 
-  protected function setPropertiesFromArray(&$object, $propertyArray, 
$allowedOptions, $ignore = array())
+  /**
+   * Use an array of properties and their respective values to set an object's
+   * properties (restricting to a set of allowed properties and allowing the
+   * specification of properties that should be ignored and not set)
+   *
+   * @param object &$object  object to act upon
+   * @param array $propertyArray  array of properties and their respective 
values
+   * @param array $allowedProperties  array of properties that can be set
+   * @param array $ignore  array of properties that should be ignored
+   *
+   * @return void
+   */
+  protected function setPropertiesFromArray(&$object, $propertyArray, 
$allowedProperties, $ignore = array())
   {
     // set properties from options, halting upon invalid option
     foreach($propertyArray as $option => $value)
     {
       if (!in_array($option, $ignore))
       {
-        if (in_array($option, $allowedOptions))
+        if (in_array($option, $allowedProperties))
         {
           $object->$option = $value;
         }
@@ -476,6 +488,15 @@
     }
   }
 
+  /**
+   * Create a Qubit note
+   *
+   * @param integer $typeId  term ID of note type
+   * @param string $text  Note text
+   * @param closure $transformationLogic  logic to manipulate note text
+   *
+   * @return QubitNote  created note
+   */
   public function createNote($typeId, $text, $transformationLogic = false)
   {
     $note = new QubitNote;
@@ -492,16 +513,24 @@
     return $note;
   }
 
+  /**
+   * Create a Qubit event
+   *
+   * @param integer $typeId  term ID of event type
+   * @param array $options  option parameter
+   *
+   * @return QubitEvent  created event
+   */
   public function createEvent($typeId, $options = array())
   {
     $event = new QubitEvent;
     $event->informationObjectId = $this->object->id;
     $event->typeId = $typeId;
 
-    $allowedOptions = array('date', 'description', 'startDate', 'endDate');
+    $allowedProperties = array('date', 'description', 'startDate', 'endDate');
     $ignoreOptions  = array('actorName', 'actorHistory');
 
-    $this->setPropertiesFromArray($event, $options, $allowedOptions, 
$ignoreOptions);
+    $this->setPropertiesFromArray($event, $options, $allowedProperties, 
$ignoreOptions);
 
     if (isset($options['actorName']))
     {
@@ -514,8 +543,18 @@
     {
       $event->save();
     }
+
+    return $event;
   }
 
+  /**
+   * Issue an SQL query
+   *
+   * @param string $query  SQL query
+   * @param string $params  values to map to placeholders (optional)
+   *
+   * @return object  database statement object
+   */
   public function sqlQuery($query, $params = array())
   {
     $connection = Propel::getConnection();
@@ -528,6 +567,14 @@
     return $statement;
   }
 
+  /**
+   * Create a Qubit actor or, if one already exists, fetch it
+   *
+   * @param string $name  name of actor
+   * @param string $history  history of actor (optional)
+   *
+   * @return QubitActor  created term or fetched object containing actor data
+   */
   public function createOrFetchActor($name, $history = false)
   {
     $query = "SELECT * FROM actor_i18n WHERE authorized_form_of_name=?";
@@ -541,6 +588,15 @@
     }
   }
 
+  /**
+   * Create a Qubit term or, if it already exists, fetch it
+   *
+   * @param integer $taxonomyId  term taxonomy
+   * @param string $name  name of term
+   * @param string $culture  culture code (defaulting to English)
+   *
+   * @return object  created term or fetched object containing term data
+   */
   public function createOrFetchTerm($taxonomyId, $name, $culture = 'en')
   {
     $query = "SELECT * FROM term t LEFT JOIN term_i18n ti ON t.id=ti.id \r
@@ -558,16 +614,34 @@
     }
   }
 
+  /**
+   * Create a Qubit term
+   *
+   * @param integer $taxonomyId  term taxonomy
+   * @param string $name  name of term
+   * @param string $culture  culture code (defaulting to English)
+   *
+   * @return QubitTerm  created term
+   */
   public function createTerm($taxonomyId, $name, $culture = 'en')
   {
     $term = new QubitTerm;
     $term->name = $name;
     $term->taxonomyId = $taxonomyId;
+    $term->culture = $culture;
     $term->save();
 
     return $term;
   }
 
+  /**
+   * Create a Qubit actor
+   *
+   * @param string $name  name of actor
+   * @param string $history  history of actor (optional)
+   *
+   * @return QubitActor  created actor
+   */
   public function createActor($name, $history = false)
   {
     $actor = new QubitActor;
@@ -581,6 +655,14 @@
     return $actor;
   }
 
+  /**
+   * Create a relation between a term and a Qubit object
+   *
+   * @param integer $objectId  object ID
+   * @param integer $termId  term ID
+   *
+   * @return QubitObjectTermRelation  created relation
+   */
   public function createObjectTermRelation($objectId, $termId)
   {
     $relation = new QubitObjectTermRelation;
@@ -591,6 +673,15 @@
     return $relation;
   }
 
+  /**
+   * Create a term and relate it to an object
+   *
+   * @param integer $taxonomyId  taxonomy ID
+   * @param string $name  name of term
+   * @param string $culture  culture code (defaulting to English)
+   *
+   * @return void
+   */
   public function createAccessPoint($taxonomyId, $name, $culture = 'en')
   {
 
@@ -601,16 +692,20 @@
 
     if (!($term = $statement->fetch(PDO::FETCH_OBJ)))
     {
-      $term = new QubitTerm();
-      $term->taxonomyId = $taxonomyId;
-      $term->name = $name;
-      $term->culture = $culture;
-      $term->save();
+      $term = $this->createTerm($taxonomyId, $name, $culture);
     }
 
     $this->createObjectTermRelation($this->object->id, $term->id);
   }
 
+  /**
+   * Get the terms in a taxonomy, optionally specifying culture
+   *
+   * @param integer $taxonomyId  taxonomy ID
+   * @param string $culture  culture code (defaulting to English)
+   *
+   * @return array  array of term IDs and their respective names
+   */
   public function getTaxonomyTerms($taxonomyId, $culture = 'en')
   {
     $terms = array();
@@ -628,6 +723,14 @@
     return $terms;
   }
 
+  /**
+   * Load terms from one or more taxonomies and use the terms to populate one
+   * or more array elements.
+   *
+   * @param array $taxonomies  array of taxonomy IDs and identifying names
+   *
+   * @return array  array of arrays containing taxonomy terms
+   */
   public function loadTermsFromTaxonomies($taxonomies)
   {
     $taxonomyTerms = array();
@@ -644,20 +747,29 @@
     return $taxonomyTerms;
   }
 
+  /**
+   * Create a Qubit right and relate it to an information object. Valid
+   * options include the ID of the rights holder (rightholderId), the ID of
+   * the basis term (basisID), the ID of the act term (actID), and the ID of
+   * the copyright status term (copyrightStatusId).
+   *
+   * @param array $options  options
+   *
+   * @return QubitRelation  result object
+   */
   public function createRightAndRelation($options)
   {
     // add right
     $right = new QubitRights;
 
-    $allowedOptions = array(
+    $allowedProperties = array(
       'rightsHolderId',
-      'restriction',
       'basisId',
       'actId',
       'copyrightStatusId'
     );
 
-    $this->setPropertiesFromArray($right, $options, $allowedOptions);
+    $this->setPropertiesFromArray($right, $options, $allowedProperties);
 
     $right->save();
 
@@ -671,14 +783,27 @@
     return $relation;
   }
 
+  /**
+   * Fetch keymap an entity's Qubit object ID (target ID) by looking up its
+   * legacy ID (source ID), the name of the import where it was mapped (source
+   * name), and the type of entity (target name)
+   *
+   * @param integer $sourceId  source ID
+   * @param string $sourceName  source name
+   * @param string $targetName  target name
+   *
+   * @return stdClass  result object
+   */
   public function fetchKeymapEntryBySourceAndTargetName($sourceId, 
$sourceName, $targetName)
   {
     $query = "SELECT target_id FROM keymap \r
       WHERE source_id=? AND source_name=? AND target_name=?";
+
     $statement = QubitFlatfileImport::sqlQuery(
       $query,
       array($sourceId, $sourceName, $targetName)
     );
+
     return $statement->fetch(PDO::FETCH_OBJ);
   }
 
@@ -713,6 +838,17 @@
     return $str;
   }
 
+  /**
+   * Map a value to its corresponding term name then return the term ID
+   * corresponding to the term name
+   *
+   * @param string $description  description of subject (for error output)
+   * @param string $value  value that needs to be mapped to a term ID
+   * @param array $valueToTermNameMap  array mapping possible values to term 
names
+   * @param array $terms  array mapping term IDs to term names
+   *
+   * @return integer  term ID
+   */
   public function translateNameToTermId($description, $value, 
$valueToTermNameMap, $terms)
   {
     if (isset($valueToTermNameMap[$value]))

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to