Пример #1
0
 public function executeDelete()
 {
     $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber');
     $this->bikeid = $this->getRequestParameter('bikeid');
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         //delete user_stat and equipment
         $c = new Criteria();
         $c->add(UserStatsPeer::USER_ID, $userId);
         $c->add(UserStatsPeer::BIKE_ID, $this->bikeid);
         $s = UserStatsPeer::doSelectJoinAll($c);
         foreach ($s as $stat) {
             foreach ($stat->getUserStatEquips() as $equip) {
                 $equip->delete();
             }
             $stat->delete();
         }
         //move equipment to shelf
         $c = new Criteria();
         $c->add(UserEquipementPeer::USER_ID, $userId);
         $c->add(UserEquipementPeer::BIKE_ID, $this->bikeid);
         $equip = UserEquipementPeer::doSelect($c);
         foreach ($equip as $e) {
             $e->setBikeId(null);
             $e->save();
         }
         //now delete bike
         $user_bikes = UserBikesPeer::retrieveByPk($this->bikeid);
         $user_bikes->delete();
         return $this->redirect('userbike/index');
     }
 }
Пример #2
0
 /**
  * Gets an array of UserEquipement objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this Users has previously been saved, it will retrieve
  * related UserEquipements from storage. If this Users is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array UserEquipement[]
  * @throws     PropelException
  */
 public function getUserEquipements($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(UsersPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collUserEquipements === null) {
         if ($this->isNew()) {
             $this->collUserEquipements = array();
         } else {
             $criteria->add(UserEquipementPeer::USER_ID, $this->user_id);
             UserEquipementPeer::addSelectColumns($criteria);
             $this->collUserEquipements = UserEquipementPeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // 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(UserEquipementPeer::USER_ID, $this->user_id);
             UserEquipementPeer::addSelectColumns($criteria);
             if (!isset($this->lastUserEquipementCriteria) || !$this->lastUserEquipementCriteria->equals($criteria)) {
                 $this->collUserEquipements = UserEquipementPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastUserEquipementCriteria = $criteria;
     return $this->collUserEquipements;
 }
Пример #3
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(UserEquipementPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(UserEquipementPeer::DATABASE_NAME);
         $criteria->add(UserEquipementPeer::EQUIPMENT_ID, $pks, Criteria::IN);
         $objs = UserEquipementPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Пример #4
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;
 }
Пример #5
0
 public function executeGetBikeEquipment($request)
 {
     $this->forward404unless($request->isXmlHttpRequest());
     //get bikeId
     $bikeId = intval($request->getParameter("param"));
     //get userId
     $userId = sfContext::getInstance()->getUser()->getAttribute('subscriber_id', null, 'subscriber');
     if ($userId && $bikeId) {
         $c = new Criteria();
         $c->add(UserEquipementPeer::BIKE_ID, $bikeId);
         $c->add(UserEquipementPeer::USER_ID, $userId);
         $this->equips = UserEquipementPeer::doSelect($c);
         //now get the mileage for each equipment
         $mileage = UserEquipement::getEquipmentMileage($userId, $bikeId);
         //now set mileage on equipment
         if ($mileage && $this->equips) {
             foreach ($this->equips as $userEquip) {
                 //if(in_array($userEquip->getEquipmentId(),$mileage)){
                 if (isset($mileage[$userEquip->getEquipmentId()])) {
                     //        echo 'found';
                     $userEquip->setMileage(utils::getMileageFromMeters($mileage[$userEquip->getEquipmentId()]));
                 } else {
                     //          echo $userEquip->getEquipmentId();
                     $userEquip->setMileage(0);
                 }
             }
         }
     } else {
         $this->equips = null;
     }
 }