/** * 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; }
/** * Setter for "displayAsCompound" property * * @param string $value new value for property * @return QubitInformationObject this object */ public function setDisplayAsCompoundObject($value) { $criteria = new Criteria(); $criteria->add(QubitProperty::OBJECT_ID, $this->id); $criteria->add(QubitProperty::NAME, 'displayAsCompound'); $displayAsCompoundProp = QubitProperty::getOne($criteria); if (is_null($displayAsCompoundProp)) { $displayAsCompoundProp = new QubitProperty(); $displayAsCompoundProp->setObjectId($this->id); $displayAsCompoundProp->setName('displayAsCompound'); } $displayAsCompoundProp->setValue($value, array('sourceCulture' => true)); $displayAsCompoundProp->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; }