public function addBreak(BreakInputModel $model) : ServiceResponse { $lectureId = $model->getLectureId(); $lecture = $this->dbContext->getLecturesRepository()->filterById(" = {$lectureId}")->findOne(); if ($lecture->getId() == null) { return new ServiceResponse(404, "Lecture not found."); } $breakStartDate = strtotime($model->getStartDate()); $breakEndDate = strtotime($model->getEndDate()); if ($breakStartDate >= $breakEndDate) { return new ServiceResponse(1, "Start date/time cannot be later than End date/time.", $model->getConferenceId()); } $lectureModel = new LectureViewModel($lecture); if (!$this->contains($lectureModel, $model)) { return new ServiceResponse(1, "Break failed to add. Time is outside lecture time.", $model->getConferenceId()); } $lectureBreaks = $this->dbContext->getLectureBreaksRepository()->filterByLectureId(" = {$lectureId}")->findAll(); $conferenceId = $model->getConferenceId(); foreach ($lectureBreaks->getLectureBreaks() as $break) { $otherBreakModel = new AddBreakViewModel($break); if ($this->compareTo($model, $otherBreakModel) == 0) { return new ServiceResponse(1, "Break failed to add. Timing conflicts with another break.", $model->getConferenceId()); } } $break = new LectureBreak($model->getTitle(), $model->getDescription(), $model->getLectureId(), $model->getStartDate(), $model->getEndDate()); $this->dbContext->getLectureBreaksRepository()->add($break); $this->dbContext->saveChanges(); return new ServiceResponse(null, "Break added.", $model->getConferenceId()); }