Author: david
Date: 2008-09-30 11:21:02 -0700 (Tue, 30 Sep 2008)
New Revision: 1409

Modified:
   trunk/apps/qubit/modules/informationobject/actions/createAction.class.php
   trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
   trunk/apps/qubit/modules/informationobject/actions/updateAction.class.php
   trunk/apps/qubit/modules/informationobject/templates/editISADSuccess.php
   trunk/apps/qubit/modules/physicalobject/templates/_edit.php
   trunk/lib/model/QubitInformationObject.php
Log:
On Information Object add and edit pages: add multiInstance select javascript 
to "Conditions of Access" and "Archival Description" languages and scripts, and 
physical object selector for existing containers.  Update 
QubitInformationObject model code to prevent adding duplicate relations.  
Update "update" code to handle arrays of form elements.

Modified: 
trunk/apps/qubit/modules/informationobject/actions/createAction.class.php
===================================================================
--- trunk/apps/qubit/modules/informationobject/actions/createAction.class.php   
2008-09-30 00:20:13 UTC (rev 1408)
+++ trunk/apps/qubit/modules/informationobject/actions/createAction.class.php   
2008-09-30 18:21:02 UTC (rev 1409)
@@ -27,6 +27,11 @@
    $this->informationObject = new QubitInformationObject;
 
    $request->setAttribute('informationObject', $this->informationObject);
+   
+   // Add javascript libraries to allow adding multiple instances of a select 
box
+   $this->getResponse()->addJavaScript('jquery');
+   $this->getResponse()->addJavaScript('/vendor/drupal/misc/drupal');
+   $this->getResponse()->addJavaScript('multiInstanceSelect');
 
    //TermManyToManyRelations
    $this->subjectAccessPoints = null;

Modified: 
trunk/apps/qubit/modules/informationobject/actions/editAction.class.php
===================================================================
--- trunk/apps/qubit/modules/informationobject/actions/editAction.class.php     
2008-09-30 00:20:13 UTC (rev 1408)
+++ trunk/apps/qubit/modules/informationobject/actions/editAction.class.php     
2008-09-30 18:21:02 UTC (rev 1409)
@@ -37,7 +37,7 @@
 
     $request->setAttribute('informationObject', $this->informationObject);
     
-    // Javascript libraries to allow selecting multiple access points
+    // Add javascript libraries to allow selecting multiple access points
     $this->getResponse()->addJavaScript('jquery');
     $this->getResponse()->addJavaScript('/vendor/drupal/misc/drupal');
     $this->getResponse()->addJavaScript('multiInstanceSelect');

