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); }
//$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
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; } }
/** * 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; }
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(); } } } }