protected function doClean($values)
 {
     if (is_null($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
     }
     $duration = $values['duration'];
     if (is_null($duration)) {
         return $values;
     }
     $date = $values['date'];
     if (is_null($date)) {
         return $values;
     }
     $date = strtotime($date);
     $activity = ActivityPeer::retrieveByPK($values['Activity_id']);
     $roomId = isset($values['Room_id']) ? $values['Room_id'] : null;
     $reservation_id = isset($values['id']) ? $values['id'] : null;
     if (!is_null($activity)) {
         if (!is_null($values['User_id'])) {
             $user = UserPeer::retrieveByPK($values['User_id']);
             $subscriptions = $user->getActiveSubscriptions($date, $activity->getId(), $roomId);
         } else {
             if (!is_null($values['Card_id'])) {
                 $card = CardPeer::retrieveByPK($values['Card_id']);
                 $subscriptions = $card->getActiveSubscriptions($date, $activity->getId(), $roomId);
             } else {
                 /* Trick to enforce potential new login objects (Like User or Card) to update this function */
                 /* This way, the validator will always throw. */
                 $subscriptions = null;
             }
         }
         $valid = false;
         $maxAvailableDuration = 0;
         if (!empty($subscriptions)) {
             foreach ($subscriptions as $subscription) {
                 $remainingCredit = $subscription->getRemainingCredit($duration, $reservation_id);
                 if ($remainingCredit >= 0) {
                     $valid = true;
                     break;
                 } else {
                     if ($maxAvailableDuration < abs($remainingCredit)) {
                         /* We keep the maximum duration number for the reservation */
                         $maxAvailableDuration = abs($remainingCredit);
                     }
                 }
             }
         }
         if (!$valid) {
             $error = new sfValidatorError($this, 'invalid', array('remaining_credit' => $maxAvailableDuration));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('duration' => $error));
         }
     }
     return $values;
 }
Beispiel #2
0
 public function executeDelete(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($card = CardPeer::retrieveByPk($request->getParameter('id')), sprintf('Object card does not exist (%s).', $request->getParameter('id')));
     $card->delete();
     $this->redirect('card/index');
 }
 protected function doClean($values)
 {
     if (is_null($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
     }
     $duration = $values['duration'];
     if (is_null($duration)) {
         return $values;
     }
     $date = $values['date'];
     if (is_null($date)) {
         return $values;
     }
     $date = strtotime($date);
     $activity = ActivityPeer::retrieveByPK($values['Activity_id']);
     $roomId = isset($values['Room_id']) ? $values['Room_id'] : null;
     $reservation_id = isset($values['id']) ? $values['id'] : null;
     if (!is_null($activity)) {
         if (!is_null($values['User_id'])) {
             $user = UserPeer::retrieveByPK($values['User_id']);
             $hours_per_week = $user->getHoursPerWeek($activity->getId(), $roomId);
             $total = $user->countMinutesPerWeek($activity->getId(), $roomId, $date, $reservation_id);
         } else {
             if (!is_null($values['Card_id'])) {
                 $card = CardPeer::retrieveByPK($values['Card_id']);
                 $hours_per_week = $card->getHoursPerWeek($activity->getId(), $roomId);
                 $total = $card->countMinutesPerWeek($activity->getId(), $roomId, $date, $reservation_id);
             } else {
                 /* Trick to enforce potential new login objects (Like User or Card) to update this function */
                 /* This way, the validator will always throw. */
                 $hours_per_week = null;
                 $total = null;
             }
         }
         if (empty($total)) {
             $total = 0;
         }
         if ($hours_per_week < 0 || is_null($hours_per_week)) {
             $error = new sfValidatorError($this, 'no_hours_per_week', array());
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('duration' => $error));
         }
         if ($total + $duration > $hours_per_week * 60) {
             $error = new sfValidatorError($this, 'invalid', array('minutes_per_week' => $hours_per_week * 60, 'total' => $total));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('duration' => $error));
         }
     }
     return $values;
 }
