public function save() { $a = $this->getBreaksList(); foreach ($a as $row) { $break = new AB_ScheduleItemBreak(); $break->setFields($row); if ($this->get('start_time') >= $break->get('start_time') || $break->get('start_time') >= $this->get('end_time') || $this->get('start_time') >= $break->get('end_time') || $break->get('end_time') >= $this->get('end_time')) { $break->delete(); } } parent::save(); }
/** * * @throws Exception */ public function executeResetBreaks() { $breaks = $this->getParameter('breaks'); // Remove all breaks for staff member. $break = new AB_ScheduleItemBreak(); $break->removeBreaksByStaffId($breaks['staff_id']); $html_breaks = array(); // Restore previous breaks. if (isset($breaks['breaks']) && is_array($breaks['breaks'])) { foreach ($breaks['breaks'] as $day) { $schedule_item_break = new AB_ScheduleItemBreak(); $schedule_item_break->setFields($day); $schedule_item_break->save(); } } $staff = new AB_Staff(); $staff->load($breaks['staff_id']); // Make array with breaks (html) for each day. foreach ($staff->getScheduleItems() as $item) { /** @var AB_StaffScheduleItem $item */ $html_breaks[$item->get('id')] = $this->render('_breaks', array('day_is_not_available' => null === $item->get('start_time'), 'item' => $item), false); } wp_send_json($html_breaks); }