public function executeAdd() { $this->userStat = new UserStats(); $this->bikes = null; $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber'); if ($this->getRequest()->getMethod() == sfRequest::POST) { if ($userId) { $rideId = $this->getRequestParameter('user_ride_id'); $ride = UserRidesPeer::retrieveByPK($rideId); $this->userStat->setRideDate(join("/", $this->getRequestParameter('ride_date'))); $this->userStat->setBikeId($this->getRequestParameter('user_bike_id')); $this->userStat->setRideKey($rideId); $this->userStat->setRideTime($this->getRequestParameter('ride_time')); $this->userStat->setAvgSpeed($this->getRequestParameter('avg_speed')); $this->userStat->setCaloriesBurned($this->getRequestParameter('cal_burned')); $this->userStat->setUserId($userId); $this->userStat->setMileage($ride->getMileage()); $this->userStat->save(); //now need to add the user equipment for the ride $c = new Criteria(); $c->add(UserEquipementPeer::BIKE_ID, $this->userStat->getBikeId()); $c->add(UserEquipementPeer::USER_ID, $this->userStat->getUserId()); $equip = UserEquipementPeer::doSelect($c); foreach ($equip as $userEquip) { $userStatEquip = new UserStatEquip(); $userStatEquip->setUserStatId($this->userStat->getStatNo()); $userStatEquip->setUserEquipId($userEquip->getEquipmentId()); $userStatEquip->save(); } return $this->redirect('userstats/index'); } } return sfView::SUCCESS; }
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(); } } } }