1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | use Chamilo\CourseBundle\Entity\CLp; |
||
6 | use Chamilo\CourseBundle\Entity\CLpView; |
||
7 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
||
0 ignored issues
–
show
|
|||
8 | |||
9 | require_once __DIR__.'/../global.inc.php'; |
||
10 | |||
11 | $httpRequest = HttpRequest::createFromGlobals(); |
||
12 | |||
13 | $isAllowedToEdit = api_is_allowed_to_edit(); |
||
14 | |||
15 | switch ($httpRequest->get('a')) { |
||
16 | case 'form_adquisition': |
||
17 | displayForm( |
||
18 | $httpRequest->query->getInt('lp_view') |
||
19 | ); |
||
20 | break; |
||
21 | case 'views_invisible': |
||
22 | processViewsInvisible( |
||
23 | $httpRequest->request->get('chkb_view') ?: [], |
||
24 | $httpRequest->request->getBoolean('state') |
||
25 | ); |
||
26 | break; |
||
27 | } |
||
28 | |||
29 | function displayForm(int $lpViewId) |
||
30 | { |
||
31 | $em = Database::getManager(); |
||
32 | |||
33 | $lpView = $em->find(CLpView::class, $lpViewId); |
||
34 | |||
35 | if (null === $lpView) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | $lp = $em->find(CLp::class, $lpView->getLpId()); |
||
40 | |||
41 | $extraField = new ExtraField('lp_view'); |
||
42 | $field = $extraField->get_handler_field_info_by_field_variable(StudentFollowPage::VARIABLE_ACQUISITION); |
||
43 | |||
44 | $extraFieldValue = new ExtraFieldValue('lp_view'); |
||
45 | $value = $extraFieldValue->get_values_by_handler_and_field_variable( |
||
46 | $lpViewId, |
||
47 | StudentFollowPage::VARIABLE_ACQUISITION |
||
48 | ); |
||
49 | |||
50 | $options = []; |
||
51 | |||
52 | foreach ($field['options'] as $option) { |
||
53 | $options[$option['option_value']] = ExtraFieldOption::translateDisplayName($option['display_text']); |
||
54 | } |
||
55 | |||
56 | $frmId = 'frm_lp_acquisition_'.$lpView->getLpId(); |
||
57 | $frmAction = api_get_self().'?'.http_build_query(['lp_view' => $lpViewId, 'a' => 'form_adquisition']); |
||
58 | |||
59 | $form = new FormValidator($frmId, 'post', $frmAction); |
||
60 | $form->addRadio(StudentFollowPage::VARIABLE_ACQUISITION, get_lang('Acquisition'), $options); |
||
61 | $form->addHidden('lp_view', $lpViewId); |
||
62 | $form->addButtonSave(get_lang('Save')); |
||
63 | |||
64 | if ($form->validate()) { |
||
65 | $values = $form->exportValues(); |
||
66 | |||
67 | $extraFieldValue = new ExtraFieldValue('lp_view'); |
||
68 | $extraFieldValue->save( |
||
69 | [ |
||
70 | 'variable' => StudentFollowPage::VARIABLE_ACQUISITION, |
||
71 | 'item_id' => $lpViewId, |
||
72 | 'comment' => json_encode(['user' => api_get_user_id(), 'datetime' => api_get_utc_datetime()]), |
||
73 | 'value' => $values[StudentFollowPage::VARIABLE_ACQUISITION], |
||
74 | ] |
||
75 | ); |
||
76 | |||
77 | echo StudentFollowPage::getLpAcquisition( |
||
78 | [ |
||
79 | 'iid' => $lp->getIid(), |
||
80 | 'lp_name' => $lp->getName(), |
||
81 | ], |
||
82 | $lpView->getUserId(), |
||
83 | $lpView->getCId(), |
||
84 | $lpView->getSessionId(), |
||
85 | true |
||
86 | ); |
||
87 | exit; |
||
0 ignored issues
–
show
|
|||
88 | } |
||
89 | |||
90 | if (!empty($value)) { |
||
91 | $form->setDefaults([StudentFollowPage::VARIABLE_ACQUISITION => $value['value']]); |
||
92 | } |
||
93 | |||
94 | echo $form->returnForm() |
||
95 | ."<script>$(function () { |
||
96 | $('#$frmId').on('submit', function (e) { |
||
97 | e.preventDefault(); |
||
98 | |||
99 | var self = $(this); |
||
100 | |||
101 | self.find(':submit').prop('disabled', true); |
||
102 | |||
103 | $.post(this.action, self.serialize()).done(function (response) { |
||
104 | $('#acquisition-$lpViewId').html(response); |
||
105 | |||
106 | $('#global-modal').modal('hide'); |
||
107 | |||
108 | self.find(':submit').prop('disabled', false); |
||
109 | }); |
||
110 | }) |
||
111 | })</script>"; |
||
112 | } |
||
113 | |||
114 | function processViewsInvisible(array $lpViews, bool $state) |
||
115 | { |
||
116 | foreach ($lpViews as $lpViewData) { |
||
117 | $parts = explode('_', $lpViewData); |
||
118 | |||
119 | [$lpId, $userId, $courseId, $sessionId] = array_map('intval', $parts); |
||
120 | |||
121 | $lpView = learnpath::findLastView($lpId, $userId, $courseId, $sessionId); |
||
122 | |||
123 | if (empty($lpView)) { |
||
124 | $tblLpView = Database::get_course_table(TABLE_LP_VIEW); |
||
125 | |||
126 | $lpViewId = Database::insert( |
||
127 | $tblLpView, |
||
128 | [ |
||
129 | 'c_id' => $courseId, |
||
130 | 'lp_id' => $lpId, |
||
131 | 'user_id' => $userId, |
||
132 | 'view_count' => 1, |
||
133 | 'session_id' => $sessionId, |
||
134 | ] |
||
135 | ); |
||
136 | Database::update($tblLpView, ['id' => $lpViewId], ['iid = ?' => $lpViewId]); |
||
137 | } else { |
||
138 | $lpViewId = $lpView['iid']; |
||
139 | } |
||
140 | |||
141 | $extraFieldValue = new ExtraFieldValue('lp_view'); |
||
142 | $extraFieldValue->save( |
||
143 | [ |
||
144 | 'variable' => StudentFollowPage::VARIABLE_INVISIBLE, |
||
145 | 'item_id' => $lpViewId, |
||
146 | 'comment' => json_encode(['user' => api_get_user_id(), 'datetime' => api_get_utc_datetime()]), |
||
147 | 'value' => $state, |
||
148 | ] |
||
149 | ); |
||
150 | } |
||
151 | } |
||
152 |
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: