Exemple #1
0
 private function validateForm($bookValues, &$bookErrors, \Application\BookingChange &$bookingData)
 {
     if (\Utility\Validator::IsFieldNotEmpty($bookValues, 'start')) {
         $bookingData->setStart($bookValues['start']);
     } else {
         $bookErrors['time'] = 'start time should be filled.';
         return;
     }
     if (\Utility\Validator::IsFieldNotEmpty($bookValues, 'end')) {
         $bookingData->setEnd($bookValues['end']);
     } else {
         $bookErrors['time'] = 'end time should be filled.';
         return;
     }
     if (!$bookingData->isTimeValid()) {
         $bookErrors['time'] = $bookingData->getErrorMessage();
     }
     if (\Utility\Validator::IsFieldNotEmpty($bookValues, 'notes')) {
         $bookingData->setNotes($bookValues['notes']);
     } else {
         $bookErrors['notes'] = 'notes should be filled.';
     }
     $bookingData->setEmpId($bookValues['employee']);
     $bookingData->setApplyChain($bookValues['apply_chain_proxy'] == 1);
 }
Exemple #2
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.';
         }
     }
 }
 /**
  * @return array
  */
 protected function defineErrorMessages()
 {
     return array_merge(parent::defineErrorMessages(), array(self::ERROR_INVALID => 'Value should have a minimum length of: %min_length%'));
 }
 /**
  * @return array
  */
 protected function defineErrorMessages()
 {
     return array_merge(parent::defineErrorMessages(), array(self::ERROR_INVALID => 'Value should be an integer'));
 }