Beispiel #4
0
 public static function authenticate($card_number, $pincode)
 {
     $c = new Criteria();
     $c->add(CardPeer::CARD_NUMBER, $card_number, Criteria::EQUAL);
     $c->addAnd(CardPeer::PIN_CODE, $pincode, Criteria::EQUAL);
     $c->addAnd(CardPeer::IS_ACTIVE, true, Criteria::EQUAL);
     $c->addAnd(CardPeer::OWNER, null, Criteria::ISNOTNULL);
     $card = CardPeer::doSelectOne($c);
     if (!$card || !$card->isOwned()) {
         return null;
     }
     return $card;
 }
Beispiel #5
0
 public function executeCreate(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     if ($request->hasParameter('userId')) {
         $this->forward404Unless($this->user = UserPeer::retrieveByPk($request->getParameter('userId')), sprintf('Object user does not exist (%s).', $request->getParameter('userId')));
         $this->form = new SubscriptionForm();
         $this->processForm($request, $this->form);
         $this->form->setDefaultUser($this->user);
     } elseif ($request->hasParameter('cardId')) {
         $this->forward404Unless($this->card = CardPeer::retrieveByPk($request->getParameter('cardId')), sprintf('Object card does not exist (%s).', $request->getParameter('cardId')));
         $this->form = new SubscriptionForm();
         $this->processForm($request, $this->form);
         $this->form->setDefaultCard($this->card);
     } else {
         $this->forward404('No user or card specified.');
     }
     $this->setTemplate('new');
 }
