Exemplo n.º 1
0
 private function validateForm($bookValues, &$bookErrors, \Application\BookingOrder &$bookingOrder, $hour_mode)
 {
     if (\Utility\Validator::IsFieldNotEmpty($bookValues, 'employee')) {
         $bookingOrder->setEmpId($bookValues['employee']);
     } else {
         $bookErrors['employee'] = 'employee should be filled.';
     }
     if (\Utility\Validator::IsDateValid($bookValues['start-year'], $bookValues['start-month'], $bookValues['start-day'])) {
         $bookingOrder->setDate($bookValues['start-year'], $bookValues['start-month'], $bookValues['start-day']);
     } else {
         $bookErrors['start-date'] = 'date invalid';
         return;
     }
     //error_log("\ndate set:" . print_r($bookingOrder, true), 3, 'my_errors.txt');
     if ($hour_mode == \Application\EmpItem::MODE_DAY_12) {
         $bookingOrder->setStartTime12($bookValues['start-hour-12'], $bookValues['start-minute'], $bookValues['start-meridiem']);
         $bookingOrder->setEndTime12($bookValues['end-hour-12'], $bookValues['end-minute'], $bookValues['end-meridiem']);
     } else {
         $bookingOrder->setStartTime24($bookValues['start-hour-24'], $bookValues['start-minute']);
         $bookingOrder->setEndTime24($bookValues['end-hour-24'], $bookValues['end-minute']);
     }
     //error_log("\ntime set:" . print_r($bookingOrder, true), 3, 'my_errors.txt');
     //error_log("\nstart-date:" . print_r($bookingData['start-date']->getTimestamp(), true), 3, 'my_errors.txt');
     if (!$bookingOrder->isTimeValid()) {
         $bookErrors['time'] = $bookingOrder->getErrorMessage();
     }
     // нельзя назначить на прошлый период
     if ($bookingOrder->isPeriodBeforeTime(new \DateTime())) {
         $bookErrors['common'] = 'you cannot book for passed time';
     }
     if (\Utility\Validator::IsFieldNotEmpty($bookValues, 'notes')) {
         $bookingOrder->setNotes($bookValues['notes']);
     } else {
         $bookErrors['notes'] = 'notes should be filled.';
     }
     if ($bookValues['recurring'] == 1) {
         $bookingOrder->setRecurring(\Application\BookingOrder::NOT_RECURRING);
     } else {
         if (\Utility\Validator::IsFieldNotEmpty($bookValues, 'duration') && is_numeric($bookValues['duration'])) {
             $cases = array(1 => BookingOrder::RECURRING_WEEKLY, 2 => BookingOrder::RECURRING_BI_WEEKLY, 3 => BookingOrder::RECURRING_MONTHLY);
             $bookingOrder->setRecurring($cases[$bookValues['recurring-period']], $bookValues['duration']);
             $bookValues['duration'] = $bookingOrder->getDuration();
         } else {
             $bookErrors['duration'] = 'duration should be filled with numeric value.';
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Returns new Appointments chain according to bookingData, user entered
  * @param array $bookingData
  * @param $creatorId
  * @param $roomId
  * @return AppointmentChain
  */
 public function makeChain(\Application\BookingOrder $bookingOrder, $creatorId, $roomId)
 {
     $result = new AppointmentChain();
     if ($bookingOrder->isRecurring()) {
         $event_dates = $this->makeDatesChain($bookingOrder->getStartTime(), $bookingOrder->getRecurring(), $bookingOrder->getDuration());
     } else {
         $event_dates = array($bookingOrder->getStartTime());
     }
     $event_duration = $bookingOrder->getEndTime()->getTimestamp() - $bookingOrder->getStartTime()->getTimestamp();
     foreach ($event_dates as $event_date) {
         $appItem = new \Application\AppointmentItem(array('emp_id' => $bookingOrder->getEmpId(), 'notes' => $bookingOrder->getNotes(), 'creator_id' => $creatorId, 'room_id' => $roomId));
         $appItem->setTimeStart($event_date);
         $appItem->setTimeEnd((new \DateTime())->setTimestamp($event_date->getTimestamp() + $event_duration));
         $result->add($appItem);
     }
     return $result;
 }