Modified: 
trunk/apps/qubit/modules/informationobject/actions/updateAction.class.php
===================================================================
--- trunk/apps/qubit/modules/informationobject/actions/updateAction.class.php   
2008-09-30 00:20:13 UTC (rev 1408)
+++ trunk/apps/qubit/modules/informationobject/actions/updateAction.class.php   
2008-09-30 18:21:02 UTC (rev 1409)
@@ -278,25 +278,61 @@
 
   public function updateProperties($informationObject)
   {
-    if ($this->getRequestParameter('language_code'))
+    
+    // Add multiple languages of access
+    if ($language_codes = $this->getRequestParameter('language_code'))
     {
-      
$informationObject->setProperty($this->getRequestParameter('language_code'), 
$name = 'information_object_language', $scope = 'languages');
-      $this->foreignKeyUpdate = true;
+      // If string, turn into single element array
+      $language_codes = (is_array($language_codes)) ? $language_codes : 
array($language_codes);
+      
+      foreach ($language_codes as $language_code) {
+        if (strlen($language_code)) {
+          $informationObject->addProperty($name = 
'information_object_language', $language_code, $scope = 'languages');
+               $this->foreignKeyUpdate = true;
+        }
+      }
     }
-    if ($this->getRequestParameter('script_code'))
+    
+    // Add multiple scripts of access
+    if ($script_codes = $this->getRequestParameter('script_code'))
     {
-      
$informationObject->setProperty($this->getRequestParameter('script_code'), 
$name = 'information_object_script', $scope = 'scripts');
-      $this->foreignKeyUpdate = true;
+      // If string, turn into single element array
+      $script_codes = (is_array($script_codes)) ? $script_codes : 
array($script_codes);
+      
+      foreach ($script_codes as $script_code) {
+        if (strlen($script_code)) {
+          $informationObject->addProperty($name = 'information_object_script', 
$script_code, $scope = 'scripts');
+          $this->foreignKeyUpdate = true;
+        }
+      }
     }
-    if ($this->getRequestParameter('description_language_code'))
+    
+    // Add multiple languages of description
+    if ($language_codes = 
$this->getRequestParameter('description_language_code'))
     {
-      
$informationObject->setProperty($this->getRequestParameter('description_language_code'),
 $name = 'language_of_information_object_description', $scope = 'languages');
-      $this->foreignKeyUpdate = true;
+      // If string, turn into single element array
+      $language_codes = (is_array($language_codes)) ? $language_codes : 
array($language_codes);
+      
+      foreach ($language_codes as $language_code) {
+        if (strlen($language_code)) {
+          $informationObject->addProperty($name = 
'language_of_information_object_description', $language_code, $scope = 
'languages');
+          $this->foreignKeyUpdate = true;
+        }
+      }
     }
-    if ($this->getRequestParameter('description_script_code'))
+    
+    // Add multiple scripts of description
+    if ($script_codes = $this->getRequestParameter('description_script_code'))
     {
-      
$informationObject->setProperty($this->getRequestParameter('description_script_code'),
 $name = 'script_of_information_object_description', $scope = 'scripts');
-      $this->foreignKeyUpdate = true;
+      // If string, turn into single element array
+      $script_codes = (is_array($script_codes)) ? $script_codes : 
array($script_codes);
+      
+      foreach ($script_codes as $script_code) {
+        if (strlen($script_code)) {
+          $informationObject->addProperty($name = 
'script_of_information_object_description', $script_code, $scope = 'scripts');
+          $this->foreignKeyUpdate = true;
+        }
+      }
     }
   }
   
@@ -516,11 +552,9 @@
   
   
   /**
-   * Update physical object.
+   * Update physical object relations.
    *
-   * @param  sfRequest         The current sfRequest object
    * @param  informationObject The current informationObject object
-   *
    */
   public function updatePhysicalObjects($informationObject)
   {
@@ -550,12 +584,22 @@
       $informationObject->addPhysicalObjectRelation($physicalObject);
     }
     
-    // If form is not populated, check if existing PO selected 
-    else if ($physicalObject = 
QubitPhysicalObject::getById($this->getRequestParameter('physicalObjectId')))
+    // If form is not populated, Add any existing physical objects that are 
selected
+    else if ($physicalObjectIds = 
$this->getRequestParameter('physicalObjectId'))
     {
+      // Make sure that $subject_id is an array, even if it's only got one 
value
+      $physicalObjectIds = (is_array($physicalObjectIds)) ? $physicalObjectIds 
: array($physicalObjectIds);
       
-      $informationObject->addPhysicalObjectRelation($physicalObject);
+      foreach ($physicalObjectIds as $physicalObjectId) {
+        
+        // If a value is set for this select box, and the physical object 
exists,
+        // add a relation to this info object
+        if (intval($physicalObjectId) && (null !== $physicalObject = 
QubitPhysicalObject::getById($physicalObjectId))) {
+          $informationObject->addPhysicalObject($physicalObject);
+          $this->foreignKeyUpdate = true;
+        }
+      }
     }
     
-  } // end fuction updatePhysicalObjects
+  } // end method: updatePhysicalObjects
 }

