Passed
Push — master ( 104510...574469 )
by Julito
09:38
created

ControllerTrait::getMenuFactory()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Traits;
6
7
use Chamilo\CoreBundle\Component\Utils\Glide;
8
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
9
use Chamilo\CoreBundle\Repository\Node\MessageAttachmentRepository;
10
use Chamilo\CoreBundle\Repository\ResourceFactory;
11
use Chamilo\CoreBundle\Repository\ResourceNodeRepository;
12
use Chamilo\CoreBundle\Settings\SettingsManager;
13
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
14
use Chamilo\CourseBundle\Repository\CAnnouncementRepository;
15
use Chamilo\CourseBundle\Repository\CAttendanceRepository;
16
use Chamilo\CourseBundle\Repository\CBlogRepository;
17
use Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository;
18
use Chamilo\CourseBundle\Repository\CDocumentRepository;
19
use Chamilo\CourseBundle\Repository\CForumAttachmentRepository;
20
use Chamilo\CourseBundle\Repository\CForumForumRepository;
21
use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
22
use Chamilo\CourseBundle\Repository\CLpRepository;
23
use Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository;
24
use Chamilo\CourseBundle\Repository\CQuizQuestionRepository;
25
use Chamilo\CourseBundle\Repository\CStudentPublicationCommentRepository;
26
use Chamilo\CourseBundle\Repository\CStudentPublicationCorrectionRepository;
27
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
28
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
29
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
30
use Symfony\Component\HttpFoundation\Request;
31
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
32
use Symfony\Contracts\Translation\TranslatorInterface;
33
34
trait ControllerTrait
35
{
36
    protected $container;
37
38
    public static function getSubscribedServices(): array
39
    {
40
        $services = AbstractController::getSubscribedServices();
41
        $services['translator'] = TranslatorInterface::class;
42
        $services['glide'] = Glide::class;
43
        $services['chamilo.settings.manager'] = SettingsManager::class;
44
        $services['chamilo_settings.form_factory.settings'] = SettingsFormFactory::class;
45
46
        $services[] = MessageAttachmentRepository::class;
47
        $services[] = ResourceFactory::class;
48
        $services[] = ResourceNodeRepository::class;
49
50
        /*
51
            The following classes are needed in order to load the resources files when using the /r/ path
52
            For example: http://my.chamilomaster.net/r/agenda/event_attachments/96/download?cid=1&sid=0&gid=0
53
            Then the repository CCalendarEventAttachmentRepository need to be added here,
54
            because it was set in the tools.yml like this:
55
            chamilo_core.tool.agenda:
56
                (...)
57
                event_attachments:
58
                    repository: Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository
59
        */
60
        $services[] = CAnnouncementRepository::class;
61
        $services[] = CAnnouncementAttachmentRepository::class;
62
        $services[] = CAttendanceRepository::class;
63
        $services[] = CBlogRepository::class;
64
        $services[] = CCalendarEventAttachmentRepository::class;
65
        $services[] = CDocumentRepository::class;
66
        $services[] = CForumForumRepository::class;
67
        $services[] = CForumAttachmentRepository::class;
68
        $services[] = CLpRepository::class;
69
        $services[] = CLpCategoryRepository::class;
70
        $services[] = CQuizQuestionRepository::class;
71
        $services[] = CQuizQuestionCategoryRepository::class;
72
        $services[] = CStudentPublicationRepository::class;
73
        $services[] = CStudentPublicationCommentRepository::class;
74
        $services[] = CStudentPublicationCorrectionRepository::class;
75
76
        $services[] = IllustrationRepository::class;
77
78
        return $services;
79
    }
80
81
    /**
82
     * @return Request|null
83
     */
84
    public function getRequest()
85
    {
86
        return $this->container->get('request_stack')->getCurrentRequest();
87
    }
88
89
    /*public function getBreadCrumb(): BreadcrumbBlockService
90
    {
91
        return $this->container->get('breadcrumb');
92
    }*/
93
94
    /**
95
     * @param string $message
96
     */
97
    public function abort($message = '')
98
    {
99
        throw new NotFoundHttpException($message);
100
    }
101
102
    /**
103
     * Translator shortcut.
104
     *
105
     * @param string $variable
106
     *
107
     * @return string
108
     */
109
    public function trans($variable)
110
    {
111
        /** @var TranslatorInterface $translator */
112
        $translator = $this->container->get('translator');
113
114
        return $translator->trans($variable);
115
    }
116
117
    /**
118
     * @return Glide
119
     */
120
    public function getGlide()
121
    {
122
        return $this->container->get('glide');
123
    }
124
125
    /**
126
     * @return SettingsManager
127
     */
128
    protected function getSettingsManager()
129
    {
130
        return $this->container->get('chamilo.settings.manager');
131
    }
132
133
    protected function getSettingsFormFactory()
134
    {
135
        return $this->container->get('chamilo_settings.form_factory.settings');
136
    }
137
}
138