Skip to content

Instantly share code, notes, and snippets.

@adelf
Created January 9, 2017 13:52
Show Gist options
  • Save adelf/37708069137cc204a122cdbf9922a4de to your computer and use it in GitHub Desktop.
Save adelf/37708069137cc204a122cdbf9922a4de to your computer and use it in GitHub Desktop.
<?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