/**
  * @param BookingSchedule                $value
  * @param ProviderAvailabilityConstraint $constraint
  * @throws Exception
  */
 public function validate($value, Constraint $constraint)
 {
     foreach ($value->getPlace()->getBusinessHours() as $bh) {
         if ($bh->getId() == $value->getId()) {
             continue;
         }
         foreach (DayFlaggableHelper::getWeekdays() as $day) {
             $method = 'getDay' . $day;
             if ($value->{$method}() && $bh->{$method}()) {
                 if ($value->getStartsAt() >= $bh->getStartsAt() && $bh->getEndsAt() >= $value->getStartsAt()) {
                     $this->context->buildViolation($constraint->openAtMessage)->setParameter('%openAt%', $value->getStartsAt()->format('H:i:s'))->setParameter('%startsAt%', $bh->getStartsAt()->format('H:i:s'))->setParameter('%endsAt%', $bh->getEndsAt()->format('H:i:s'))->setParameter('%day%', $day)->atPath('startsAt')->addViolation();
                     break;
                 }
                 if ($value->getEndsAt() >= $bh->getStartsAt() && $bh->getEndsAt() >= $value->getEndsAt()) {
                     $this->context->buildViolation($constraint->closeAtMessage)->setParameter('%closeAt%', $value->getEndsAt()->format('H:i:s'))->setParameter('%startsAt%', $bh->getStartsAt()->format('H:i:s'))->setParameter('%endsAt%', $bh->getEndsAt()->format('H:i:s'))->setParameter('%day%', $day)->atPath('endsAt')->addViolation();
                     break;
                 }
             }
         }
     }
     //        return;
     //        //die();
     //        var_dump('business hours validator' . $value->getId()) . '-';return;
     //        if (!$value instanceof Booking) {
     //            throw new Exception('bad entity');
     //        }
     //        $start = $value->getStartsAt();
     //        $end   = $value->getEndsAt();
     //        if ($start >= $end) {
     //            $this->context->addViolationAt('endsAt', $constraint->endsMessage);
     //        }
     //        if($value->getChangedHours() >= $value->getInitialHours() && $value->getChangedHoursReason()){
     //            $this->context->addViolationAt('changedHourseReason', $constraint->deniedChangedHoursReasonMessage);
     //        }
     //        // new booking rules
     //        if (!$value->getId()){
     //            if($start < new \DateTime()) {
     //                $this->context->addViolationAt('startsAt', $constraint->dateOldMessage);
     //            }
     //            $h = Constants::BOOKING_MIN_HOURS_IN_ADVANCE;
     //            if($start < new \DateTime(sprintf('+%d hours', $h))){
     //                $this->context->addViolationAt('startsAt', $constraint->dateMinHoursInAdvance, ['%hours%' => $h]);
     //            }
     //            if ($book = $this->validateProvider($value)) {
     //                $this->context->addViolation(
     //                    $constraint->busyMessage,
     //                    [
     //                        '%provider%' => $value->getProvider(),
     //                        '%from%' => $book->getStartsAt()->format('d M Y H:i'),
     //                        '%to%' =>   $book->getEndsAt()->format('d M Y H:i')
     //                    ]
     //                );
     //            }
     //        }
 }
Exemple #2
0
 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     DayFlaggableHelper::buildFields($builder);
     //        $builder
     //            ->add('dayMonday', null, array('required' => false))
     //            ->add('dayTuesday', null, array('required' => false))
     //            ->add('dayWednesday', null, array('required' => false))
     //            ->add('dayThursday', null, array('required' => false))
     //            ->add('dayFriday', null, array('required' => false))
     //            ->add('daySaturday', null, array('required' => false))
     //            ->add('daySunday', null, array('required' => false))
     //        ;
     $builder->add('startsAt', 'clock_picker', array('required' => true))->add('endsAt', 'clock_picker', array('required' => true));
 }
Exemple #3
0
 public function __construct()
 {
     DayFlaggableHelper::fillFields($this, false);
     //$this->setStartsAt(new \DateTime());
 }
 protected function divideBusinessHours($entity)
 {
     //var_dump($entity->getPlace());die();
     $today = new \DateTime();
     if ($entity->getStartsAt()->format('H:i:s') > $entity->getEndsAt()->format('H:i:s')) {
         //var_dump($entity->getPlace(). 'dddd');die();
         $endsAt = $entity->getEndsAt();
         $entity->setEndsAt($today::createFromFormat('H:i:s', '23:59:59'));
         $bh = new BusinessHours();
         DayFlaggableHelper::fillFields($bh, false);
         $pa = PropertyAccess::createPropertyAccessor();
         foreach (DayFlaggableHelper::getWeekdays() as $key => $label) {
             if ($pa->getValue($entity, 'day' . ucwords($key)) == true) {
                 $nextDay = DayFlaggableHelper::nextDay($key);
                 $pa->setValue($bh, 'day' . ucwords($nextDay), true);
             }
         }
         //var_dump($entity->getPlace());
         $bh->setPlace($entity->getPlace());
         $bh->setStartsAt($today::createFromFormat('H:i:s', '00:00:00'));
         $bh->setEndsAt($endsAt);
         $this->entities[] = $bh;
     }
 }
 protected function getClosestOpenHours($place)
 {
     $now = new \DateTime();
     $day = $now->format('l');
     $dayOpenMin = new \DateTime('+10 years');
     //Dummy
     foreach ($place->getBusinessHours() as $bh) {
         $endsAt = $bh->getEndsAt();
         $startsAt = $bh->getStartsAt();
         for ($i = 1; $i <= 7; $i++) {
             $method = 'getDay' . ucfirst($day);
             $dayOpen = new \Datetime($day);
             $dayOpen->setTime($startsAt->format('H'), $startsAt->format('i'), $startsAt->format('s'));
             if ($bh->{$method}() && $dayOpen > $now) {
                 //Looking for soonest open hours
                 if ($dayOpen < $dayOpenMin) {
                     $dayOpenMin = $dayOpen;
                 }
             }
             $day = DayFlaggableHelper::nextDay($day);
         }
     }
     return $dayOpenMin;
 }