public function save()
 {
     if (isset($this->data['days'])) {
         foreach ($this->data['days'] as $id => $day_index) {
             $staffScheduleItem = new AB_StaffScheduleItem();
             $staffScheduleItem->load($id);
             $staffScheduleItem->set('day_index', $day_index);
             if ($this->data['start_time'][$day_index]) {
                 $staffScheduleItem->set('start_time', $this->data['start_time'][$day_index]);
                 $staffScheduleItem->set('end_time', $this->data['end_time'][$day_index]);
             } else {
                 $staffScheduleItem->set('start_time', null);
                 $staffScheduleItem->set('end_time', null);
             }
             $staffScheduleItem->save();
         }
     }
 }
Esempio n. 2
0
<?php

if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
$staffScheduleItem = new AB_StaffScheduleItem();
$staffScheduleItem->load($list_item->staff_schedule_item_id);
$breaks_list = $staffScheduleItem->getBreaksList();
$display = count($breaks_list) ? 'inline-block' : 'none;';
?>
<table class="breaks-list hide-on-non-working-day" cellspacing="0" cellpadding="0"<?php 
if ($day_is_not_available) {
    ?>
 style="display: none"<?php 
}
?>
>
    <tr>
        <td class="breaks-list-label">
            <span style="display: <?php 
echo $display;
?>
">
                <?php 
_e('breaks:', 'ab');
?>
            </span>
        </td>
        <td class="breaks-list-content">
            <?php 
 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;
 }
Esempio n. 4
0
 /**
  * Extend parent method to control access on staff member level.
  *
  * @param string $action
  * @return bool
  */
 protected function hasAccess($action)
 {
     if (parent::hasAccess($action)) {
         if (!AB_Utils::isCurrentUserAdmin()) {
             $staff = new AB_Staff();
             switch ($action) {
                 case 'executeEditStaff':
                 case 'executeDeleteStaffAvatar':
                 case 'executeStaffServices':
                 case 'executeStaffSchedule':
                 case 'executeStaffHolidays':
                     $staff->load($this->getParameter('id'));
                     break;
                 case 'executeStaffServicesUpdate':
                 case 'executeStaffHolidaysUpdate':
                     $staff->load($this->getParameter('staff_id'));
                     break;
                 case 'executeStaffScheduleHandleBreak':
                     $staffScheduleItem = new AB_StaffScheduleItem();
                     $staffScheduleItem->load($this->getParameter('staff_schedule_item_id'));
                     $staff->load($staffScheduleItem->get('staff_id'));
                     break;
                 case 'executeDeleteStaffScheduleBreak':
                     $break = new AB_ScheduleItemBreak();
                     $break->load($this->getParameter('id'));
                     $staffScheduleItem = new AB_StaffScheduleItem();
                     $staffScheduleItem->load($break->get('staff_schedule_item_id'));
                     $staff->load($staffScheduleItem->get('staff_id'));
                     break;
                 case 'executeStaffScheduleUpdate':
                     if ($this->hasParameter('days')) {
                         foreach ($this->getParameter('days') as $id => $day_index) {
                             $staffScheduleItem = new AB_StaffScheduleItem();
                             $staffScheduleItem->load($id);
                             $staff = new AB_Staff();
                             $staff->load($staffScheduleItem->get('staff_id'));
                             if ($staff->get('wp_user_id') != get_current_user_id()) {
                                 return false;
                             }
                         }
                     }
                     break;
                 default:
                     return false;
             }
             return $staff->get('wp_user_id') == get_current_user_id();
         }
         return true;
     }
     return false;
 }