1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
use Chamilo\CourseBundle\Entity\CItemProperty; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class StudentFollowPage. |
9
|
|
|
*/ |
10
|
|
|
class StudentFollowPage |
11
|
|
|
{ |
12
|
|
|
public const VARIABLE_ACQUISITION = 'acquisition'; |
13
|
|
|
public const VARIABLE_INVISIBLE = 'invisible'; |
14
|
|
|
|
15
|
|
|
public static function getLpSubscription( |
16
|
|
|
array $lpInfo, |
17
|
|
|
int $studentId, |
18
|
|
|
int $courseId, |
19
|
|
|
int $sessionId = 0, |
20
|
|
|
bool $showTeacherName = true |
21
|
|
|
): string { |
22
|
|
|
$em = Database::getManager(); |
23
|
|
|
|
24
|
|
|
if ($lpInfo['subscribe_users']) { |
25
|
|
|
$itemRepo = $em->getRepository(CItemProperty::class); |
26
|
|
|
$itemProperty = $itemRepo->findByUserSuscribedToItem( |
27
|
|
|
'learnpath', |
28
|
|
|
$lpInfo['iid'], |
29
|
|
|
$studentId, |
30
|
|
|
$courseId, |
31
|
|
|
$sessionId |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
if (null === $itemProperty) { |
35
|
|
|
$userGroups = GroupManager::getAllGroupPerUserSubscription($studentId, $courseId); |
36
|
|
|
|
37
|
|
|
foreach ($userGroups as $groupInfo) { |
38
|
|
|
$itemProperty = $itemRepo->findByGroupSuscribedToLp( |
39
|
|
|
'learnpath', |
40
|
|
|
$lpInfo['iid'], |
41
|
|
|
$groupInfo['iid'], |
42
|
|
|
$courseId, |
43
|
|
|
$sessionId |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
if (null !== $itemProperty) { |
47
|
|
|
break; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (null === $itemProperty) { |
53
|
|
|
return '-'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$formattedDate = api_convert_and_format_date($itemProperty->getInsertDate(), DATE_TIME_FORMAT_LONG); |
57
|
|
|
|
58
|
|
|
if ($showTeacherName) { |
59
|
|
|
$insertUser = $itemProperty->getInsertUser()->getId() !== $studentId |
60
|
|
|
? $itemProperty->getInsertUser()->getCompleteName() |
61
|
|
|
: '-'; |
62
|
|
|
|
63
|
|
|
return "$insertUser<br>".Display::tag('small', $formattedDate); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $formattedDate; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$subscriptionEvent = Event::findUserSubscriptionToCourse($studentId, $courseId, $sessionId); |
|
|
|
|
70
|
|
|
|
71
|
|
|
if (empty($subscriptionEvent)) { |
72
|
|
|
return '-'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$formattedDate = api_convert_and_format_date($subscriptionEvent['default_date'], DATE_TIME_FORMAT_LONG); |
76
|
|
|
|
77
|
|
|
if ($showTeacherName) { |
78
|
|
|
$creator = api_get_user_entity($subscriptionEvent['default_user_id']); |
79
|
|
|
|
80
|
|
|
return "{$creator->getCompleteName()}<br>".Display::tag('small', $formattedDate); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $formattedDate; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public static function getLpAcquisition( |
87
|
|
|
array $lpInfo, |
88
|
|
|
int $studentId, |
89
|
|
|
int $courseId, |
90
|
|
|
int $sessionId = 0, |
91
|
|
|
bool $allowEdit = false |
92
|
|
|
): string { |
93
|
|
|
$lpView = learnpath::findLastView($lpInfo['iid'], $studentId, $courseId, $sessionId, true); |
94
|
|
|
|
95
|
|
|
$extraField = new ExtraField('lp_view'); |
96
|
|
|
$field = $extraField->get_handler_field_info_by_field_variable(self::VARIABLE_ACQUISITION); |
97
|
|
|
|
98
|
|
|
$extraFieldValue = new ExtraFieldValue('lp_view'); |
99
|
|
|
$value = $extraFieldValue->get_values_by_handler_and_field_variable($lpView['iid'], self::VARIABLE_ACQUISITION); |
100
|
|
|
|
101
|
|
|
$return = ''; |
102
|
|
|
|
103
|
|
|
if (empty($value)) { |
104
|
|
|
$return .= '-'; |
105
|
|
|
} else { |
106
|
|
|
$optionSelected = array_filter( |
107
|
|
|
$field['options'], |
108
|
|
|
function (array $option) use ($value) { |
109
|
|
|
return $option['option_value'] == $value['value']; |
110
|
|
|
} |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
if (empty($optionSelected)) { |
114
|
|
|
$return .= '-'; |
115
|
|
|
} else { |
116
|
|
|
$optionSelected = current($optionSelected); |
117
|
|
|
$valueComment = json_decode($value['comment'], true); |
118
|
|
|
|
119
|
|
|
$register = api_get_user_entity($valueComment['user']); |
120
|
|
|
|
121
|
|
|
$return .= ExtraFieldOption::translateDisplayName($optionSelected['display_text']).'<br>' |
122
|
|
|
.Display::tag('small', $register->getCompleteName()).'<br>' |
123
|
|
|
.Display::tag( |
124
|
|
|
'small', |
125
|
|
|
api_convert_and_format_date($valueComment['datetime'], DATE_TIME_FORMAT_LONG) |
126
|
|
|
).'<br>'; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$editUrl = api_get_path(WEB_AJAX_PATH).'student_follow_page.ajax.php?' |
131
|
|
|
.http_build_query(['lp_view' => $lpView['iid'], 'a' => 'form_adquisition']); |
132
|
|
|
|
133
|
|
|
if ($allowEdit) { |
134
|
|
|
$return .= Display::url( |
135
|
|
|
Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_TINY), |
136
|
|
|
$editUrl, |
137
|
|
|
['class' => 'ajax', 'data-title' => strip_tags($lpInfo['lp_name'])] |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return '<div id="acquisition-'.$lpView['iid'].'">'.$return.'</div>'; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public static function getLpVisibleScript() |
145
|
|
|
{ |
146
|
|
|
$url = api_get_path(WEB_AJAX_PATH).'student_follow_page.ajax.php?'.http_build_query(['a' => 'views_invisible']); |
147
|
|
|
|
148
|
|
|
return "<script>$(function () { |
149
|
|
|
var chkbView = $('[name=\"chkb_view[]\"]'); |
150
|
|
|
|
151
|
|
|
function doRequest(element, state) { |
152
|
|
|
element.prop('disabled', true); |
153
|
|
|
|
154
|
|
|
var views = $.makeArray(element).map(function (input) { return input.value; }); |
155
|
|
|
|
156
|
|
|
return $.post('$url', { 'chkb_view[]': views, 'state': state }, function () { element.prop('disabled', false); }); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$('[name=\"chkb_category[]\"]').on('change', function () { |
160
|
|
|
var checked = this.checked; |
161
|
|
|
var chkbs = $(this).parents('table').find('td :checkbox').each(function () { this.checked = checked; }); |
162
|
|
|
|
163
|
|
|
doRequest(chkbs, checked); |
164
|
|
|
}).prop('checked', true); |
165
|
|
|
|
166
|
|
|
chkbView.on('change', function () { |
167
|
|
|
doRequest($(this), this.checked); |
168
|
|
|
|
169
|
|
|
$(this).parents('table').find('th :checkbox').prop( |
170
|
|
|
'checked', |
171
|
|
|
$.makeArray($(this).parents('table').find('td :checkbox')) |
172
|
|
|
.map(function (input) { return input.checked; }) |
173
|
|
|
.reduce(function (acc, cur) { return acc && cur; }) |
174
|
|
|
); |
175
|
|
|
}).each(function () { |
176
|
|
|
if (!this.checked) { |
177
|
|
|
$(this).parents('table').find('th :checkbox').prop('checked', false); |
178
|
|
|
} |
179
|
|
|
}); |
180
|
|
|
});</script>"; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public static function getLpVisibleField(array $lpInfo, int $studentId, int $courseId, int $sessionId = 0) |
184
|
|
|
{ |
185
|
|
|
$attrs = []; |
186
|
|
|
|
187
|
|
|
$isVisible = self::isViewVisible($lpInfo['iid'], $studentId, $courseId, $sessionId); |
188
|
|
|
|
189
|
|
|
if (!$isVisible) { |
190
|
|
|
$attrs['checked'] = 'checked'; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return Display::input( |
194
|
|
|
'checkbox', |
195
|
|
|
'chkb_view[]', |
196
|
|
|
implode('_', [$lpInfo['iid'], $studentId, $courseId, $sessionId]), |
197
|
|
|
$attrs |
198
|
|
|
); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public static function isViewVisible(int $lpId, int $studentId, int $courseId, int $sessionId): bool |
202
|
|
|
{ |
203
|
|
|
$lpView = learnpath::findLastView($lpId, $studentId, $courseId, $sessionId); |
204
|
|
|
|
205
|
|
|
if (empty($lpView)) { |
206
|
|
|
return true; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
$extraFieldValue = new ExtraFieldValue('lp_view'); |
210
|
|
|
$value = $extraFieldValue->get_values_by_handler_and_field_variable($lpView['iid'], self::VARIABLE_INVISIBLE); |
211
|
|
|
|
212
|
|
|
return empty($value) || empty($value['value']); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.