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');
     }
     if (is_null($values[$this->getOption('members_count_field')]) || is_null($values[$this->getOption('guests_count_field')])) {
         return $values;
     }
     $activity = ActivityPeer::retrieveByPK($values['Activity_id']);
     if (!is_null($activity)) {
         $needed_count = $activity->getMinimumOccupation() - 1;
         $granted_count = $activity->getMaximumOccupation() - 1;
         $people_count = $values[$this->getOption('members_count_field')] + $values[$this->getOption('guests_count_field')];
         if ($people_count < $needed_count) {
             $error = new sfValidatorError($this, 'people_missing', array('people_count' => $people_count, 'needed_count' => $needed_count));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array($this->getOption('members_count_field') => $error));
         }
         if ($people_count > $granted_count) {
             $error = new sfValidatorError($this, 'too_much_people', array('people_count' => $people_count, 'granted_count' => $granted_count));
             if ($this->getOption('throw_global_error')) {
                 throw $error;
             }
             throw new sfValidatorErrorSchema($this, array($this->getOption('members_count_field') => $error));
         }
     }
     return $values;
 }
 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;
 }
 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;
 }
 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;
 }
 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;
 }
Exemplo n.º 6
0
 public function getActivity(PropelPDO $con = null)
 {
     if ($this->aActivity === null && $this->activity_id !== null) {
         /* ActivityPeer::retrieveByPK is cached */
         $this->aActivity = ActivityPeer::retrieveByPK($this->activity_id, $con);
     }
     return $this->aActivity;
 }