Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace App\Domain\Courses;
use App\Domain\Courses\Exam\ExamQuestion;
use App\Domain\Courses\Exam\ExamVersion;
use App\Exceptions\Courses\CourseCannotBeOpened;
class CourseOpener
{
public function open(Course $course)
{
if($course->open)
{
throw new CourseCannotBeOpened('Course is open');
}
if(!$course->video_uploaded)
{
throw new CourseCannotBeOpened('Course should have video');
}
if($course->questions->count() < 3)
{
throw new CourseCannotBeOpened('Create at least 3 questions for the course exam before open it');
}
if($course->checklistItems->count() < 2)
{
throw new CourseCannotBeOpened('Create at least 2 checklist items for the course video exam before open it');
}
if($course->raters()->count() <= 0)
{
throw new CourseCannotBeOpened('Assign at least 1 rater for this course');
}
if($this->shouldCreateNewExamVersion($course))
{
$course->exam_version_id = $this->createNewExamVersion($course)->id;
}
$course->open = true;
$course->save();
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.