/** * 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; }
/** * Returns a list of properties. * * @param array $names Optional. Array with names of properties to return. * If omitted or NULL, all domain-specific properties will be returned. * Default is NULL. * @param PropelPDO $con Optional. The database connection to use. * Default is NULL. * @return array An associative array mapping property names to associative * arrays of value (key "Value") and type string (key "Type"). */ public function getProperties(array $names = null, PropelPDO $con = null) { $query = PropertyValueQuery::create()->joinWith('Property')->add(PropertyPeer::ACCOUNT_ID, $this->getId())->filterByDomainId(null)->filterByUserId(null); if (is_array($names)) { $query->filterBy(PropertyPeer::NAME, $names, Criteria::IN); } $result = array(); foreach ($query->find($con) as $propertyValue) { /* @var PropertyValue $propertyValue */ $property = $propertyValue->getProperty($con); $result[$property->getName()] = array('Value' => $propertyValue->get(), 'Type' => $property->getType()); } return $result; }
private static function createPropertyValueQuery($accountId, $domainId, $userId) { $query = PropertyValueQuery::create()->joinProperty(); if ($accountId !== null) { $query->add(PropertyPeer::ACCOUNT_ID, $accountId); } if ($domainId !== null) { $query->add(PropertyValuePeer::DOMAIN_ID, $domainId); } if ($userId !== null) { $query->add(PropertyValuePeer::USER_ID, $userId); } return $query; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Property is new, it will return * an empty collection; or if this Property has previously * been saved, it will retrieve related PropertyValues from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Property. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|PropertyValue[] List of PropertyValue objects */ public function getPropertyValuesJoinUser($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = PropertyValueQuery::create(null, $criteria); $query->joinWith('User', $join_behavior); return $this->getPropertyValues($query, $con); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(PropertyValuePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = PropertyValueQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }