/** * Set the value of [value] column. * * @param string $v new value * @param PropelPDO $con Optional. The database connection to use. * Default is NULL. * @return PropertyValue The current object (for fluent API support) */ public function set($v, PropelPDO $con = null) { $property = $this->getProperty($con); if ($property === null) { throw new Exception('Could not get property definition for property value #' . $this->id . '.'); } $v = PropertyPeer::initValue($v, $property->getType()); return $this->setValue(json_encode($v)); }
public static function retrieveMunicipality($text, $limit) { $criteria = new Criteria(); $criteria->add(PropertyPeer::MUNICIPALITY, '%' . $text . '%', Criteria::LIKE); $criteria->addAscendingOrderByColumn(PropertyPeer::MUNICIPALITY); $criteria->setLimit($limit); $municipalities = array(); foreach (PropertyPeer::doSelect($criteria) as $property) { $municipalities[$property->getMunicipality()] = (string) $property->getMunicipality(); } return $municipalities; }
/** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. * * @param mixed $key Primary key to use for the query * @param PropelPDO $con A connection object * * @return Property A model object, or null if the key is not found * @throws PropelException */ protected function findPkSimple($key, $con) { $sql = 'SELECT `id`, `account_id`, `name`, `label`, `description`, `type`, `default_value`, `fixed` FROM `property` WHERE `id` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); $stmt->execute(); } catch (Exception $e) { Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); } $obj = null; if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new Property(); $obj->hydrate($row); PropertyPeer::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this State is new, it will return * an empty collection; or if this State has previously * been saved, it will retrieve related Propertys 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 State. */ public function getPropertysJoinsfAssetFolder($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(StatePeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collPropertys === null) { if ($this->isNew()) { $this->collPropertys = array(); } else { $criteria->add(PropertyPeer::STATE_ID, $this->id); $this->collPropertys = PropertyPeer::doSelectJoinsfAssetFolder($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(PropertyPeer::STATE_ID, $this->id); if (!isset($this->lastPropertyCriteria) || !$this->lastPropertyCriteria->equals($criteria)) { $this->collPropertys = PropertyPeer::doSelectJoinsfAssetFolder($criteria, $con, $join_behavior); } } $this->lastPropertyCriteria = $criteria; return $this->collPropertys; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(PropertyPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(PropertyPeer::DATABASE_NAME); $criteria->add(PropertyPeer::ID, $pks, Criteria::IN); $objs = PropertyPeer::doSelect($criteria, $con); } return $objs; }
/** * Selects a collection of PropertyValue objects pre-filled with all related objects except User. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of PropertyValue objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(PropertyValuePeer::DATABASE_NAME); } PropertyValuePeer::addSelectColumns($criteria); $startcol2 = PropertyValuePeer::NUM_HYDRATE_COLUMNS; DomainPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + DomainPeer::NUM_HYDRATE_COLUMNS; PropertyPeer::addSelectColumns($criteria); $startcol4 = $startcol3 + PropertyPeer::NUM_HYDRATE_COLUMNS; $criteria->addJoin(PropertyValuePeer::DOMAIN_ID, DomainPeer::ID, $join_behavior); $criteria->addJoin(PropertyValuePeer::PROPERTY_ID, PropertyPeer::ID, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = PropertyValuePeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = PropertyValuePeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = PropertyValuePeer::getOMClass(); $obj1 = new $cls(); $obj1->hydrate($row); PropertyValuePeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Domain rows $key2 = DomainPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = DomainPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = DomainPeer::getOMClass(); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); DomainPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (PropertyValue) to the collection in $obj2 (Domain) $obj2->addPropertyValue($obj1); } // if joined row is not null // Add objects for joined Property rows $key3 = PropertyPeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = PropertyPeer::getInstanceFromPool($key3); if (!$obj3) { $cls = PropertyPeer::getOMClass(); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); PropertyPeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (PropertyValue) to the collection in $obj3 (Property) $obj3->addPropertyValue($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = TypePeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Property objects $c = new Criteria(PropertyPeer::DATABASE_NAME); $c->add(PropertyPeer::TYPE_ID, $obj->getId()); $affectedRows += PropertyPeer::doDelete($c, $con); } return $affectedRows; }
protected function _ENV($elem) { $key = (string) $elem['KEY']; switch ($elem['TYPE']) { case 'tymio': switch ($key) { case 'API_URL': return $this->getApiUrl(); default: return null; } case 'server': return isset($_SERVER[$key]) ? $_SERVER[$key] : null; case 'property': default: $userId = (string) $elem['USER']; $user = $this->getUser($this->user, $userId); return $key === '' ? PropertyPeer::getAll($this->account, null, $user) : PropertyPeer::get($key, $this->account, null, $user); } }
public static function ldapAuthenticate(User $user, $password, PropelPDO $con = null) { $account = $user->getAccount($con); if ($account === null) { throw new Exception('Could not determine account of user #' . $user->getId() . ' "' . $user->getName . '".'); } $ldapSettings = PropertyPeer::getAll($account, null, null, array(self::LDAP_SETTING_HOST, self::LDAP_SETTING_LOGIN_NAME, self::LDAP_SETTING_OPTIONS, self::LDAP_SETTING_PORT), $con); if (!isset($ldapSettings[self::LDAP_SETTING_HOST], $ldapSettings[self::LDAP_SETTING_LOGIN_NAME])) { return false; } $ldapLoginName = KeyReplace::replace($ldapSettings[self::LDAP_SETTING_LOGIN_NAME], array('user' => $user->getName(), 'account' => $account->getIdentifier())); if ((string) $password === '') { return false; } //throw new Exception('Password must not be empty for LDAP authentication.'); try { new LDAP($ldapSettings[self::LDAP_SETTING_HOST], $ldapLoginName, $password, (isset($ldapSettings[self::LDAP_SETTING_OPTIONS]) and is_array($ldapSettings[self::LDAP_SETTING_OPTIONS])) ? $ldapSettings[self::LDAP_SETTING_OPTIONS] : array(), isset($ldapSettings[self::LDAP_SETTING_PORT]) ? $ldapSettings[self::LDAP_SETTING_PORT] : null); return true; } catch (Exception $e) { return false; } }
/** * Sets multiple properties from an array. * * @param array $values Associative array mapping property names to values. * @param PropelPDO $con Optional. The database connection to use. * Default is NULL. * @return self */ public function setProperties(array $values, PropelPDO $con = null) { return PropertyPeer::setProperties($this, $values, $con); }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = AccountPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related BookingType objects $criteria = new Criteria(BookingTypePeer::DATABASE_NAME); $criteria->add(BookingTypePeer::ACCOUNT_ID, $obj->getId()); $affectedRows += BookingTypePeer::doDelete($criteria, $con); // delete related ClockingType objects $criteria = new Criteria(ClockingTypePeer::DATABASE_NAME); $criteria->add(ClockingTypePeer::ACCOUNT_ID, $obj->getId()); $affectedRows += ClockingTypePeer::doDelete($criteria, $con); // delete related Domain objects $criteria = new Criteria(DomainPeer::DATABASE_NAME); $criteria->add(DomainPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += DomainPeer::doDelete($criteria, $con); // delete related Holiday objects $criteria = new Criteria(HolidayPeer::DATABASE_NAME); $criteria->add(HolidayPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += HolidayPeer::doDelete($criteria, $con); // delete related Plugin objects $criteria = new Criteria(PluginPeer::DATABASE_NAME); $criteria->add(PluginPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += PluginPeer::doDelete($criteria, $con); // delete related Property objects $criteria = new Criteria(PropertyPeer::DATABASE_NAME); $criteria->add(PropertyPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += PropertyPeer::doDelete($criteria, $con); // delete related User objects $criteria = new Criteria(UserPeer::DATABASE_NAME); $criteria->add(UserPeer::ACCOUNT_ID, $obj->getId()); $affectedRows += UserPeer::doDelete($criteria, $con); } return $affectedRows; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's BasePeer::TYPE_PHPNAME * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = PropertyPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setAccountId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setName($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setLabel($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDescription($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setType($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setDefaultValue($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setFixed($arr[$keys[7]]); } }
/** * 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; }
/** * Ajax for municipality field * * @param sfWebRequest $request * @return string */ public function executeMunicipalityAjax(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $municipality = PropertyPeer::retrieveMunicipality($request->getParameter('text'), $request->getParameter('limit')); return $this->renderText(json_encode($municipality)); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = PropertyPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setSlug($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setMunicipality($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setAddress($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setArea($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setOfferId($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setTypeId($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setTypologyId($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setDescription($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setStateId($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setYear($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setFloors($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setOnFloor($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setSurface($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setHeating($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setGarden($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setBalcony($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setBath($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setBedroom($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setEntrance($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setKitchenId($arr[$keys[20]]); } if (array_key_exists($keys[21], $arr)) { $this->setDiningroom($arr[$keys[21]]); } if (array_key_exists($keys[22], $arr)) { $this->setLivingroom($arr[$keys[22]]); } if (array_key_exists($keys[23], $arr)) { $this->setCellar($arr[$keys[23]]); } if (array_key_exists($keys[24], $arr)) { $this->setLift($arr[$keys[24]]); } if (array_key_exists($keys[25], $arr)) { $this->setAttic($arr[$keys[25]]); } if (array_key_exists($keys[26], $arr)) { $this->setParking($arr[$keys[26]]); } if (array_key_exists($keys[27], $arr)) { $this->setPrice($arr[$keys[27]]); } if (array_key_exists($keys[28], $arr)) { $this->setIsPublic($arr[$keys[28]]); } if (array_key_exists($keys[29], $arr)) { $this->setHasPriority($arr[$keys[29]]); } if (array_key_exists($keys[30], $arr)) { $this->setSfAssetFolderId($arr[$keys[30]]); } if (array_key_exists($keys[31], $arr)) { $this->setCreatedAt($arr[$keys[31]]); } if (array_key_exists($keys[32], $arr)) { $this->setUpdatedAt($arr[$keys[32]]); } }
/** * Checks whether the clocking's start and end dates are within the time limit. * Throws an exception if the time limit is exceeded. * * @return void * @see pastGraceTimeExceeded() */ private function validateTimeLimits(Account $account, User $authUser, Clocking $clocking, PropelPDO $con = null) { $type = $clocking->getClockingType($con); if ($type === null) { throw new Exception('Could not get clocking type with ID #' . $clocking->getTypeId() . ' for clocking #' . $clocking->getId() . '.'); } // Check time limit in seconds $propertyName = KeyReplace::replace(self::PROPERTY_CLOCKING_TIME_LIMIT, array('type' => $type->getIdentifier())); $domain = $authUser->getDomain($con); $lastChanged = $clocking->getLastChanged('U'); $end = $clocking->getEnd('U'); // Check clocking-type-specific limit first, fall back to default $editTimeLimit = PropertyPeer::get($propertyName, $account, $domain, $authUser, $con); if ($editTimeLimit === null) { $editTimeLimit = PropertyPeer::get(self::PROPERTY_CLOCKING_TIME_LIMIT_DEFAULT, $account, $domain, $authUser, $con); } $errorData = array('changed' => $lastChanged, 'end' => $end, 'limit' => $editTimeLimit); if ($editTimeLimit !== null and !is_numeric($editTimeLimit)) { throw new APIException(self::ERROR_TIME_LIMIT, 'Invalid non-numeric value ' . json_encode($editTimeLimit) . ' encountered for property "' . $propertyName . '".', $errorData); } $minTimeAllowed = time() - $editTimeLimit; $result = ((double) $end > $minTimeAllowed and ($clocking->isNew() or (double) $lastChanged > $minTimeAllowed)); if ($result) { return; } throw new APIException(self::ERROR_TIME_LIMIT, 'Clocking cannot be edited any more after ' . round($editTimeLimit / 3600.0, 2) . ' hours.', $errorData); }