Beispiel #6
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(CardPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(CardPeer::DATABASE_NAME);
         $criteria->add(CardPeer::ID, $pks, Criteria::IN);
         $objs = CardPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 protected function doClean($values)
 {
     if (is_null($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
     }
     $date = strtotime($values['date']);
     $now = time();
     if ($date < $now) {
         return $values;
     }
     $activity = ActivityPeer::retrieveByPK($values['Activity_id']);
     $roomId = isset($values['Room_id']) ? $values['Room_id'] : null;
     if (!is_null($activity)) {
         $overall_minimum_delay = $activity->getMinimumDelay();
         $overall_minimum_date = $activity->getMinimumDate($now);
         if (!is_null($values['User_id'])) {
             $user = UserPeer::retrieveByPK($values['User_id']);
             $minimum_delay = $user->getMinimumDelay($activity->getId(), $roomId);
             $minimum_date = $user->getMinimumDate($activity->getId(), $roomId, $now);
             $maximum_delay = $user->getMaximumDelay($activity->getId(), $roomId);
             $maximum_date = $user->getMaximumDate($activity->getId(), $roomId, $now);
             $has_subscription = $user->hasSubscription($activity->getId(), $roomId, $date);
         } else {
             if (!is_null($values['Card_id'])) {
                 $card = CardPeer::retrieveByPK($values['Card_id']);
                 $minimum_delay = $card->getMinimumDelay($activity->getId(), $roomId);
                 $minimum_date = $card->getMinimumDate($activity->getId(), $roomId, $now);
                 $maximum_delay = $card->getMaximumDelay($activity->getId(), $roomId);
                 $maximum_date = $card->getMaximumDate($activity->getId(), $roomId, $now);
                 $has_subscription = $card->hasSubscription($activity->getId(), $roomId, $date);
             } else {
                 /* Trick to enforce potential new login objects (Like User or Card) to update this function */
                 /* This way, the validator will always throw. */
                 $has_subscription = false;
                 $minimum_delay = null;
                 $maximum_delay = null;
             }
         }
         if (!$has_subscription) {
             $error = new sfValidatorError($this, 'no_subscription', array());
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('date' => $error));
         }
         if ($date < $overall_minimum_date) {
             $error = new sfValidatorError($this, 'minimum_delay', array('minimum_delay' => $overall_minimum_delay));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('date' => $error));
         }
         if ($maximum_delay < 0 || is_null($maximum_delay)) {
             $error = new sfValidatorError($this, 'no_delay', array());
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('date' => $error));
         }
         if ($date >= $maximum_date) {
             $error = new sfValidatorError($this, 'maximum_delay', array('maximum_delay' => $maximum_delay));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('date' => $error));
         }
     }
     return $values;
 }
 /**
  * Selects a collection of Subscription objects pre-filled with all related objects except Usergroup.
  *
  * @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 Subscription objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptUsergroup(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $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);
     }
     SubscriptionPeer::addSelectColumns($c);
     $startcol2 = SubscriptionPeer::NUM_COLUMNS - SubscriptionPeer::NUM_LAZY_LOAD_COLUMNS;
     ActivityPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (ActivityPeer::NUM_COLUMNS - ActivityPeer::NUM_LAZY_LOAD_COLUMNS);
     ZonePeer::addSelectColumns($c);
     $startcol4 = $startcol3 + (ZonePeer::NUM_COLUMNS - ZonePeer::NUM_LAZY_LOAD_COLUMNS);
     CardPeer::addSelectColumns($c);
     $startcol5 = $startcol4 + (CardPeer::NUM_COLUMNS - CardPeer::NUM_LAZY_LOAD_COLUMNS);
     UserPeer::addSelectColumns($c);
     $startcol6 = $startcol5 + (UserPeer::NUM_COLUMNS - UserPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(SubscriptionPeer::ACTIVITY_ID), array(ActivityPeer::ID), $join_behavior);
     $c->addJoin(array(SubscriptionPeer::ZONE_ID), array(ZonePeer::ID), $join_behavior);
     $c->addJoin(array(SubscriptionPeer::CARD_ID), array(CardPeer::ID), $join_behavior);
     $c->addJoin(array(SubscriptionPeer::USER_ID), array(UserPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = SubscriptionPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = SubscriptionPeer::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 = SubscriptionPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             SubscriptionPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Activity rows
         $key2 = ActivityPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = ActivityPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = ActivityPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 ActivityPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (Subscription) to the collection in $obj2 (Activity)
             $obj2->addSubscription($obj1);
         }
         // if joined row is not null
         // Add objects for joined Zone rows
         $key3 = ZonePeer::getPrimaryKeyHashFromRow($row, $startcol3);
         if ($key3 !== null) {
             $obj3 = ZonePeer::getInstanceFromPool($key3);
             if (!$obj3) {
                 $omClass = ZonePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj3 = new $cls();
                 $obj3->hydrate($row, $startcol3);
                 ZonePeer::addInstanceToPool($obj3, $key3);
             }
             // if $obj3 already loaded
             // Add the $obj1 (Subscription) to the collection in $obj3 (Zone)
             $obj3->addSubscription($obj1);
         }
         // if joined row is not null
         // Add objects for joined Card rows
         $key4 = CardPeer::getPrimaryKeyHashFromRow($row, $startcol4);
         if ($key4 !== null) {
             $obj4 = CardPeer::getInstanceFromPool($key4);
             if (!$obj4) {
                 $omClass = CardPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj4 = new $cls();
                 $obj4->hydrate($row, $startcol4);
                 CardPeer::addInstanceToPool($obj4, $key4);
             }
             // if $obj4 already loaded
             // Add the $obj1 (Subscription) to the collection in $obj4 (Card)
             $obj4->addSubscription($obj1);
         }
         // if joined row is not null
         // Add objects for joined User rows
         $key5 = UserPeer::getPrimaryKeyHashFromRow($row, $startcol5);
         if ($key5 !== null) {
             $obj5 = UserPeer::getInstanceFromPool($key5);
             if (!$obj5) {
                 $omClass = UserPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj5 = new $cls();
                 $obj5->hydrate($row, $startcol5);
                 UserPeer::addInstanceToPool($obj5, $key5);
             }
             // if $obj5 already loaded
             // Add the $obj1 (Subscription) to the collection in $obj5 (User)
             $obj5->addSubscription($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Beispiel #9
0
 /**
  * Get the associated Card object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Card The associated Card object.
  * @throws     PropelException
  */
 public function getCard(PropelPDO $con = null)
 {
     if ($this->aCard === null && $this->card_id !== null) {
         $c = new Criteria(CardPeer::DATABASE_NAME);
         $c->add(CardPeer::ID, $this->card_id);
         $this->aCard = CardPeer::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->aCard->addReservations($this);
         		 */
     }
     return $this->aCard;
 }