Modified: 
trunk/apps/qubit/modules/informationobject/templates/editISADSuccess.php
===================================================================
--- trunk/apps/qubit/modules/informationobject/templates/editISADSuccess.php    
2008-09-30 00:20:13 UTC (rev 1408)
+++ trunk/apps/qubit/modules/informationobject/templates/editISADSuccess.php    
2008-09-30 18:21:02 UTC (rev 1409)
@@ -218,7 +218,7 @@
           </div>
         <?php endforeach; ?>
       <?php endif; ?>
-      <?php echo select_language_tag('language_code', null, 
array('include_blank' => true)) ?>
+      <?php echo select_language_tag('language_code', null, 
array('include_blank' => true, 'class'=>'multiInstance')) ?>
      </div>
 
     <div class="form-item">
@@ -230,7 +230,7 @@
           </div>
         <?php endforeach; ?>
       <?php endif; ?>
-      <?php echo select_script_tag('script_code', null, array('include_blank' 
=> true)) ?>
+      <?php echo select_script_tag('script_code', null, array('include_blank' 
=> true, 'class'=>'multiInstance')) ?>
     </div>
 
     <div class="form-item">
@@ -406,7 +406,7 @@
           </div>
         <?php endforeach; ?>
       <?php endif; ?>
-      <?php echo select_language_tag('description_language_code', null, 
array('include_blank' => true)) ?>
+      <?php echo select_language_tag('description_language_code', null, 
array('include_blank' => true, 'class'=>'multiInstance')) ?>
     </div>
 
     <div class="form-item">
@@ -418,7 +418,7 @@
           </div>
         <?php endforeach; ?>
       <?php endif; ?>
-      <?php echo select_script_tag('description_script_code', null, 
array('include_blank' => true)) ?>
+      <?php echo select_script_tag('description_script_code', null, 
array('include_blank' => true, 'class'=>'multiInstance')) ?>
     </div>
 
     <div class="form-item">

Modified: trunk/apps/qubit/modules/physicalobject/templates/_edit.php
===================================================================
--- trunk/apps/qubit/modules/physicalobject/templates/_edit.php 2008-09-30 
00:20:13 UTC (rev 1408)
+++ trunk/apps/qubit/modules/physicalobject/templates/_edit.php 2008-09-30 
18:21:02 UTC (rev 1409)
@@ -41,13 +41,13 @@
 <table class="inline" style="width: 98%;">
   <tr>
     <td colspan="3" class="headerCell" style="width: 98%">
-      <?php echo __('link to an existing container'); ?>
+      <?php echo __('add container links (duplicate links will be ignored)'); 
?>
     </td>
   </tr>
 </table>
 <div class="form-item">
   <?php echo object_select_tag(null, null, 
-    array('related_class'=>'QubitPhysicalObject', 'name'=>'physicalObjectId', 
'include_blank'=>true)); ?><br />
+    array('related_class'=>'QubitPhysicalObject', 'name'=>'physicalObjectId', 
'include_blank'=>true, 'class'=>'multiInstance')); ?><br />
 </div>
 
 

Modified: trunk/lib/model/QubitInformationObject.php
===================================================================
--- trunk/lib/model/QubitInformationObject.php  2008-09-30 00:20:13 UTC (rev 
1408)
+++ trunk/lib/model/QubitInformationObject.php  2008-09-30 18:21:02 UTC (rev 
1409)
@@ -404,16 +404,56 @@
     return QubitObjectTermRelation::getOne($criteria);
   }
 
-  public function setProperty($code, $name = null, $scope = null)
+  /**
+   * Add a property related to this information object
+   * 
+   * @param string $name  Name of property
+   * @param string $value Value of property
+   * @param string $scope Add scope note (optional)
+   * @return QubitInformationObject this information object
+   */
+  public function addProperty($name, $value, $scope = null)
   {
-    $newCode = new QubitProperty;
-    $newCode->setObjectId($this->getId());
-    $newCode->setScope($scope);
-    $newCode->setName($name);
-    $newCode->setValue($code);
-    $newCode->save();
+    // Only add this property if an identical one does NOT exist already
+    if ($this->getProperty($name, $value, $scope) === null) {
+           $newCode = new QubitProperty;
+           $newCode->setObjectId($this->getId());
+           $newCode->setName($name);
+           $newCode->setValue($value);
+           $newCode->setScope($scope);
+           $newCode->save();
+    }
+    
+    return $this;
   }
