public static function getCountOfavailableSeats($rideId) { $ride = Rides::model()->find('id=:rideId', array(':rideId' => $rideId)); if ($ride) { $approved = RideUsers::model()->findAll('ride_id=:rideId AND status=:status', array(':rideId' => $rideId, ':status' => 'APPROVED')); $approvedCount = 0; if (!empty($approved)) { $approvedCount = count($approved); } $count = $ride->seats_available_to_book - $approvedCount; return $count; } else { return false; } }
/** * Declares an association between this object and a Rides object. * * @param Rides $v * @return UserRides The current object (for fluent API support) * @throws PropelException */ public function setRides(Rides $v = null) { if ($v === null) { $this->setRideId(NULL); } else { $this->setRideId($v->getRideKey()); } $this->aRides = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Rides object, it will not be re-added. if ($v !== null) { $v->addUserRides($this); } return $this; }
public static function searchRides($data) { $criteria = new CDbCriteria(); $condition = null; $params = null; /*$goingFromLat=getGoingFromName($fromLat); $goingFromLong=getGoingFromName($fromLong); $goingToLat=getGoingToName($toLat); $goingToLong=getGoingToName($toLong);*/ $goingFromLat = 11.0168445; $goingFromLong = 76.95583209999995; $fromLat1 = $goingFromLat - 0.01; $fromLat2 = $goingFromLat + 0.01; $fromLong1 = $goingFromLong - 0.01; $fromLong2 = $goingFromLong + 0.01; $goingToLat = 11.0168445; $goingToLong = 76.95583209999995; $toLat1 = $goingToLat - 0.01; $toLat2 = $goingToLat + 0.01; $toLong1 = $goingToLong - 0.01; $toLong2 = $goingToLong + 0.01; if ($data['GoingFrom'] != "") { $condition .= 'start_point_lat>=:fromLat1 AND start_point_lat<=:fromLat2 AND start_point_long>=:fromLong1 AND start_point_long<=:fromLong2'; $params[':fromLat1'] = $fromLat1; $params[':fromLat2'] = $fromLat2; $params[':fromLong1'] = $fromLong1; $params[':fromLong2'] = $fromLong2; } if ($data['GoingTo'] != "") { if ($condition != "") { $condition .= ' && '; } $condition .= 'end_point_lat>=:toLat1 AND end_point_lat<=:toLat2 AND end_point_long>=:toLong1 AND end_point_long<=:toLong2'; $params[':toLat1'] = $toLat1; $params[':toLat2'] = $toLat2; $params[':toLong1'] = $toLong1; $params[':toLong2'] = $toLong2; } if ($data['date'] != "") { if ($condition != "") { $condition .= ' && '; } $condition .= 'start_date=:date'; $params[':date'] = $data['date']; } else { if ($condition != "") { $condition .= ' && '; } $condition .= 'start_date>=:date'; $sdate = date("Y-m-d"); $params[':date'] = $sdate; } if ($data['time'] != "") { if ($condition != "") { $condition .= ' && '; } $condition .= 'start_time=:time'; $params[':time'] = $data['time']; } if ($data['age'] != "") { if ($condition != "") { $condition .= ' && '; } $condition .= 'age_group=:age'; $params[':age'] = $data['age']; } if ($condition != null) { $criteria->condition = $condition; $criteria->params = $params; } $rides = Rides::model()->findAll($criteria); return $rides; }
/** * 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 Rides $value A Rides object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Rides $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getRideKey(); } // if key === null self::$instances[$key] = $obj; } }