Beispiel #10
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 = CardPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setCardNumber($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setPinCode($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setIsActive($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setOwner($arr[$keys[4]]);
     }
 }
 protected function doClean($values)
 {
     if (is_null($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
     }
     $duration = $values['duration'];
     if (is_null($duration)) {
         return $values;
     }
     $activity = ActivityPeer::retrieveByPK($values['Activity_id']);
     $roomId = isset($values['Room_id']) ? $values['Room_id'] : null;
     $step = sfConfig::get('app_booking_step');
     if (is_null($step)) {
         throw new sfException('Cannot find `booking_step` configuration value.');
     }
     if (!is_null($activity)) {
         if (!is_null($values['User_id'])) {
             $user = UserPeer::retrieveByPK($values['User_id']);
             $minimum_duration = $user->getMinimumDuration($activity->getId(), $roomId);
             $maximum_duration = $user->getMaximumDuration($activity->getId(), $roomId);
         } else {
             if (!is_null($values['Card_id'])) {
                 $card = CardPeer::retrieveByPK($values['Card_id']);
                 $minimum_duration = $card->getMinimumDuration($activity->getId(), $roomId);
                 $maximum_duration = $card->getMaximumDuration($activity->getId(), $roomId);
             } else {
                 /* Trick to enforce potential new login objects (Like User or Card) to update this function */
                 /* This way, the validator will always throw. */
                 $minimum_duration = null;
                 $maximum_duration = null;
             }
         }
         if ($maximum_duration < 0 || is_null($maximum_duration)) {
             $error = new sfValidatorError($this, 'no_duration', array());
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('duration' => $error));
         }
         if (floor($duration / $step) * $step != $duration) {
             $error = new sfValidatorError($this, 'invalid_step', array('step' => $step));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('duration' => $error));
         }
         if ($duration < $minimum_duration) {
             $error = new sfValidatorError($this, 'invalid_min', array('minimum_duration' => $minimum_duration));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('duration' => $error));
         }
         if ($duration > $maximum_duration) {
             $error = new sfValidatorError($this, 'invalid_max', array('maximum_duration' => $maximum_duration));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array('duration' => $error));
         }
     }
     return $values;
 }
Beispiel #12
0
 /**
  * Returns the number of related Card objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Card objects.
  * @throws     PropelException
  */
 public function countCards(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(CarduserPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collCards === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(CardPeer::OWNER, $this->id);
             $count = CardPeer::doCount($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 count of the collection.
             $criteria->add(CardPeer::OWNER, $this->id);
             if (!isset($this->lastCardCriteria) || !$this->lastCardCriteria->equals($criteria)) {
                 $count = CardPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collCards);
             }
         } else {
             $count = count($this->collCards);
         }
     }
     return $count;
 }
Beispiel #13
0
 public function executePrepareCardLogin(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     if (!$this->getUser()->isAuthenticated()) {
         $card_number = $request->getParameter('card_number');
         $pincode = $request->getParameter('pincode');
         $card = CardPeer::authenticate($card_number, $pincode);
         if (!is_null($card)) {
             $this->getUser()->setTemposCard($card);
             $referer = $request->getParameter('referer');
             if (empty($referer)) {
                 $referer = 'home/index';
             }
             $this->redirect($referer);
         } else {
             $this->getUser()->setFlash('cardLoginError', true);
         }
     }
     $this->redirect('login/cardLogin');
 }