Skip to content

Instantly share code, notes, and snippets.

@antonkomarev
Forked from adelf/CourseOpener.php
Created January 11, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonkomarev/39ac7e9dc1037eccdee42db7174fd5da to your computer and use it in GitHub Desktop.
Save antonkomarev/39ac7e9dc1037eccdee42db7174fd5da 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