Esempio n. 1
0
 /**
  * Returns a new PropertyQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   PropertyQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return PropertyQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof PropertyQuery) {
         return $criteria;
     }
     $query = new PropertyQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * Returns the number of related Property objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related Property objects.
  * @throws PropelException
  */
 public function countPropertys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collPropertysPartial && !$this->isNew();
     if (null === $this->collPropertys || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collPropertys) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getPropertys());
         }
         $query = PropertyQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByAccount($this)->count($con);
     }
     return count($this->collPropertys);
 }
Esempio n. 4
0
 /**
  * Updates a property
  *
  * @param int $id The property ID
  * @param array $data
  * @return int The property ID
  */
 public function do_update($id, $data = null)
 {
     $user = $this->requireUser();
     if (!$user->isAdmin()) {
         throw new Exception('Only administrators are allowed to edit properties.');
     }
     // Validate input data
     $validator = new KickstartValidator();
     $locale = Localizer::getInstance();
     $warnings = $validator->filterErrors($data, $this->initFilter($this->filter_basic, $locale));
     if ($warnings) {
         return array('result' => false, 'warnings' => $warnings);
     }
     $query = PropertyQuery::create()->filterByAccount($user->getAccount());
     if ($id !== null) {
         $query->filterById($id, Criteria::NOT_EQUAL);
         $property = PropertyQuery::create()->filterByAccount($user->getAccount())->findOneById($id);
         if (!$property) {
             throw new Exception('Property not found; ID: ' . $id);
         }
     } else {
         $property = new Property();
     }
     // Check for duplicates
     if (isset($data['Name']) and $query->findOneByName($data['Name'])) {
         throw new Exception($locale->insert('error.taken', array('value' => '"' . $data['Name'] . '"')));
     }
     unset($data['Id']);
     $property->fromArray($data);
     $property->setAccount($user->getAccount());
     $property->save();
     return $property->getId();
 }
Esempio n. 5
0
 /**
  * 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(PropertyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = PropertyQuery::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;
     }
 }
Esempio n. 6
0
 /**
  * Retrieves the most-specific property value for the specified user, domain or account.
  *
  * If a user does not have a specific value set, the user's domain is
  * searched for the value, and if this does not yield anything, the account
  * will be scanned for the default value.
  *
  * @param string $name The property name.
  * @param Account $account The account defining the properties.
  * @param Domain $domain Optional. Default is NULL.
  * @param User $user Optional. Default is NULL.
  * @param PropelPDO $con Optional. The database connection to use.
  *     Default is NULL.
  * @return mixed The property value, or NULL if no property is found.
  * @see getProperty()
  */
 public static function get($name, Account $account, Domain $domain = null, User $user = null, PropelPDO $con = null)
 {
     $property = PropertyQuery::create()->filterByAccount($account)->findOneByName($name, $con);
     if ($property === null) {
         return null;
     }
     $accountId = $account->getId();
     $domainId = $domain === null ? null : $domain->getId();
     $userId = $user === null ? null : $user->getId();
     $values = self::createPropertyValueQuery($accountId, null, null)->findByPropertyId($property->getId(), $con);
     $result = PropertyPeer::initValue(json_decode($property->getDefaultValue(), true), $property->getType());
     foreach ($values as $value) {
         $valueUserId = $value->getUserId();
         if ($valueUserId !== null and $valueUserId === $userId) {
             return $value->get($con);
         } elseif ($valueUserId !== null) {
             continue;
         } elseif ($value->getDomainId() === $domainId and $domainId !== null) {
             $result = $value->get($con);
         }
     }
     return $result;
 }
Esempio n. 7
0
 /**
  * Get the associated Property object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Property The associated Property object.
  * @throws PropelException
  */
 public function getProperty(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aProperty === null && $this->property_id !== null && $doQuery) {
         $this->aProperty = PropertyQuery::create()->findPk($this->property_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aProperty->addPropertyValues($this);
            */
     }
     return $this->aProperty;
 }