Пример #1
0
 /**
  * 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      UserStatEquip $value A UserStatEquip object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(UserStatEquip $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getUserStatEquipId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Пример #2
0
 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;
 }