Пример #1
0
 public function configure()
 {
     //get profile object
     $user = $this->getObject();
     if (!$user->getUserProfile()) {
         $profile = UserProfilePeer::retrieveByPK($user->getUserId());
         if (!$profile) {
             $profile = new UserProfile();
             $profile->setUserId($user->getUserId());
         }
         $user->setUserProfile($profile);
     }
     // build state criteria
     // echo $profile->getCountry().'&';
     $stateC = new Criteria();
     $stateC->add(CpStatesPeer::COUNTRY_ID, $user->getUserProfile()->getCountry());
     // build city criteria
     $cityC = new Criteria();
     $cityC->add(CpCitiesPeer::STATE_ID, $user->getUserProfile()->getState());
     $this->setWidgets(array('country_id' => new sfWidgetFormPropelSelect(array('model' => 'CpCountries', 'add_empty' => '-- Country --', 'order_by' => array('Name', 'asc'))), 'state_id' => new sfWidgetFormPropelSelect(array('model' => 'CpStates', 'add_empty' => '-- State/Province --', 'order_by' => array('Name', 'asc'), 'criteria' => $stateC)), 'city_id' => new sfWidgetFormPropelSelect(array('model' => 'CpCities', 'add_empty' => '-- City --', 'order_by' => array('Name', 'asc'), 'criteria' => $cityC)), 'id' => new sfWidgetFormInputHidden()));
     $this->setValidators(array('country_id' => new sfValidatorPropelChoice(array('model' => 'CpCountries', 'column' => 'id'), array('required' => '- Please choose country', 'invalid' => '- Invalid country')), 'state_id' => new sfValidatorPropelChoice(array('model' => 'CpStates', 'column' => 'id', 'criteria' => clone $stateC), array('required' => '- Please choose state', 'invalid' => '- Invalid state')), 'city_id' => new sfValidatorPropelChoice(array('model' => 'CpCities', 'column' => 'id', 'criteria' => clone $cityC), array('required' => '- Please choose city', 'invalid' => '- Invalid city')), 'id' => new sfValidatorNumber(array('required' => false))));
     //$this->widgetSchema->setLabels(array(
     //	'name'	=> 'Name',
     //));
     $this->widgetSchema->setNameFormat('user[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
 }
Пример #2
0
 public function executePassword()
 {
     if ($this->getRequest()->getMethod() != sfRequest::POST) {
         return sfView::SUCCESS;
     }
     $email = $this->getRequestParameter('email');
     $c = new Criteria();
     $c->add(UserProfilePeer::EMAIL, $email);
     $profile = UserProfilePeer::doSelectOne($c);
     if (!$profile) {
         $this->getRequest()->setError('email', 'There is no user with this email.');
         return sfView::SUCCESS;
     }
     $sfGuardUser = $profile->getSfGuardUser();
     $password = substr(md5(rand(100000, 999999)), 0, 6);
     $sfGuardUser->setPassword($password);
     $this->getRequest()->setAttribute('full_name', $profile->getFullName());
     $this->getRequest()->setAttribute('email', $email);
     $this->getRequest()->setAttribute('username', $sfGuardUser->getUsername());
     $this->getRequest()->setAttribute('password', $password);
     $this->sendEmail('mail', 'forgotPassword');
     $sfGuardUser->save();
     $this->setFlash('info', 'A new password is sent to your email.');
     $this->forward('site', 'message');
 }
//$exampleGen->displayHead( 'Example' );
include 'include/common.php';
// EXAMPLE START ------------------------------------------------------
/**
 * main patForms class
 */
require_once 'patForms.php';
/**
 * patErrorManager class
 */
require_once 'patErrorManager.php';
// create the creator :)
$creator =& patForms::createCreator('Propel');
// create the form object from the given propel Object class instance
require_once 'model/general/UserProfile.php';
$userProfile = UserProfilePeer::retrieveByPK(1);
$form =& $creator->create($userProfile);
//$wikipage = WikipagePeer::retrieveByPK('wiki');
//$form =& $creator->create($wikipage);
// create the needed renderer
$renderer =& patForms::createRenderer("Array");
// set the renderer
$form->setRenderer($renderer);
// use auto-validation
$form->setAutoValidate('save');
// serialize the elements
$elements = $form->renderForm();
// ERROR DISPLAY ------------------------------------------------------
if ($form->isSubmitted()) {
    displayErrors($form);
    // see patExampleGen/customFunctions.php
Пример #4
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this CpCities is new, it will return
  * an empty collection; or if this CpCities has previously
  * been saved, it will retrieve related UserProfiles 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 CpCities.
  */
 public function getUserProfilesJoinCpStates($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(CpCitiesPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collUserProfiles === null) {
         if ($this->isNew()) {
             $this->collUserProfiles = array();
         } else {
             $criteria->add(UserProfilePeer::CITY, $this->id);
             $this->collUserProfiles = UserProfilePeer::doSelectJoinCpStates($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(UserProfilePeer::CITY, $this->id);
         if (!isset($this->lastUserProfileCriteria) || !$this->lastUserProfileCriteria->equals($criteria)) {
             $this->collUserProfiles = UserProfilePeer::doSelectJoinCpStates($criteria, $con, $join_behavior);
         }
     }
     $this->lastUserProfileCriteria = $criteria;
     return $this->collUserProfiles;
 }
Пример #5
0
 /**
  * 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 = UserProfilePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setUserId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setBirthdate($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setCountry($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setState($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setCity($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setZip($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setMiles($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setWeight($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setHeight($arr[$keys[8]]);
     }
 }
Пример #6
0
 /**
  * Gets a single UserProfile object, which is related to this object by a one-to-one relationship.
  *
  * @param      PropelPDO $con
  * @return     UserProfile
  * @throws     PropelException
  */
 public function getUserProfile(PropelPDO $con = null)
 {
     if ($this->singleUserProfile === null && !$this->isNew()) {
         $this->singleUserProfile = UserProfilePeer::retrieveByPK($this->user_id, $con);
     }
     return $this->singleUserProfile;
 }
Пример #7
0
 public function executeGetCities()
 {
     $stateId = $this->getRequestParameter('state');
     $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber');
     $profile = UserProfilePeer::retrieveByPK($userId);
     if ($profile && $profile->getCity()) {
         $this->currentCity = $profile->getCity();
     } else {
         $this->currentCity = -1;
     }
     if ($stateId) {
         $this->cities = CpCitiesPeer::getAllCitiesByState($stateId);
     } else {
         $this->cities = null;
     }
 }
Пример #8
0
 /**
  * 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 = sfGuardUserPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related NotaPedido objects
         $c = new Criteria(NotaPedidoPeer::DATABASE_NAME);
         $c->add(NotaPedidoPeer::ADMINISTRA_ID, $obj->getId());
         $affectedRows += NotaPedidoPeer::doDelete($c, $con);
         // delete related NotaPedido objects
         $c = new Criteria(NotaPedidoPeer::DATABASE_NAME);
         $c->add(NotaPedidoPeer::SOLICITA_ID, $obj->getId());
         $affectedRows += NotaPedidoPeer::doDelete($c, $con);
         // delete related NotaPedido objects
         $c = new Criteria(NotaPedidoPeer::DATABASE_NAME);
         $c->add(NotaPedidoPeer::CONTROLA_ID, $obj->getId());
         $affectedRows += NotaPedidoPeer::doDelete($c, $con);
         // delete related NotaPedido objects
         $c = new Criteria(NotaPedidoPeer::DATABASE_NAME);
         $c->add(NotaPedidoPeer::AUTORIZA_ID, $obj->getId());
         $affectedRows += NotaPedidoPeer::doDelete($c, $con);
         // delete related NotaPedidoEstado objects
         $c = new Criteria(NotaPedidoEstadoPeer::DATABASE_NAME);
         $c->add(NotaPedidoEstadoPeer::USER_ID, $obj->getId());
         $affectedRows += NotaPedidoEstadoPeer::doDelete($c, $con);
         // delete related Evento objects
         $c = new Criteria(EventoPeer::DATABASE_NAME);
         $c->add(EventoPeer::USER_ID, $obj->getId());
         $affectedRows += EventoPeer::doDelete($c, $con);
         // delete related CompraEstado objects
         $c = new Criteria(CompraEstadoPeer::DATABASE_NAME);
         $c->add(CompraEstadoPeer::USER_ID, $obj->getId());
         $affectedRows += CompraEstadoPeer::doDelete($c, $con);
         // delete related Venta objects
         $c = new Criteria(VentaPeer::DATABASE_NAME);
         $c->add(VentaPeer::TRANSPORTISTA_INTERNO_ID, $obj->getId());
         $affectedRows += VentaPeer::doDelete($c, $con);
         // delete related VentaEstado objects
         $c = new Criteria(VentaEstadoPeer::DATABASE_NAME);
         $c->add(VentaEstadoPeer::USER_ID, $obj->getId());
         $affectedRows += VentaEstadoPeer::doDelete($c, $con);
         // delete related sfGuardUserPermission objects
         $c = new Criteria(sfGuardUserPermissionPeer::DATABASE_NAME);
         $c->add(sfGuardUserPermissionPeer::USER_ID, $obj->getId());
         $affectedRows += sfGuardUserPermissionPeer::doDelete($c, $con);
         // delete related sfGuardUserGroup objects
         $c = new Criteria(sfGuardUserGroupPeer::DATABASE_NAME);
         $c->add(sfGuardUserGroupPeer::USER_ID, $obj->getId());
         $affectedRows += sfGuardUserGroupPeer::doDelete($c, $con);
         // delete related sfGuardRememberKey objects
         $c = new Criteria(sfGuardRememberKeyPeer::DATABASE_NAME);
         $c->add(sfGuardRememberKeyPeer::USER_ID, $obj->getId());
         $affectedRows += sfGuardRememberKeyPeer::doDelete($c, $con);
         // delete related RecepcionPedido objects
         $c = new Criteria(RecepcionPedidoPeer::DATABASE_NAME);
         $c->add(RecepcionPedidoPeer::RECIBE_ID, $obj->getId());
         $affectedRows += RecepcionPedidoPeer::doDelete($c, $con);
         // delete related RecepcionPedido objects
         $c = new Criteria(RecepcionPedidoPeer::DATABASE_NAME);
         $c->add(RecepcionPedidoPeer::CONTROLA_ID, $obj->getId());
         $affectedRows += RecepcionPedidoPeer::doDelete($c, $con);
         // delete related RecepcionPedido objects
         $c = new Criteria(RecepcionPedidoPeer::DATABASE_NAME);
         $c->add(RecepcionPedidoPeer::ADMINISTRA_ID, $obj->getId());
         $affectedRows += RecepcionPedidoPeer::doDelete($c, $con);
         // delete related UserProfile objects
         $c = new Criteria(UserProfilePeer::DATABASE_NAME);
         $c->add(UserProfilePeer::USER_ID, $obj->getId());
         $affectedRows += UserProfilePeer::doDelete($c, $con);
     }
     return $affectedRows;
 }
Пример #9
0
 /**
  * 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(UserProfilePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(UserProfilePeer::DATABASE_NAME);
         $criteria->add(UserProfilePeer::USER_ID, $pks, Criteria::IN);
         $objs = UserProfilePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 protected function createUserAndProfile($username, $con = null)
 {
     // no user with this username
     if (null === $con) {
         $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME);
     }
     try {
         $con->begin();
         // create a new user object
         $user = new sfGuardUser();
         $user->setUsername($username);
         $user->setIsActive(1);
         $user->setAlgorithm('');
         $user->save($con);
         // do we have a profile in the system with this net_id?
         // this could happen if the profile was added manually by an admin
         $userProfile = UserProfilePeer::selectByNetIdWithNoUserId($username);
         if ($userProfile) {
             // there is already a dangling user profile with this net id, link the user with the profile
             $userProfile->setUserId($user->getId());
             $userProfile->save($con);
         } else {
             // make a new user profile
             $userProfile = new UserProfile();
             $userProfile->setUserId($user->getId());
             $userProfile->setNetId($user->getUsername());
             $userProfile->save($con);
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
     return $user;
 }
Пример #11
0
 public static function retrieveByConfirmation($key)
 {
     $c = new Criteria();
     $c->add(UserProfilePeer::CONFIRMATION, $key);
     return UserProfilePeer::doSelectOne($c);
 }
Пример #12
0
 public function executeMap()
 {
     $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber');
     $this->mileagePref = sfContext::getInstance()->getUser()->getAttribute('mileage', null, 'subscriber');
     $mapMileage = $this->getRequestParameter('mapMileage');
     $this->totalMileage = 0;
     $this->elevationChart = null;
     //
     //get profile to get mileage preference
     $this->lat = 37.4419;
     $this->long = -122.1419;
     $profile = UserProfilePeer::retrieveByPK($userId);
     if ($profile) {
         $cpCity = $profile->getLatLong();
         if ($cpCity) {
             $this->lat = $cpCity->getLatitude();
             $this->long = $cpCity->getLongitude();
         }
     }
     $this->rideId = $this->getRequestParameter('rideId');
     sfContext::getInstance()->getLogger()->info('@@@@@@@@@@@@@@@rideId ' . $this->rideId);
     $this->coords = null;
     $ride = UserRidesPeer::retrieveByPK($this->rideId);
     $mapPoints = null;
     $this->rideName = "";
     if ($ride) {
         $this->rideName = $ride->getDescription();
         //see if there are any coords
         $c = new Criteria();
         $c->add(UserRideMapPeer::USER_RIDE_ID, $this->rideId);
         $mapPoints = UserRideMapPeer::doSelect($c);
         $this->coords = UserRideMap::createMapString($mapPoints);
     }
     if ($this->getRequest()->getMethod() == sfRequest::POST && $ride) {
         //need to see if we have existing route, if so then we will just delete and recreate
         if ($mapPoints) {
             foreach ($mapPoints as $mp) {
                 $mp->delete();
             }
         }
         $coordinates = $this->getRequestParameter('coords');
         sfContext::getInstance()->getLogger()->info('@@@@@@@@@@@@@@@coords ' . $coordinates);
         if ($coordinates) {
             $coordArray = explode('*', $coordinates);
             $count = 0;
             $mapPoints = array();
             foreach ($coordArray as $c) {
                 $latLng = explode(',', $c);
                 if ($latLng && count($latLng) == 2) {
                     $map = new UserRideMap();
                     $map->setUserRideId($this->rideId);
                     $map->setCoordOrder($count++);
                     $map->setLat($latLng[0]);
                     $map->setLong($latLng[1]);
                     //	$map->setElevation($this->lookupElevation($latLng[0], $latLng[1]));
                     sfContext::getInstance()->getLogger()->info('lat' . $latLng[0]);
                     sfContext::getInstance()->getLogger()->info('lng' . $latLng[1]);
                     $map->save();
                     array_push($mapPoints, $map);
                 }
             }
         }
         $this->coords = UserRideMap::createMapString($mapPoints);
         //need to save new mileage if overriden
         if ($mapMileage && $mapMileage == 1) {
             $meterMile = $this->getRequestParameter('totalMileage');
             if ($meterMile) {
                 sfContext::getInstance()->getLogger()->info('Overriding Map Mileage with' . $mapMileage);
                 $ride->setMileage($meterMile);
                 $ride->save();
             }
         }
     }
 }
Пример #13
0
 public function executeConfirmation()
 {
     $key = $this->getRequestParameter('key');
     if ($key) {
         $user_profile = UserProfilePeer::retrieveByConfirmation($key);
         if ($user_profile) {
             $user = sfGuardUserPeer::retrieveByPK($user_profile->getUserId());
             $user->setIsActive(true);
             $user->save();
             $this->setFlash('info', 'Your account has been activated.');
             $this->forward('site', 'message');
         }
     }
     $this->setFlash('error', 'Activation link is not valid.');
     $this->forward('site', 'message');
 }