|
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; |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
require_once __DIR__.'/../global.inc.php'; |
|
10
|
|
|
|
|
11
|
|
|
api_protect_course_script(true); |
|
12
|
|
|
|
|
13
|
|
|
$httpRequest = HttpRequest::createFromGlobals(); |
|
14
|
|
|
|
|
15
|
|
|
$isAllowedToEdit = api_is_allowed_to_edit(); |
|
16
|
|
|
|
|
17
|
|
|
switch ($httpRequest->get('a')) { |
|
18
|
|
|
case 'form_adquisition': |
|
19
|
|
|
displayForm( |
|
20
|
|
|
$httpRequest->query->getInt('lp_view') |
|
21
|
|
|
); |
|
22
|
|
|
break; |
|
23
|
|
|
case 'views_invisible': |
|
24
|
|
|
processViewsInvisible( |
|
25
|
|
|
$httpRequest->request->get('chkb_view') ?: [], |
|
26
|
|
|
$httpRequest->request->getBoolean('state') |
|
27
|
|
|
); |
|
28
|
|
|
break; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function displayForm(int $lpViewId) |
|
32
|
|
|
{ |
|
33
|
|
|
$em = Database::getManager(); |
|
34
|
|
|
|
|
35
|
|
|
$lpView = $em->find(CLpView::class, $lpViewId); |
|
36
|
|
|
|
|
37
|
|
|
if (null === $lpView) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$lp = $em->find(CLp::class, $lpView->getLpId()); |
|
42
|
|
|
|
|
43
|
|
|
$extraField = new ExtraField('lp_view'); |
|
44
|
|
|
$field = $extraField->get_handler_field_info_by_field_variable(StudentFollowPage::VARIABLE_ACQUISITION); |
|
45
|
|
|
|
|
46
|
|
|
$extraFieldValue = new ExtraFieldValue('lp_view'); |
|
47
|
|
|
$value = $extraFieldValue->get_values_by_handler_and_field_variable( |
|
48
|
|
|
$lpViewId, |
|
49
|
|
|
StudentFollowPage::VARIABLE_ACQUISITION |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$options = []; |
|
53
|
|
|
|
|
54
|
|
|
foreach ($field['options'] as $option) { |
|
55
|
|
|
$options[$option['option_value']] = $option['display_text']; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$frmId = 'frm_lp_acquisition_'.$lpView->getLpId(); |
|
59
|
|
|
$frmAction = api_get_self().'?'.http_build_query(['lp_view' => $lpViewId, 'a' => 'form_adquisition']); |
|
60
|
|
|
|
|
61
|
|
|
$form = new FormValidator($frmId, 'post', $frmAction); |
|
62
|
|
|
$form->addRadio(StudentFollowPage::VARIABLE_ACQUISITION, get_lang('Acquisition'), $options); |
|
63
|
|
|
$form->addHidden('lp_view', $lpViewId); |
|
64
|
|
|
$form->addButtonSave(get_lang('Save')); |
|
65
|
|
|
|
|
66
|
|
|
if ($form->validate()) { |
|
67
|
|
|
$values = $form->exportValues(); |
|
68
|
|
|
|
|
69
|
|
|
$extraFieldValue = new ExtraFieldValue('lp_view'); |
|
70
|
|
|
$extraFieldValue->save( |
|
71
|
|
|
[ |
|
72
|
|
|
'variable' => StudentFollowPage::VARIABLE_ACQUISITION, |
|
73
|
|
|
'item_id' => $lpViewId, |
|
74
|
|
|
'comment' => json_encode(['user' => api_get_user_id(), 'datetime' => api_get_utc_datetime()]), |
|
75
|
|
|
'value' => $values[StudentFollowPage::VARIABLE_ACQUISITION], |
|
76
|
|
|
] |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
echo StudentFollowPage::getLpAcquisition( |
|
80
|
|
|
[ |
|
81
|
|
|
'iid' => $lp->getIid(), |
|
82
|
|
|
'lp_name' => $lp->getName(), |
|
83
|
|
|
], |
|
84
|
|
|
$lpView->getUserId(), |
|
85
|
|
|
$lpView->getCId(), |
|
86
|
|
|
$lpView->getSessionId(), |
|
87
|
|
|
true |
|
88
|
|
|
); |
|
89
|
|
|
exit; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (!empty($value)) { |
|
93
|
|
|
$form->setDefaults([StudentFollowPage::VARIABLE_ACQUISITION => $value['value']]); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
echo $form->returnForm() |
|
97
|
|
|
."<script>$(function () { |
|
98
|
|
|
$('#$frmId').on('submit', function (e) { |
|
99
|
|
|
e.preventDefault(); |
|
100
|
|
|
|
|
101
|
|
|
var self = $(this); |
|
102
|
|
|
|
|
103
|
|
|
self.find(':submit').prop('disabled', true); |
|
104
|
|
|
|
|
105
|
|
|
$.post(this.action, self.serialize()).done(function (response) { |
|
106
|
|
|
$('#acquisition-$lpViewId').html(response); |
|
107
|
|
|
|
|
108
|
|
|
$('#global-modal').modal('hide'); |
|
109
|
|
|
|
|
110
|
|
|
self.find(':submit').prop('disabled', false); |
|
111
|
|
|
}); |
|
112
|
|
|
}) |
|
113
|
|
|
})</script>"; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
function processViewsInvisible(array $lpViewsIds, bool $state) |
|
117
|
|
|
{ |
|
118
|
|
|
$lpViewsIds = array_map('intval', $lpViewsIds); |
|
119
|
|
|
$lpViewsIds = array_filter($lpViewsIds); |
|
120
|
|
|
|
|
121
|
|
|
if (empty($lpViewsIds)) { |
|
122
|
|
|
return; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
foreach ($lpViewsIds as $lpViewId) { |
|
126
|
|
|
$extraFieldValue = new ExtraFieldValue('lp_view'); |
|
127
|
|
|
$extraFieldValue->save( |
|
128
|
|
|
[ |
|
129
|
|
|
'variable' => StudentFollowPage::VARIABLE_INVISIBLE, |
|
130
|
|
|
'item_id' => $lpViewId, |
|
131
|
|
|
'comment' => json_encode(['user' => api_get_user_id(), 'datetime' => api_get_utc_datetime()]), |
|
132
|
|
|
'value' => !$state, |
|
133
|
|
|
] |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: