/**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      UserRideMap $value A UserRideMap object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(UserRideMap $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getUserRideId(), (string) $obj->getCoordOrder()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Example #2
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();
             }
         }
     }
 }