-
+  
+  /**
+   * Get an existing property related to this information object.
+   * 
+   * @param string $code  QubitProperty value column value
+   * @param string $name  QubitProperty name column value
+   * @param string $scope QubitProperty scope column value (default: null)
+   * @return QubitProperty if match found, null if no match
+   */
+  public function getProperty($name, $value, $scope = null)
+  {
+    $criteria = new Criteria;
+    $criteria->add(QubitProperty::OBJECT_ID, $this->getId());
+    $criteria->add(QubitProperty::NAME, $name);
+    $criteria->add(QubitProperty::VALUE, $value);
+    $criteria->add(QubitProperty::SCOPE, $scope);
+    
+    return QubitProperty::getOne($criteria);
+  }
+  
+  /**
+   * Return all properties related to this information object,
+   * with option of filtering by name and/or scope
+   * 
+   * @param string $name filter results by name (optional)
+   * @param string $scope filter results by scope (optional)
+   * @return QubitQuery list of QubitProperty objects matching criteria 
+   */
   public function getProperties($name = null, $scope = null)
   {
     $criteria = new Criteria;
@@ -690,33 +730,36 @@
    * sure the relationship is unique.
    *
    * @param QubitPhysicalObject $physicalObject Subject of relationship
-   * @return mixed false on failure, QubitRelation on success
+   * @return QubitInformationObject this object
    */
-  public function addPhysicalObjectRelation($physicalObject)
+  public function addPhysicalObject($physicalObject)
   {
-    // Verify that $physicalObject is a Physical Object
-    if (get_class($physicalObject) != 'QubitPhysicalObject')
-    {
-      return false;
-    }
-
+    // Verify that $physicalObject is really a Physical Object and
     // Don't add an identical info object -> physical object relationship
-    $relatedPhysicalObjects = 
QubitRelation::getRelatedSubjectsByObjectId($this->getId(),
-      array('typeId', QubitTerm::HAS_PHYSICAL_OBJECT_ID));
-    foreach ($relatedPhysicalObjects as $relatedPhysicalObject)
+    if (get_class($physicalObject) == 'QubitPhysicalObject' && 
$this->getPhysicalObject($physicalObject->getId()) === null)
     {
-      if ($relatedPhysicalObject->getId() == $physicalObject->getId())
-      {
-        return false;
-      }
+           $relation = new QubitRelation;
+           $relation->setObject($this);
+           $relation->setSubject($physicalObject);
+           $relation->setTypeId(QubitTerm::HAS_PHYSICAL_OBJECT_ID);
+           $relation->save();
     }
 
-    $relation = new QubitRelation;
-    $relation->setObject($this);
-    $relation->setSubject($physicalObject);
-    $relation->setTypeId(QubitTerm::HAS_PHYSICAL_OBJECT_ID);
-    $relation->save();
-
-    return $relation;
+    return $this;
   }
+  
+  /**
+   * Get a physical object related to this info object
+   * 
+   * @param integer $physicalObjectId the id of the related physical object
+   * @return mixed the QubitRelation object on success, null if no match found
+   */
+  public function getPhysicalObject($physicalObjectId)
+  {
+    $criteria = new Criteria;
+    $criteria->add(QubitRelation::OBJECT_ID, $this->getId());
+    $criteria->add(QubitRelation::SUBJECT_ID, $physicalObjectId);
+    
+    return QubitRelation::getOne($criteria);
+  }
 }


--~--~---------~--~----~------------~-------~--~----~
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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to