/**
  * Save a related property and create a new property if a matching one doesn't
  * already exist.
  *
  * @param string $name name of property
  * @param string $value new value to set
  * @param array $options array of options
  * @return QubitInformationObject
  */
 public function saveProperty($name, $value, $options = array())
 {
     // Get existing property if possible
     if (null === ($property = QubitProperty::getOneByObjectIdAndName($this->id, $name, $options))) {
         // Create a new property if required
         $property = new QubitProperty();
         $property->setObjectId($this->id);
         $property->setName($name);
         if (isset($options['scope'])) {
             $property->setScope($options['scope']);
         }
     }
     $property->setValue($value, $options);
     $property->save();
     return $this;
 }
 /**
  * Set 'page_count' property for this asset
  *
  * NOTE: requires the ImageMagick library
  *
  * @return QubitDigitalObject this object
  */
 public function setPageCount()
 {
     if ($this->canThumbnail() && self::hasImageMagick()) {
         if (QubitTerm::EXTERNAL_URI_ID == $this->usageId) {
             $command = 'identify ' . $this->localPath;
         } else {
             $command = 'identify ' . $this->getAbsolutePath();
         }
         exec($command, $output, $status);
         if ($status == 0) {
             // Add "number of pages" property
             $pageCount = new QubitProperty();
             $pageCount->setObjectId($this->id);
             $pageCount->setName('page_count');
             $pageCount->setScope('digital_object');
             $pageCount->setValue(count($output), array('sourceCulture' => true));
             $pageCount->save();
         }
     }
     return $this;
 }
 /**
  * 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;
 }