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