Passed
Push — master ( 0a87d5...5ba6bb )
by Julito
18:12
created

TicketFixtures::setContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\DataFixtures;
8
9
use Chamilo\CoreBundle\Entity\TicketCategory;
10
use Chamilo\CoreBundle\Entity\TicketPriority;
11
use Chamilo\CoreBundle\Entity\TicketProject;
12
use Chamilo\CoreBundle\Entity\TicketStatus;
13
use Doctrine\Bundle\FixturesBundle\Fixture;
14
use Doctrine\Persistence\ObjectManager;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
use TicketManager;
18
19
class TicketFixtures extends Fixture implements ContainerAwareInterface
20
{
21
    private ContainerInterface $container;
22
23
    public function setContainer(ContainerInterface $container = null): void
24
    {
25
        $this->container = $container;
26
    }
27
28
    public function load(ObjectManager $manager): void
29
    {
30
        $container = $this->container;
31
        $trans = $container->get('translator');
32
33
        $adminId = 1;
34
35
        $ticketProject = new TicketProject();
36
        $ticketProject
37
            ->setName('Ticket System')
38
            ->setInsertUserId($adminId)
39
        ;
40
41
        $manager->persist($ticketProject);
42
        $manager->flush();
43
44
        $categories = [
45
            $trans->trans('Enrollment') => $trans->trans('Tickets about enrollment'),
46
            $trans->trans('General information') => $trans->trans('Tickets about general information'),
47
            $trans->trans('Requests and paperwork') => $trans->trans('Tickets about requests and paperwork'),
48
            $trans->trans('Academic Incidents') => $trans->trans('Tickets about academic incidents, like exams, practices, tasks, etc.'),
49
            $trans->trans('Virtual campus') => $trans->trans('Tickets about virtual campus'),
50
            $trans->trans('Online evaluation') => $trans->trans('Tickets about online evaluation'),
51
        ];
52
53
        $i = 1;
54
        foreach ($categories as $category => $description) {
55
            // Online evaluation requires a course
56
            $ticketCategory = new TicketCategory();
57
            $ticketCategory
58
                ->setName($category)
59
                ->setDescription($description)
60
                ->setProject($ticketProject)
61
                ->setInsertUserId($adminId)
62
            ;
63
64
            $isRequired = 6 === $i;
65
            $ticketCategory->setCourseRequired($isRequired);
66
67
            $manager->persist($ticketCategory);
68
            $i++;
69
        }
70
71
        // Default Priorities
72
        $defaultPriorities = [
73
            TicketManager::PRIORITY_NORMAL => $trans->trans('Normal'),
74
            TicketManager::PRIORITY_HIGH => $trans->trans('High'),
75
            TicketManager::PRIORITY_LOW => $trans->trans('Low'),
76
        ];
77
78
        foreach ($defaultPriorities as $code => $priority) {
79
            $ticketPriority = new TicketPriority();
80
            $ticketPriority
81
                ->setName($priority)
82
                ->setCode($code)
83
                ->setInsertUserId($adminId)
84
            ;
85
86
            $manager->persist($ticketPriority);
87
        }
88
89
        $manager->flush();
90
91
        // Default status
92
        $defaultStatus = [
93
            TicketManager::STATUS_NEW => $trans->trans('New'),
94
            TicketManager::STATUS_PENDING => $trans->trans('Pending'),
95
            TicketManager::STATUS_UNCONFIRMED => $trans->trans('Unconfirmed'),
96
            TicketManager::STATUS_CLOSE => $trans->trans('Close'),
97
            TicketManager::STATUS_FORWARDED => $trans->trans('Forwarded'),
98
        ];
99
100
        foreach ($defaultStatus as $code => $status) {
101
            $ticketStatus = new TicketStatus();
102
            $ticketStatus
103
                ->setName($status)
104
                ->setCode($code)
105
            ;
106
            $manager->persist($ticketStatus);
107
        }
108
109
        $manager->flush();
110
    }
111
}
112