public static function validateNewDates($user, $termId, $tutorId, $startDate, $endDate, $existingAppointmentId = false) { $nowDate = new DateTime(); date_default_timezone_set('Europe/Athens'); // TODO: remove hardcoded $user if ($nowDate > $startDate && !$user->isAdmin()) { throw new Exception("Starting datetime cannot be less than current datetime."); } $minutesAppointmentDuration = ($endDate->getTimestamp() - $startDate->getTimestamp()) / 60; if ($minutesAppointmentDuration < 30 || $minutesAppointmentDuration > 480) { throw new Exception("Appointment's duration can be between 30 min and 8 hours."); } if (!$user->isAdmin() && !ScheduleFetcher::existsTutorsSchedulesBetween($tutorId, $termId, $startDate, $endDate)) { throw new Exception("There is a conflict with start/end date with tutor's schedule. "); } if (AppointmentFetcher::existsTutorsAppointmentsBetween($tutorId, $termId, $startDate, $endDate, $existingAppointmentId)) { throw new Exception("There is a conflict with the start/end date with another appointment for selected tutor."); } }