1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | use Chamilo\CoreBundle\Entity\Portfolio; |
||
6 | use Chamilo\CoreBundle\Entity\PortfolioCategory; |
||
7 | use Chamilo\CoreBundle\Entity\PortfolioComment; |
||
8 | use Chamilo\CoreBundle\Entity\Tag; |
||
9 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | // Make sure we void the course context if we are in the social network section |
||
12 | if (empty($_GET['cidReq'])) { |
||
13 | $cidReset = true; |
||
14 | } |
||
15 | require_once __DIR__.'/../inc/global.inc.php'; |
||
16 | |||
17 | api_block_anonymous_users(); |
||
18 | |||
19 | if (api_get_course_int_id()) { |
||
20 | api_protect_course_script(true); |
||
21 | } |
||
22 | |||
23 | if (false === api_get_configuration_value('allow_portfolio_tool')) { |
||
24 | api_not_allowed(true); |
||
25 | } |
||
26 | |||
27 | $httpRequest = HttpRequest::createFromGlobals(); |
||
28 | $action = $httpRequest->query->get('action', 'list'); |
||
29 | |||
30 | // It validates the management of categories will be only for admins |
||
31 | if (in_array($action, ['list_categories', 'add_category', 'edit_category']) && !api_is_platform_admin()) { |
||
32 | api_not_allowed(true); |
||
33 | } |
||
34 | |||
35 | // It includes the user language for translations |
||
36 | $checkUserLanguage = true; |
||
37 | if ($checkUserLanguage) { |
||
38 | global $_user; |
||
39 | $langPath = api_get_path(SYS_LANG_PATH).$_user['language'].'/trad4all.inc.php'; |
||
40 | if (file_exists($langPath)) { |
||
41 | require_once $langPath; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | $controller = new \PortfolioController(); |
||
46 | |||
47 | $em = Database::getManager(); |
||
48 | |||
49 | $htmlHeadXtra[] = api_get_js('portfolio.js'); |
||
50 | |||
51 | switch ($action) { |
||
52 | case 'translate_category': |
||
53 | $id = $httpRequest->query->getInt('id'); |
||
54 | $languageId = $httpRequest->query->getInt('sub_language'); |
||
55 | |||
56 | /** @var PortfolioCategory $category */ |
||
57 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
58 | |||
59 | if (empty($category)) { |
||
60 | break; |
||
61 | } |
||
62 | |||
63 | $languages = $em |
||
64 | ->getRepository('ChamiloCoreBundle:Language') |
||
65 | ->findAllPlatformSubLanguages(); |
||
66 | |||
67 | $controller->translateCategory($category, $languages, $languageId); |
||
68 | |||
69 | return; |
||
70 | case 'list_categories': |
||
71 | $controller->listCategories(); |
||
72 | |||
73 | return; |
||
74 | case 'add_category': |
||
75 | $controller->addCategory(); |
||
76 | |||
77 | return; |
||
78 | case 'edit_category': |
||
79 | $id = $httpRequest->query->getInt('id'); |
||
80 | |||
81 | /** @var PortfolioCategory $category */ |
||
82 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
83 | |||
84 | if (empty($category)) { |
||
85 | break; |
||
86 | } |
||
87 | |||
88 | $controller->editCategory($category); |
||
89 | |||
90 | return; |
||
91 | case 'hide_category': |
||
92 | case 'show_category': |
||
93 | $id = $httpRequest->query->getInt('id'); |
||
94 | |||
95 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
96 | |||
97 | if (empty($category)) { |
||
98 | break; |
||
99 | } |
||
100 | |||
101 | $controller->showHideCategory($category); |
||
102 | |||
103 | return; |
||
104 | case 'delete_category': |
||
105 | $id = $httpRequest->query->getInt('id'); |
||
106 | |||
107 | /** @var PortfolioCategory $category */ |
||
108 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
109 | |||
110 | if (empty($category)) { |
||
111 | break; |
||
112 | } |
||
113 | |||
114 | $controller->deleteCategory($category); |
||
115 | |||
116 | return; |
||
117 | case 'add_item': |
||
118 | $controller->addItem(); |
||
119 | |||
120 | return; |
||
121 | case 'edit_item': |
||
122 | $id = $httpRequest->query->getInt('id'); |
||
123 | |||
124 | /** @var Portfolio $item */ |
||
125 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
126 | |||
127 | if (empty($item)) { |
||
128 | break; |
||
129 | } |
||
130 | |||
131 | $controller->editItem($item); |
||
132 | |||
133 | return; |
||
134 | case 'visibility': |
||
135 | $id = $httpRequest->query->getInt('id'); |
||
136 | |||
137 | /** @var Portfolio $item */ |
||
138 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
139 | |||
140 | if (empty($item)) { |
||
141 | break; |
||
142 | } |
||
143 | |||
144 | $controller->showHideItem($item); |
||
145 | |||
146 | return; |
||
147 | case 'item_visiblity_choose': |
||
148 | $id = $httpRequest->query->getInt('id'); |
||
149 | |||
150 | /** @var Portfolio $item */ |
||
151 | $item = $em->find(Portfolio::class, $id); |
||
152 | |||
153 | if (empty($item)) { |
||
154 | break; |
||
155 | } |
||
156 | |||
157 | $controller->itemVisibilityChooser($item); |
||
158 | break; |
||
159 | case 'comment_visiblity_choose': |
||
160 | $id = $httpRequest->query->getInt('id'); |
||
161 | |||
162 | $comment = $em->find(PortfolioComment::class, $id); |
||
163 | |||
164 | if (empty($comment)) { |
||
165 | break; |
||
166 | } |
||
167 | |||
168 | $controller->commentVisibilityChooser($comment); |
||
169 | break; |
||
170 | case 'delete_item': |
||
171 | $id = $httpRequest->query->getInt('id'); |
||
172 | |||
173 | /** @var Portfolio $item */ |
||
174 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
175 | |||
176 | if (empty($item)) { |
||
177 | break; |
||
178 | } |
||
179 | |||
180 | $controller->deleteItem($item); |
||
181 | |||
182 | return; |
||
183 | case 'view': |
||
184 | $id = $httpRequest->query->getInt('id'); |
||
185 | |||
186 | /** @var Portfolio $item */ |
||
187 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
188 | |||
189 | if (empty($item)) { |
||
190 | break; |
||
191 | } |
||
192 | |||
193 | if ($httpRequest->query->has('user')) { |
||
194 | $urlUser = $httpRequest->query->getInt('user'); |
||
195 | } |
||
196 | $controller->view($item, $urlUser); |
||
197 | |||
198 | return; |
||
199 | case 'copy': |
||
200 | case 'teacher_copy': |
||
201 | $type = $httpRequest->query->getAlpha('copy'); |
||
202 | $id = $httpRequest->query->getInt('id'); |
||
203 | |||
204 | if ('item' === $type) { |
||
205 | $item = $em->find(Portfolio::class, $id); |
||
206 | |||
207 | if (empty($item)) { |
||
208 | break; |
||
209 | } |
||
210 | |||
211 | if ('copy' === $action) { |
||
212 | $controller->copyItem($item); |
||
213 | } elseif ('teacher_copy' === $action) { |
||
214 | $controller->teacherCopyItem($item); |
||
215 | } |
||
216 | } elseif ('comment' === $type) { |
||
217 | $comment = $em->find(PortfolioComment::class, $id); |
||
218 | |||
219 | if (empty($comment)) { |
||
220 | break; |
||
221 | } |
||
222 | |||
223 | if ('copy' === $action) { |
||
224 | $controller->copyComment($comment); |
||
225 | } elseif ('teacher_copy' === $action) { |
||
226 | $controller->teacherCopyComment($comment); |
||
227 | } |
||
228 | } |
||
229 | |||
230 | break; |
||
231 | case 'mark_important': |
||
232 | api_protect_teacher_script(); |
||
233 | |||
234 | $item = $em->find(Portfolio::class, $httpRequest->query->getInt('item')); |
||
235 | $comment = $em->find(PortfolioComment::class, $httpRequest->query->getInt('id')); |
||
236 | |||
237 | if (empty($item) || empty($comment)) { |
||
238 | break; |
||
239 | } |
||
240 | |||
241 | $controller->markImportantCommentInItem($item, $comment); |
||
242 | |||
243 | return; |
||
244 | case 'details': |
||
245 | $controller->details($httpRequest); |
||
246 | |||
247 | return; |
||
248 | case 'export_pdf': |
||
249 | $controller->exportPdf($httpRequest); |
||
250 | break; |
||
251 | case 'export_zip': |
||
252 | $controller->exportZip($httpRequest); |
||
253 | break; |
||
254 | case 'qualify': |
||
255 | api_protect_teacher_script(); |
||
256 | |||
257 | if ($httpRequest->query->has('item')) { |
||
258 | if ('1' !== api_get_course_setting('qualify_portfolio_item')) { |
||
259 | api_not_allowed(true); |
||
260 | } |
||
261 | |||
262 | /** @var Portfolio $item */ |
||
263 | $item = $em->find( |
||
264 | Portfolio::class, |
||
265 | $httpRequest->query->getInt('item') |
||
266 | ); |
||
267 | |||
268 | if (empty($item)) { |
||
269 | break; |
||
270 | } |
||
271 | |||
272 | $controller->qualifyItem($item); |
||
273 | } elseif ($httpRequest->query->has('comment')) { |
||
274 | if ('1' !== api_get_course_setting('qualify_portfolio_comment')) { |
||
275 | api_not_allowed(true); |
||
276 | } |
||
277 | |||
278 | /** @var Portfolio $item */ |
||
279 | $comment = $em->find( |
||
280 | PortfolioComment::class, |
||
281 | $httpRequest->query->getInt('comment') |
||
282 | ); |
||
283 | |||
284 | if (empty($comment)) { |
||
285 | break; |
||
286 | } |
||
287 | |||
288 | $controller->qualifyComment($comment); |
||
289 | } |
||
290 | break; |
||
291 | case 'download_attachment': |
||
292 | $controller->downloadAttachment($httpRequest); |
||
293 | break; |
||
294 | case 'delete_attachment': |
||
295 | $controller->deleteAttachment($httpRequest); |
||
296 | break; |
||
297 | case 'highlighted': |
||
298 | api_protect_teacher_script(); |
||
299 | |||
300 | $id = $httpRequest->query->getInt('id'); |
||
301 | |||
302 | /** @var Portfolio $item */ |
||
303 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
304 | |||
305 | if (empty($item)) { |
||
306 | break; |
||
307 | } |
||
308 | |||
309 | $controller->markAsHighlighted($item); |
||
310 | break; |
||
311 | case 'template': |
||
312 | $id = $httpRequest->query->getInt('id'); |
||
313 | |||
314 | /** @var Portfolio $item */ |
||
315 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
316 | |||
317 | if (empty($item)) { |
||
318 | break; |
||
319 | } |
||
320 | |||
321 | $controller->markAsTemplate($item); |
||
322 | break; |
||
323 | case 'template_comment': |
||
324 | $id = $httpRequest->query->getInt('id'); |
||
325 | |||
326 | $comment = $em->find(PortfolioComment::class, $id); |
||
327 | |||
328 | if (empty($comment)) { |
||
329 | break; |
||
330 | } |
||
331 | |||
332 | $controller->markAsTemplateComment($comment); |
||
333 | break; |
||
334 | case 'edit_comment': |
||
335 | $id = $httpRequest->query->getInt('id'); |
||
336 | |||
337 | $comment = $em->find(PortfolioComment::class, $id); |
||
338 | |||
339 | if (!empty($comment)) { |
||
340 | $controller->editComment($comment); |
||
341 | } |
||
342 | |||
343 | break; |
||
344 | case 'delete_comment': |
||
345 | $id = $httpRequest->query->getInt('id'); |
||
346 | |||
347 | $comment = $em->find(PortfolioComment::class, $id); |
||
348 | |||
349 | if (!empty($comment)) { |
||
350 | $controller->deleteComment($comment); |
||
351 | } |
||
352 | break; |
||
353 | case 'tags': |
||
354 | case 'edit_tag': |
||
355 | $controller->listTags($httpRequest); |
||
356 | break; |
||
357 | case 'delete_tag': |
||
358 | $id = $httpRequest->query->getInt('id'); |
||
359 | |||
360 | $tag = $em->find(Tag::class, $id); |
||
361 | |||
362 | if (empty($tag)) { |
||
363 | break; |
||
364 | } |
||
365 | |||
366 | $controller->deleteTag($tag); |
||
367 | break; |
||
368 | case 'list': |
||
369 | default: |
||
370 | $controller->index($httpRequest); |
||
371 | |||
372 | return; |
||
373 | } |
||
374 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: