/** * 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(PasswordRequestPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(PasswordRequestPeer::DATABASE_NAME); $criteria->add(PasswordRequestPeer::ID, $pks, Criteria::IN); $objs = PasswordRequestPeer::doSelect($criteria, $con); } return $objs; }
/** * Returns the number of related PasswordRequest objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related PasswordRequest objects. * @throws PropelException */ public function countPasswordRequests(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(PersonPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collPasswordRequests === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(PasswordRequestPeer::PERSON_ID, $this->id); $count = PasswordRequestPeer::doCount($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // 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 count of the collection. $criteria->add(PasswordRequestPeer::PERSON_ID, $this->id); if (!isset($this->lastPasswordRequestCriteria) || !$this->lastPasswordRequestCriteria->equals($criteria)) { $count = PasswordRequestPeer::doCount($criteria, $con); } else { $count = count($this->collPasswordRequests); } } else { $count = count($this->collPasswordRequests); } } return $count; }
/** * 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 = PersonPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related EmailTemplate objects $c = new Criteria(EmailTemplatePeer::DATABASE_NAME); $c->add(EmailTemplatePeer::PERSON_ID, $obj->getId()); $affectedRows += EmailTemplatePeer::doDelete($c, $con); // delete related PasswordRequest objects $c = new Criteria(PasswordRequestPeer::DATABASE_NAME); $c->add(PasswordRequestPeer::PERSON_ID, $obj->getId()); $affectedRows += PasswordRequestPeer::doDelete($c, $con); // delete related PersonRole objects $c = new Criteria(PersonRolePeer::DATABASE_NAME); $c->add(PersonRolePeer::PERSON_ID, $obj->getId()); $affectedRows += PersonRolePeer::doDelete($c, $con); // delete related PersonalNote objects $c = new Criteria(PersonalNotePeer::DATABASE_NAME); $c->add(PersonalNotePeer::PERSON_ID, $obj->getId()); $affectedRows += PersonalNotePeer::doDelete($c, $con); } return $affectedRows; }
/** * Shows password reset form where the token matches * @param sfWebRequest $request */ public function executeResetPassword(sfWebRequest $request) { $password_request = PasswordRequestPeer::getByToken($request->getParameter('token')); if ($password_request && $password_request->getEmail() == $request->getParameter('email') && $password_request->getCreatedAt('U') > time() - (int) sfConfig::get('app_password_request_lifetime')) { # token is valid if ($request->isMethod('post')) { # validate $password_len = strlen($request->getParameter('password')); $required_len = sfConfig::get('app_password_minimum_length'); if ($password_len > 0) { if ($password_len >= $required_len) { if ($request->getParameter('password') == $request->getParameter('confirm')) { $person = $password_request->getPerson(); $person->setPassword($request->getParameter('password')); $person->save(); $password_request->delete(); # all success $this->getUser()->setFlash('success', 'Your password has been successfully changed! Please use following form to login.'); $this->redirect('secure/login'); } else { $this->error_msg = 'Passwords don\'t match!'; } } else { $this->error_msg = 'Password must be at least ' . $required_len . ' characters'; } } else { $this->error_msg = 'Please type your password'; } } $form = new sfForm(); $this->csrf_tag = $form['_csrf_token']; $this->password_request = $password_request; } else { $this->getUser()->setFlash('warning', 'We didn\'t find any matching password request. Or your password request has been expired!'); $this->redirect('@homepage'); } }
/** * 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 = PasswordRequestPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setPersonId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setEmail($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setToken($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setCreatedAt($arr[$keys[4]]); } }