Passed
Push — master ( eade60...eec955 )
by Paweł
02:46
created

DemoFixtures::createLessons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 38
nc 1
nop 2
dl 0
loc 45
rs 9.312
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\DataFixtures;
6
7
use App\Entity\Author;
8
use App\Entity\Course;
9
use App\Entity\Lesson;
10
use App\Entity\Module;
11
use App\Model\CourseInterface;
12
use DateTime;
13
use Doctrine\Bundle\FixturesBundle\Fixture;
14
use Doctrine\Common\Persistence\ObjectManager;
15
16
class DemoFixtures extends Fixture
17
{
18
    public function load(ObjectManager $manager): void
19
    {
20
        $course = $this->createCourse();
21
        $this->createLessons($manager, $course);
22
        $this->createAuthor($manager, $course);
23
        $manager->persist($course);
24
25
        $manager->flush();
26
    }
27
28
    private function createCourse(): CourseInterface
29
    {
30
        $course = new Course();
31
        $course->setTitle('From courses maker ZERO to HERO');
32
        $course->setDescription('Learn how to use OwnCourses and deliver amazing courses to your audience.');
33
        $course->setVisible(true);
34
        $course->setStartDate(new DateTime('now'));
35
        $course->setEndDate((new DateTime('now'))->modify('+10 years'));
36
37
        return $course;
38
    }
39
40
    private function createLessons(ObjectManager $manager, CourseInterface $course): void
41
    {
42
        $firstModule = new Module();
43
        $firstModule->setTitle('Installation');
44
        $firstModule->setDescription('Learn how to install OwnCourses (and where to host it).');
45
        $firstModule->setCourse($course);
46
        $manager->persist($firstModule);
47
48
        $firstLesson = new Lesson();
49
        $firstLesson->setTitle('Requirements');
50
        $firstLesson->setDescription('What do You need to install OwnCourses.');
51
        $firstLesson->setDurationInMinutes(10);
52
        $firstLesson->setEmbedCode('<p>No embed</p>');
53
        $firstLesson->setModule($firstModule);
54
        $manager->persist($firstLesson);
55
56
        $secondLesson = new Lesson();
57
        $secondLesson->setTitle('Installation steps');
58
        $secondLesson->setDescription('Install OwnCourses server and students app.');
59
        $secondLesson->setDurationInMinutes(25);
60
        $secondLesson->setEmbedCode('<p>No embed</p>');
61
        $secondLesson->setModule($firstModule);
62
        $manager->persist($secondLesson);
63
64
        $secondModule = new Module();
65
        $secondModule->setTitle('Configuration');
66
        $secondModule->setDescription('Learn how to configure OwnCourses.');
67
        $secondModule->setCourse($course);
68
        $manager->persist($secondModule);
69
70
        $thirdLesson = new Lesson();
71
        $thirdLesson->setTitle('Storage with AWS');
72
        $thirdLesson->setDescription('How to store courses and lessons covers and attachments on AWS.');
73
        $thirdLesson->setDurationInMinutes(15);
74
        $thirdLesson->setEmbedCode('<p>No embed</p>');
75
        $thirdLesson->setModule($secondModule);
76
        $manager->persist($thirdLesson);
77
78
        $fourthLesson = new Lesson();
79
        $fourthLesson->setTitle('Integrations via Zappier');
80
        $fourthLesson->setDescription('Learn how to use full OwnCourses power with Zappier integrations.');
81
        $fourthLesson->setDurationInMinutes(40);
82
        $fourthLesson->setEmbedCode('<p>No embed</p>');
83
        $fourthLesson->setModule($secondModule);
84
        $manager->persist($fourthLesson);
85
    }
86
87
    private function createAuthor(ObjectManager $manager, CourseInterface $course): void
88
    {
89
        $author = new Author();
90
        $author->setName('Paweł Mikołajczuk');
91
        $author->setBio('OwnCourses founder. OpenSource developer.');
92
        $author->addCourse($course);
93
        $manager->persist($author);
94
    }
95
}
96