Author: mcantelon
Date: Mon Jan 30 17:46:16 2012
New Revision: 10780

Log:
Created helper method for rightsholder creation.

Modified:
   trunk/lib/QubitFlatfileImport.class.php
   trunk/lib/task/import/csvImportTask.class.php

Modified: trunk/lib/QubitFlatfileImport.class.php
==============================================================================
--- trunk/lib/QubitFlatfileImport.class.php     Mon Jan 30 17:03:34 2012        
(r10779)
+++ trunk/lib/QubitFlatfileImport.class.php     Mon Jan 30 17:46:16 2012        
(r10780)
@@ -857,7 +857,7 @@
    * @param string $name  name of actor
    * @param string $history  history of actor (optional)
    *
-   * @return QubitActor  created term or fetched object containing actor data
+   * @return QubitActor  created or fetched actor
    */
   public function createOrFetchActor($name, $history = false)
   {
@@ -875,6 +875,37 @@
   }
 
   /**
+   * Create a Qubit rights holder or, if one already exists, fetch it
+   *
+   * @param string $name  name of rights holder
+   *
+   * @return QubitRightsHolder  created or fetched rights holder
+   */
+  public function createOrFetchRightsHolder($name)
+  {
+    $query = "SELECT object.id
+      FROM object JOIN actor_i18n i18n
+      ON object.id = i18n.id
+      WHERE i18n.authorized_form_of_name = ?
+      AND object.class_name = 'QubitRightsHolder';";
+
+    $statement = QubitFlatfileImport::sqlQuery($query, array($name));
+
+    $result = $statement->fetch(PDO::FETCH_OBJ);
+
+    if (!$result)
+    {
+      $rightsHolder = new QubitRightsHolder;
+      $rightsHolder->authorizedFormOfName = $name;
+      $rightsHolder->save();
+    } else {
+      $rightsHolder = QubitRightsHolder::getById($result->id);
+    }
+
+    return $rightsHolder;
+  }
+
+  /**
    * Create Qubit contract information for an actor or, if it already exists,
    * fetch it
    *

Modified: trunk/lib/task/import/csvImportTask.class.php
==============================================================================
--- trunk/lib/task/import/csvImportTask.class.php       Mon Jan 30 17:03:34 
2012        (r10779)
+++ trunk/lib/task/import/csvImportTask.class.php       Mon Jan 30 17:46:16 
2012        (r10780)
@@ -355,26 +355,10 @@
                 $rightsHolderId = FALSE;
                 if ($self->rowStatusVars['copyrightHolder'])
                 {
-                  $query = "SELECT object.id
-                    FROM object JOIN actor_i18n i18n
-                    ON object.id = i18n.id
-                    WHERE i18n.authorized_form_of_name = ?
-                    AND object.class_name = 'QubitRightsHolder';";
-
-                  $statement = $self->sqlQuery($query, 
array($self->rowStatusVars['copyrightHolder']));
-
-                  $result = $statement->fetch(PDO::FETCH_OBJ);
-
-                  if (!$result)
-                  {
-                    $rightsHolder = new QubitRightsHolder;
-                    $rightsHolder->authorizedFormOfName = 
$self->rowStatusVars['copyrightHolder'];
-                    $rightsHolder->save();
-
-                    $rightsHolderId = $rightsHolder->id;
-                  } else {
-                    $rightsHolderId = $result->id;
-                  }
+                  $rightsHolder = $self->createOrFetchRightsHolder(
+                    $self->rowStatusVars['copyrightHolder']
+                  );
+                  $rightsHolderId = $rightsHolder->id;
                 }
 
                 $rightAndRelation = array(

-- 
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