Author: david
Date: 2008-11-11 16:03:58 -0800 (Tue, 11 Nov 2008)
New Revision: 1577

Modified:
   trunk/qubit/lib/model/QubitActor.php
   trunk/qubit/lib/model/QubitInformationObject.php
   trunk/qubit/lib/model/QubitProperty.php
Log:
Add QubitProperty::addUnique() method, and use it for adding language and 
script properties to info objects, actors and repositories. Fixes issue #511.

Modified: trunk/qubit/lib/model/QubitActor.php
===================================================================
--- trunk/qubit/lib/model/QubitActor.php        2008-11-11 23:35:14 UTC (rev 
1576)
+++ trunk/qubit/lib/model/QubitActor.php        2008-11-12 00:03:58 UTC (rev 
1577)
@@ -247,7 +247,7 @@
    */
   public function addProperty($name, $value, $options = array())
   {
-    $property = QubitProperty::addProperty($this->getId(), $name, $value, 
$options);
+    $property = QubitProperty::addUnique($this->getId(), $name, $value, 
$options);
 
     return $this;
   }

Modified: trunk/qubit/lib/model/QubitInformationObject.php
===================================================================
--- trunk/qubit/lib/model/QubitInformationObject.php    2008-11-11 23:35:14 UTC 
(rev 1576)
+++ trunk/qubit/lib/model/QubitInformationObject.php    2008-11-12 00:03:58 UTC 
(rev 1577)
@@ -417,22 +417,8 @@
    */
   public function addProperty($name, $value, $options = array())
   {
-    // Only add if an existing property does not exist
-    if (!QubitProperty::isExistent($this->getId(), $name, $value, $options))
-    {
-      $property = new QubitProperty;
-      $property->setObjectId($this->getId());
-      $property->setName($name);
-      $property->setValue($value, $options);
+    QubitProperty::addUnique($this->getId(), $name, $value, $options);
 
-      if (isset($options['scope']))
-      {
-        $property->setScope($options['scope']);
-      }
-
-      $property->save();
-    }
-
     return $this;
   }
 

Modified: trunk/qubit/lib/model/QubitProperty.php
===================================================================
--- trunk/qubit/lib/model/QubitProperty.php     2008-11-11 23:35:14 UTC (rev 
1576)
+++ trunk/qubit/lib/model/QubitProperty.php     2008-11-12 00:03:58 UTC (rev 
1577)
@@ -100,6 +100,39 @@
   }
 
   /**
+   * Add property after verifying that there isn't already one with an 
identical
+   * object_id, name, and (optionally) scope.
+   *
+   * @param integer $objectId related object foreign key
+   * @param string  $name name of property
+   * @param string  $value value to set for property
+   * @param array   $options optional parameters
+   * @return QubitProperty this property object
+   */
+  public static function addUnique($objectId, $name, $value, $options = 
array())
+  {
+    // Only add if an existing property does not exist
+    if (!QubitProperty::isExistent($objectId, $name, $value, $options))
+    {
+      $property = new QubitProperty;
+      $property->setObjectId($objectId);
+      $property->setName($name);
+      $property->setValue($value, $options);
+
+      if (isset($options['scope']))
+      {
+        $property->setScope($options['scope']);
+      }
+
+      $property->save();
+
+      return $property;
+    }
+
+    return null;
+  }
+
+  /**
    * Determine if a property matching passed values already exists.
    *
    * @param integer $objectId foreign key to QubitObject::ID


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