public function executeStaffScheduleHandleBreak()
 {
     $start_time = $this->getParameter('start_time');
     $end_time = $this->getParameter('end_time');
     $working_start = $this->getParameter('working_start');
     $working_end = $this->getParameter('working_end');
     if (strtotime(date('Y-m-d ' . $start_time)) >= strtotime(date('Y-m-d ' . $end_time))) {
         echo json_encode(array('success' => false, 'error_msg' => __('The start time must be less than the end one', 'ab')));
         exit;
     }
     $staffScheduleItem = new AB_StaffScheduleItem();
     $staffScheduleItem->load($this->getParameter('staff_schedule_item_id'));
     $break_id = $this->getParameter('break_id', 0);
     $in_working_time = $working_start <= $start_time && $start_time <= $working_end && $working_start <= $end_time && $end_time <= $working_end;
     if (!$in_working_time || !$staffScheduleItem->isBreakIntervalAvailable($start_time, $end_time, $break_id)) {
         echo json_encode(array('success' => false, 'error_msg' => __('The requested interval is not available', 'ab')));
         exit;
     }
     $time_format = get_option('time_format');
     $formatted_interval_start = date_i18n($time_format, strtotime($start_time));
     $formatted_interval_end = date_i18n($time_format, strtotime($end_time));
     $formatted_interval = $formatted_interval_start . ' - ' . $formatted_interval_end;
     if ($break_id) {
         $break = new AB_ScheduleItemBreak();
         $break->load($break_id);
         $break->set('start_time', $start_time);
         $break->set('end_time', $end_time);
         $break->save();
         echo json_encode(array('success' => true, 'new_interval' => $formatted_interval));
     } else {
         $this->form = new AB_StaffScheduleItemBreakForm();
         $this->form->bind($this->getPostParameters());
         $staffScheduleItemBreak = $this->form->save();
         if ($staffScheduleItemBreak) {
             $breakStart = new AB_TimeChoiceWidget(array('use_empty' => false));
             $break_start_choices = $breakStart->render('', $start_time, array('class' => 'break-start', 'data-default_value' => AB_StaffScheduleItem::WORKING_START_TIME));
             $breakEnd = new AB_TimeChoiceWidget(array('use_empty' => false));
             $break_end_choices = $breakEnd->render('', $end_time, array('class' => 'break-end', 'data-default_value' => date('H:i:s', strtotime(AB_StaffScheduleItem::WORKING_START_TIME . ' + 1 hour'))));
             echo json_encode(array('success' => true, 'item_content' => '<div class="break-interval-wrapper" data-break_id="' . $staffScheduleItemBreak->get('id') . '">
                                       <div class="ab-popup-wrapper hide-on-non-working-day">
                                          <a class="ab-popup-trigger break-interval" href="javascript:void(0)">' . $formatted_interval . '</a>
                                          <div class="ab-popup" style="display: none">
                                              <div class="ab-arrow"></div>
                                              <div class="error" style="display: none"></div>
                                              <div class="ab-content">
                                                  <table cellspacing="0" cellpadding="0">
                                                      <tr>
                                                          <td>' . $break_start_choices . ' <span class="hide-on-non-working-day">' . __('to', 'ab') . '</span> ' . $break_end_choices . '</td>
                                                      </tr>
                                                      <tr>
                                                          <td>
                                                              <a class="btn btn-info ab-popup-save ab-save-break">' . __('Save break', 'ab') . '</a>
                                                              <a class="ab-popup-close" href="#">' . __('Cancel', 'ab') . '</a>
                                                          </td>
                                                      </tr>
                                                  </table>
                                                  <a class="ab-popup-close ab-popup-close-icon" href="javascript:void(0)"></a>
                                               </div>
                                           </div>
                                       </div>
                                       <img class="delete-break" src="' . plugins_url('backend/resources/images/delete_cross.png', AB_PATH . '/main.php') . '" />
                                    </div>'));
         } else {
             echo json_encode(array('success' => false, 'error_msg' => __('Error adding the break interval', 'ab')));
         }
     }
     exit;
 }
Exemplo n.º 2
0
 public function executeStaffScheduleHandleBreak()
 {
     $start_time = $this->getParameter('start_time');
     $end_time = $this->getParameter('end_time');
     $working_start = $this->getParameter('working_start');
     $working_end = $this->getParameter('working_end');
     if (strtotime(date('Y-m-d ' . $start_time)) >= strtotime(date('Y-m-d ' . $end_time))) {
         wp_send_json(array('success' => false, 'error_msg' => __('The start time must be less than the end one', 'bookly')));
     }
     $staffScheduleItem = new AB_StaffScheduleItem();
     $staffScheduleItem->load($this->getParameter('staff_schedule_item_id'));
     $break_id = $this->getParameter('break_id', 0);
     $in_working_time = $working_start <= $start_time && $start_time <= $working_end && $working_start <= $end_time && $end_time <= $working_end;
     if (!$in_working_time || !$staffScheduleItem->isBreakIntervalAvailable($start_time, $end_time, $break_id)) {
         wp_send_json(array('success' => false, 'error_msg' => __('The requested interval is not available', 'bookly')));
     }
     $formatted_interval_start = AB_DateTimeUtils::formatTime($start_time);
     $formatted_interval_end = AB_DateTimeUtils::formatTime($end_time);
     $formatted_interval = $formatted_interval_start . ' - ' . $formatted_interval_end;
     if ($break_id) {
         $break = new AB_ScheduleItemBreak();
         $break->load($break_id);
         $break->set('start_time', $start_time);
         $break->set('end_time', $end_time);
         $break->save();
         wp_send_json(array('success' => true, 'new_interval' => $formatted_interval));
     } else {
         $this->form = new AB_StaffScheduleItemBreakForm();
         $this->form->bind($this->getPostParameters());
         $staffScheduleItemBreak = $this->form->save();
         if ($staffScheduleItemBreak) {
             $breakStart = new AB_TimeChoiceWidget(array('use_empty' => false));
             $break_start_choices = $breakStart->render('', $start_time, array('class' => 'break-start', 'data-default_value' => AB_StaffScheduleItem::WORKING_START_TIME));
             $breakEnd = new AB_TimeChoiceWidget(array('use_empty' => false));
             $break_end_choices = $breakEnd->render('', $end_time, array('class' => 'break-end', 'data-default_value' => date('H:i:s', strtotime(AB_StaffScheduleItem::WORKING_START_TIME . ' + 1 hour'))));
             wp_send_json(array('success' => true, 'item_content' => $this->render('_break', array('staff_schedule_item_break_id' => $staffScheduleItemBreak->get('id'), 'formatted_interval' => $formatted_interval, 'break_start_choices' => $break_start_choices, 'break_end_choices' => $break_end_choices), false)));
         } else {
             wp_send_json(array('success' => false, 'error_msg' => __('Error adding the break interval', 'bookly')));
         }
     }
 }