1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool; |
||
5 | use Symfony\Component\HttpFoundation\Request; |
||
0 ignored issues
–
show
|
|||
6 | |||
7 | $cidReset = true; |
||
8 | |||
9 | require_once __DIR__.'/../../main/inc/global.inc.php'; |
||
10 | |||
11 | api_protect_admin_script(); |
||
12 | |||
13 | $plugin = ImsLtiPlugin::create(); |
||
14 | $webPluginPath = api_get_path(WEB_PLUGIN_PATH).'ims_lti/'; |
||
15 | |||
16 | $em = Database::getManager(); |
||
17 | |||
18 | try { |
||
19 | if ($plugin->get('enabled') !== 'true') { |
||
20 | throw new Exception(get_lang('NotAllowed')); |
||
21 | } |
||
22 | |||
23 | $request = Request::createFromGlobals(); |
||
24 | $ltiToolId = $request->query->getInt('id'); |
||
25 | $sessionId = $request->query->getInt('session_id'); |
||
26 | |||
27 | /** @var ImsLtiTool $tool */ |
||
28 | $tool = $em->find('ChamiloPluginBundle:ImsLti\ImsLtiTool', $ltiToolId); |
||
29 | |||
30 | if (!$tool) { |
||
31 | throw new Exception($plugin->get_lang('NoTool')); |
||
32 | } |
||
33 | |||
34 | if ($tool->getParent()) { |
||
35 | throw new Exception($plugin->get_lang('NoAllowed')); |
||
36 | } |
||
37 | |||
38 | $session = api_get_session_entity($sessionId); |
||
39 | |||
40 | if (!$session) { |
||
41 | api_not_allowed(true); |
||
42 | } |
||
43 | |||
44 | $content = ''; |
||
45 | |||
46 | $courses = ImsLtiPlugin::getCoursesForParentTool($tool, $session); |
||
47 | |||
48 | $slctCourses = []; |
||
49 | |||
50 | /** @var \Chamilo\CoreBundle\Entity\Course $course */ |
||
51 | foreach ($courses as $course) { |
||
52 | $slctCourses[$course->getId()] = $course->getName(); |
||
53 | } |
||
54 | |||
55 | $selectedCoursesIds = array_keys($slctCourses); |
||
56 | |||
57 | $form = new FormValidator('frm_multiply', 'post', api_get_self().'?id='.$tool->getId().'&session_id='.$sessionId); |
||
58 | $form->addLabel(get_lang('SessionName'), $session); |
||
59 | $form->addLabel($plugin->get_lang('Tool'), $tool->getName()); |
||
60 | $form->addSelectAjax( |
||
61 | 'courses', |
||
62 | get_lang('Courses'), |
||
63 | $slctCourses, |
||
64 | [ |
||
65 | 'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?'.http_build_query( |
||
66 | [ |
||
67 | 'a' => 'search_course_by_session_all', |
||
68 | 'session_id' => $sessionId, |
||
69 | ] |
||
70 | ), |
||
71 | 'multiple' => true, |
||
72 | ] |
||
73 | ); |
||
74 | $form->addCheckBox('tool_visible', get_lang('SetVisible'), get_lang('ToolIsNowVisible')); |
||
75 | $form->addButtonExport(get_lang('Save')); |
||
76 | |||
77 | if ($form->validate()) { |
||
78 | $em = Database::getManager(); |
||
79 | $formValues = $form->exportValues(); |
||
80 | $formValues['courses'] = empty($formValues['courses']) ? [] : $formValues['courses']; |
||
81 | $formValues['tool_visible'] = !empty($formValues['tool_visible']); |
||
82 | |||
83 | $courseIdsToDelete = array_diff($selectedCoursesIds, $formValues['courses']); |
||
84 | $newSelectedCourseIds = array_diff($formValues['courses'], $selectedCoursesIds); |
||
85 | |||
86 | if ($courseIdsToDelete) { |
||
87 | $toolLinks = []; |
||
88 | |||
89 | /** @var ImsLtiTool $childInCourse */ |
||
90 | foreach ($tool->getChildrenInCourses($courseIdsToDelete) as $childInCourse) { |
||
91 | $toolLinks[] = "ims_lti/start.php?id={$childInCourse->getId()}"; |
||
92 | |||
93 | $em->remove($childInCourse); |
||
94 | } |
||
95 | |||
96 | $em->flush(); |
||
97 | |||
98 | if (!empty($toolLinks)) { |
||
99 | $em |
||
100 | ->createQuery( |
||
101 | "DELETE FROM ChamiloCourseBundle:CTool ct WHERE ct.category = :category AND ct.link IN (:links) AND ct.session_id = :sessionId" |
||
102 | ) |
||
103 | ->execute(['category' => 'plugin', 'links' => $toolLinks, 'sessionId' => $sessionId]); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | if ($newSelectedCourseIds) { |
||
108 | foreach ($newSelectedCourseIds as $newSelectedCourseId) { |
||
109 | $newSelectedCourse = api_get_course_entity($newSelectedCourseId); |
||
110 | |||
111 | $newTool = clone $tool; |
||
112 | $newTool->setParent($tool); |
||
113 | $newTool->setCourse($newSelectedCourse); |
||
114 | $newTool->setSession($session); |
||
115 | |||
116 | $em->persist($newTool); |
||
117 | $em->flush(); |
||
118 | |||
119 | if ($tool->isActiveDeepLinking()) { |
||
120 | continue; |
||
121 | } |
||
122 | |||
123 | $plugin->addCourseSessionTool( |
||
124 | $newSelectedCourse, |
||
125 | $session, |
||
126 | $newTool, |
||
127 | $formValues['tool_visible'] |
||
128 | ); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | Display::addFlash( |
||
133 | Display::return_message(get_lang('ItemUpdated')) |
||
134 | ); |
||
135 | |||
136 | header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); |
||
137 | exit; |
||
138 | } |
||
139 | |||
140 | $form->setDefaults( |
||
141 | [ |
||
142 | 'courses' => $selectedCoursesIds, |
||
143 | 'tool_visible' => true, |
||
144 | ] |
||
145 | ); |
||
146 | $form->protect(); |
||
147 | |||
148 | $content = $form->returnForm(); |
||
149 | |||
150 | $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/index.php', 'name' => get_lang('PlatformAdmin')]; |
||
151 | $interbreadcrumb[] = ['url' => api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php', 'name' => $plugin->get_title()]; |
||
152 | |||
153 | $template = new Template($plugin->get_lang('AddInCourses')); |
||
154 | $template->assign('header', $plugin->get_lang('AddInCourses')); |
||
155 | $template->assign('content', $content); |
||
156 | $template->display_one_col_template(); |
||
157 | } catch (Exception $exception) { |
||
158 | Display::addFlash( |
||
159 | Display::return_message($exception->getMessage(), 'error') |
||
160 | ); |
||
161 | |||
162 | header('Location: '.api_get_path(WEB_PLUGIN_PATH).'ims_lti/admin.php'); |
||
163 | } |
||
164 |
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: