예제 #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
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Users is new, it will return
  * an empty collection; or if this Users has previously
  * been saved, it will retrieve related UserEquipements from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Users.
  */
 public function getUserEquipementsJoinUserBikes($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     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);
             $this->collUserEquipements = UserEquipementPeer::doSelectJoinUserBikes($criteria, $con, $join_behavior);
         }
     } else {
         // 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);
         if (!isset($this->lastUserEquipementCriteria) || !$this->lastUserEquipementCriteria->equals($criteria)) {
             $this->collUserEquipements = UserEquipementPeer::doSelectJoinUserBikes($criteria, $con, $join_behavior);
         }
     }
     $this->lastUserEquipementCriteria = $criteria;
     return $this->collUserEquipements;
 }
예제 #3
0
 /**
  * Selects a collection of UserStatEquip objects pre-filled with all related objects except UserStats.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of UserStatEquip objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptUserStats(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     foreach (sfMixer::getCallables('BaseUserStatEquipPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) {
         call_user_func($callable, 'BaseUserStatEquipPeer', $c, $con);
     }
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     // $c->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     UserStatEquipPeer::addSelectColumns($c);
     $startcol2 = UserStatEquipPeer::NUM_COLUMNS - UserStatEquipPeer::NUM_LAZY_LOAD_COLUMNS;
     UserEquipementPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (UserEquipementPeer::NUM_COLUMNS - UserEquipementPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(UserStatEquipPeer::USER_EQUIP_ID), array(UserEquipementPeer::EQUIPMENT_ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = UserStatEquipPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = UserStatEquipPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $omClass = UserStatEquipPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             UserStatEquipPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined UserEquipement rows
         $key2 = UserEquipementPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = UserEquipementPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = UserEquipementPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 UserEquipementPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (UserStatEquip) to the collection in $obj2 (UserEquipement)
             $obj2->addUserStatEquip($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
예제 #4
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = UserEquipementPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setUserId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setEquipmentId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDescription($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setBikeId($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setEquipFunction($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setPurchasePrice($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setPurchaseDate($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setMake($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setModel($arr[$keys[8]]);
     }
 }
예제 #5
0
 /**
  * Get the associated UserEquipement object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     UserEquipement The associated UserEquipement object.
  * @throws     PropelException
  */
 public function getUserEquipement(PropelPDO $con = null)
 {
     if ($this->aUserEquipement === null && $this->user_equip_id !== null) {
         $c = new Criteria(UserEquipementPeer::DATABASE_NAME);
         $c->add(UserEquipementPeer::EQUIPMENT_ID, $this->user_equip_id);
         $this->aUserEquipement = UserEquipementPeer::doSelectOne($c, $con);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aUserEquipement->addUserStatEquips($this);
         		 */
     }
     return $this->aUserEquipement;
 }
예제 #6
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;
 }
예제 #7
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;
 }
예제 #8
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;
     }
 }