public function checkVacations($start, $end, $reselleremployee_id) { if (!is_integer($start)) { throw new Exception("start must be an integer timestamp."); } if (!is_integer($end)) { throw new Exception("end must be an integer timestamp."); } if (!is_integer($reselleremployee_id)) { throw new Exception("reselleremployee_id must be an integer id."); } if ($start > $end) { throw new Exception("start must be lower than end."); } $vacations = Model::Vacation()->where(['reselleremployee_id', '=', (int) $reselleremployee_id])->between('start', (int) $start, (int) $end)->between('end', (int) $start, (int) $end)->exec(true); /* s'il y a des vacations, on fabrique les dispos qui correspondent pour chacune */ foreach ($vacations as $vacation) { $dispo = Model::Availability()->where(['reselleremployee_id', '=', (int) $reselleremployee_id])->between('start', (int) $start, (int) $end)->between('end', (int) $start, (int) $end)->exec(true); foreach ($dispos as $dispo) { $keep = $dispo; $dispo->delete(); if ($start != $keep->start) { $availability = $this->addAvailability((int) $keep->start, (int) $start, (int) $reseller_id, (int) $reselleremployee_id); $vacation->attach($availability, ['start' => (int) $keep->start, (int) 'end' => $start]); } if ($end != $keep->end) { $availability = $this->addAvailability((int) $end, (int) $keep->end, (int) $reseller_id, (int) $reselleremployee_id); $vacation->attach($availability, ['start' => (int) $end, 'end' => (int) $keep->end]); } } } }