/** * Returns a PropertyValue object for the specified base object (User, Domain or Account) * * @param User|Domain|Account $obj The reference object * @throws Exception * @return PropertyValue */ private function getValueObject($obj) { $query = PropertyValueQuery::create(); if ($obj instanceof User) { $query->filterByUser($obj); } elseif ($obj instanceof Domain) { $query->filterByDomain($obj); } elseif ($obj instanceof Account) { $query->filterByAccount($obj); } else { throw new Exception('Invalid base object applied. User, Domain or Account expected!'); } $property_value = $query->findOneByProperty($this); if (!$property_value) { $property_value = new PropertyValue(); $property_value->setProperty($this); if ($obj instanceof User) { $property_value->setUser($obj); } elseif ($obj instanceof Domain) { $property_value->setDomain($obj); } elseif ($obj instanceof Account) { $property_value->setAccount($obj); } } return $property_value; }
/** * Stores a property. * * @param string $name Property name * @param mixed $value Property value * @param PropelPDO $con Optional. The database connection to use. * Default is NULL. * @return self Returns $this. */ public function setProperty($name, $value, PropelPDO $con = null) { $property = PropertyQuery::create()->filterByAccount($this)->findOneByName($name, $con); if ($property === null) { throw new Exception('Could not find property "' . $name . '".'); } /* @var PropertyValue $propertyValue */ $propertyValue = PropertyValueQuery::create()->filterByDomainId(null)->filterByUserId(null)->findOneByPropertyId($property->getId(), $con); if ($propertyValue === null) { $propertyValue = new PropertyValue(); $propertyValue->setProperty($property); } $propertyValue->set($value)->save($con); return $this; }
/** * Stores a property. * * @param string $name Property name * @param mixed $value Property value * @param PropelPDO $con Optional. The database connection to use. * Default is NULL. * @return BaseObject Returns {@link $object}. */ public static function setProperty(BaseObject $object, $name, $value, PropelPDO $con = null) { $property = PropertyQuery::create()->filterByAccount($object->getAccount($con))->findOneByName($name, $con); if ($property === null) { throw new Exception('Could not find property "' . $name . '".'); } $class = get_class($object); /* @var PropertyValue $propertyValue */ $propertyValue = PropertyValueQuery::create()->{'filterBy' . $class}($object)->findOneByPropertyId($property->getId(), $con); if ($propertyValue === null) { $propertyValue = new PropertyValue(); $propertyValue->setProperty($property)->{'set' . $class}($object); } $propertyValue->set($value)->save($con); return $object; }
/** * @param PropertyValue $propertyValue The propertyValue object to add. */ protected function doAddPropertyValue($propertyValue) { $this->collPropertyValues[] = $propertyValue; $propertyValue->setProperty($this); }