1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see license.txt */ |
4
|
|
|
|
5
|
|
|
use ChamiloSession as Session; |
6
|
|
|
use CpChart\Cache as pCache; |
7
|
|
|
use CpChart\Data as pData; |
8
|
|
|
use CpChart\Image as pImage; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* GradebookTable Class |
12
|
|
|
* Table to display categories, evaluations and links. |
13
|
|
|
* |
14
|
|
|
* @author Stijn Konings |
15
|
|
|
* @author Bert Steppé (refactored, optimised) |
16
|
|
|
*/ |
17
|
|
|
class GradebookTable extends SortableTable |
18
|
|
|
{ |
19
|
|
|
public $cats; |
20
|
|
|
public $exportToPdf; |
21
|
|
|
public $teacherView; |
22
|
|
|
public $userId; |
23
|
|
|
public $studentList = []; |
24
|
|
|
private $currentcat; |
25
|
|
|
private $datagen; |
26
|
|
|
private $evals_links; |
27
|
|
|
private $dataForGraph; |
28
|
|
|
/** |
29
|
|
|
* @var array Indicates which columns should be shown in gradebook |
30
|
|
|
* |
31
|
|
|
* @example [1] To add Ranking column |
32
|
|
|
* [2] To add Best Score column |
33
|
|
|
* [3] To add Average column |
34
|
|
|
*/ |
35
|
|
|
private $loadStats = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* GradebookTable constructor. |
39
|
|
|
* |
40
|
|
|
* @param Category $currentcat |
41
|
|
|
* @param array $cats |
42
|
|
|
* @param array $evals |
43
|
|
|
* @param array $links |
44
|
|
|
* @param null $addparams |
|
|
|
|
45
|
|
|
* @param bool $exportToPdf |
46
|
|
|
* @param null $showTeacherView |
|
|
|
|
47
|
|
|
* @param int $userId |
48
|
|
|
* @param array $studentList |
49
|
|
|
*/ |
50
|
|
|
public function __construct( |
51
|
|
|
$currentcat, |
52
|
|
|
$cats = [], |
53
|
|
|
$evals = [], |
54
|
|
|
$links = [], |
55
|
|
|
$addparams = null, |
56
|
|
|
$exportToPdf = false, |
57
|
|
|
$showTeacherView = null, |
58
|
|
|
$userId = null, |
59
|
|
|
$studentList = [], |
60
|
|
|
array $loadStats = [] |
61
|
|
|
) { |
62
|
|
|
$this->teacherView = is_null($showTeacherView) ? api_is_allowed_to_edit(null, true) : $showTeacherView; |
63
|
|
|
$this->userId = is_null($userId) ? api_get_user_id() : $userId; |
64
|
|
|
$this->exportToPdf = $exportToPdf; |
65
|
|
|
$this->studentList = $studentList; |
66
|
|
|
|
67
|
|
|
parent::__construct( |
68
|
|
|
'gradebooklist', |
69
|
|
|
null, |
70
|
|
|
null, |
71
|
|
|
api_is_allowed_to_edit() ? 1 : 0, |
72
|
|
|
1000, |
73
|
|
|
'ASC', |
74
|
|
|
'gradebook_list' |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$this->evals_links = array_merge($evals, $links); |
78
|
|
|
$this->currentcat = $currentcat; |
79
|
|
|
$this->cats = $cats; |
80
|
|
|
$this->loadStats = $loadStats; |
81
|
|
|
$this->datagen = new GradebookDataGenerator($cats, $evals, $links); |
82
|
|
|
$this->datagen->exportToPdf = $this->exportToPdf; |
83
|
|
|
$this->datagen->preLoadDataKey = $this->getPreloadDataKey(); |
84
|
|
|
$this->datagen->hidePercentage = api_get_configuration_value('hide_gradebook_percentage_user_result'); |
85
|
|
|
|
86
|
|
|
if (!empty($userId)) { |
87
|
|
|
$this->datagen->userId = $userId; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (isset($addparams)) { |
91
|
|
|
$this->set_additional_parameters($addparams ?: []); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$column = 0; |
95
|
|
|
if ($this->teacherView) { |
96
|
|
|
if (false == $this->exportToPdf) { |
97
|
|
|
$this->set_header($column++, '', '', 'width="25px"'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$styleTextRight = ['style' => 'text-align: right;']; |
102
|
|
|
$styleTextRight100 = ['style' => 'text-align: right; width: 100px;']; |
103
|
|
|
$styleTextRight120 = ['style' => 'text-align: right; width: 120px;']; |
104
|
|
|
$styleCenterRight = ['style' => 'text-align: center;']; |
105
|
|
|
|
106
|
|
|
$this->set_header($column++, get_lang('Type'), '', 'width="20px"'); |
107
|
|
|
$this->set_header($column++, get_lang('Name'), false); |
108
|
|
|
if (false == $this->exportToPdf) { |
109
|
|
|
$this->set_header($column++, get_lang('Description'), false); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$model = ExerciseLib::getCourseScoreModel(); |
113
|
|
|
$settings = api_get_configuration_value('gradebook_pdf_export_settings'); |
114
|
|
|
$showWeight = true; |
115
|
|
|
if ($this->exportToPdf && isset($settings['hide_score_weight']) && $settings['hide_score_weight']) { |
116
|
|
|
$showWeight = false; |
117
|
|
|
} |
118
|
|
|
if ($showWeight) { |
119
|
|
|
$this->set_header($column++, get_lang('Weight'), false, $styleTextRight100, $styleTextRight100); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if (!$this->teacherView) { |
123
|
|
|
$this->set_header($column++, get_lang('Result'), false, $styleTextRight, $styleTextRight); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (empty($model)) { |
127
|
|
|
if (in_array(1, $this->loadStats)) { |
128
|
|
|
$this->set_header($column++, get_lang('Ranking'), false, $styleTextRight100, $styleTextRight100); |
129
|
|
|
} |
130
|
|
|
if (in_array(2, $this->loadStats)) { |
131
|
|
|
$this->set_header($column++, get_lang('BestScore'), false, $styleTextRight120, $styleTextRight120); |
132
|
|
|
} |
133
|
|
|
if (in_array(3, $this->loadStats)) { |
134
|
|
|
$this->set_header($column++, get_lang('Average'), false, $styleTextRight100, $styleTextRight100); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
if ($this->teacherView) { |
139
|
|
|
} else { |
140
|
|
|
if (!empty($cats)) { |
141
|
|
|
if ($this->exportToPdf == false) { |
142
|
|
|
$this->set_header($column++, get_lang('Actions'), false, $styleCenterRight, $styleCenterRight); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
// Deactivates the odd/even alt rows in order that the +/- buttons work see #4047 |
148
|
|
|
$this->odd_even_rows_enabled = false; |
149
|
|
|
|
150
|
|
|
// Admins get an edit column. |
151
|
|
|
if ($this->teacherView) { |
152
|
|
|
$this->set_header($column++, get_lang('Modify'), false, 'width="195px"'); |
153
|
|
|
// Actions on multiple selected documents. |
154
|
|
|
$this->set_form_actions( |
155
|
|
|
[ |
156
|
|
|
'setvisible' => get_lang('SetVisible'), |
157
|
|
|
'setinvisible' => get_lang('SetInvisible'), |
158
|
|
|
'deleted' => get_lang('DeleteSelected'), |
159
|
|
|
] |
160
|
|
|
); |
161
|
|
|
} else { |
162
|
|
|
if (empty($_GET['selectcat']) && !$this->teacherView) { |
163
|
|
|
if ($this->exportToPdf == false) { |
164
|
|
|
$this->set_header( |
165
|
|
|
$column++, |
166
|
|
|
get_lang('Certificates'), |
167
|
|
|
false |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return GradebookDataGenerator |
176
|
|
|
*/ |
177
|
|
|
public function get_data() |
178
|
|
|
{ |
179
|
|
|
return $this->datagen; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Function used by SortableTable to get total number of items in the table. |
184
|
|
|
* |
185
|
|
|
* @return int |
186
|
|
|
*/ |
187
|
|
|
public function get_total_number_of_items() |
188
|
|
|
{ |
189
|
|
|
return $this->datagen->get_total_items_count(); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
public function getPreloadDataKey() |
196
|
|
|
{ |
197
|
|
|
return 'default_data_'.api_get_course_id().'_'.api_get_session_id(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function preloadData() |
201
|
|
|
{ |
202
|
|
|
$allitems = $this->datagen->items; |
203
|
|
|
usort($allitems, ['GradebookDataGenerator', 'sort_by_name']); |
204
|
|
|
$visibleItems = array_merge($this->datagen->items, $this->evals_links); |
205
|
|
|
$defaultDataFromSession = Session::read($this->getPreloadDataKey()); |
206
|
|
|
if (empty($defaultDataFromSession)) { |
207
|
|
|
$defaultData = []; |
208
|
|
|
/** @var GradebookItem $item */ |
209
|
|
|
foreach ($visibleItems as $item) { |
210
|
|
|
$item->setStudentList($this->studentList); |
211
|
|
|
$itemType = get_class($item); |
212
|
|
|
switch ($itemType) { |
213
|
|
|
case 'Evaluation': |
214
|
|
|
// Best |
215
|
|
|
$best = $this->datagen->buildBestResultColumn($item); |
216
|
|
|
$defaultData[$item->get_id()]['best'] = $best; |
217
|
|
|
// Average |
218
|
|
|
$average = $this->datagen->buildAverageResultColumn($item); |
219
|
|
|
$defaultData[$item->get_id()]['average'] = $average; |
220
|
|
|
break; |
221
|
|
|
case 'ExerciseLink': |
222
|
|
|
/** @var ExerciseLink $item */ |
223
|
|
|
// Best |
224
|
|
|
$best = $this->datagen->buildBestResultColumn($item); |
225
|
|
|
$defaultData[$item->get_id()]['best'] = $best; |
226
|
|
|
// Average |
227
|
|
|
$average = $this->datagen->buildAverageResultColumn($item); |
228
|
|
|
$defaultData[$item->get_id()]['average'] = $average; |
229
|
|
|
// Ranking |
230
|
|
|
/*if (!empty($this->studentList)) { |
231
|
|
|
$invalidateRanking = true; |
232
|
|
|
foreach ($this->studentList as $user) { |
233
|
|
|
$score = $this->datagen->build_result_column( |
234
|
|
|
$user['user_id'], |
235
|
|
|
$item, |
236
|
|
|
false, |
237
|
|
|
true |
238
|
|
|
); |
239
|
|
|
if (!empty($score['score'])) { |
240
|
|
|
$invalidateRanking = false; |
241
|
|
|
} |
242
|
|
|
$rankingStudentList[$user['user_id']] = $score['score'][0]; |
243
|
|
|
$defaultData[$item->get_id()]['ranking'] = $rankingStudentList; |
244
|
|
|
$defaultData[$item->get_id()]['ranking_invalidate'] = $invalidateRanking; |
245
|
|
|
} |
246
|
|
|
}*/ |
247
|
|
|
break; |
248
|
|
|
default: |
249
|
|
|
// Best |
250
|
|
|
$best = $this->datagen->buildBestResultColumn($item); |
251
|
|
|
$defaultData[$item->get_id()]['best'] = $best; |
252
|
|
|
|
253
|
|
|
// Average |
254
|
|
|
$average = $this->datagen->buildAverageResultColumn($item); |
255
|
|
|
$defaultData[$item->get_id()]['average'] = $average; |
256
|
|
|
|
257
|
|
|
// Ranking |
258
|
|
|
if (!empty($this->studentList)) { |
259
|
|
|
$invalidateRanking = true; |
260
|
|
|
foreach ($this->studentList as $user) { |
261
|
|
|
$score = $this->datagen->build_result_column( |
262
|
|
|
$user['user_id'], |
263
|
|
|
$item, |
264
|
|
|
false, |
265
|
|
|
true |
266
|
|
|
); |
267
|
|
|
if (!empty($score['score'])) { |
268
|
|
|
$invalidateRanking = false; |
269
|
|
|
} |
270
|
|
|
$rankingStudentList[$user['user_id']] = $score['score'][0]; |
271
|
|
|
$defaultData[$item->get_id()]['ranking'] = $rankingStudentList; |
272
|
|
|
$defaultData[$item->get_id()]['ranking_invalidate'] = $invalidateRanking; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
break; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
Session::write($this->getPreloadDataKey(), $defaultData); |
279
|
|
|
} else { |
280
|
|
|
$defaultData = $defaultDataFromSession; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
return $defaultData; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Function used by SortableTable to generate the data to display. |
288
|
|
|
* |
289
|
|
|
* @param int $from |
290
|
|
|
* @param int $per_page |
291
|
|
|
* @param int $column |
292
|
|
|
* @param string $direction |
293
|
|
|
* @param int $sort |
294
|
|
|
* |
295
|
|
|
* @return array|mixed |
296
|
|
|
*/ |
297
|
|
|
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) |
298
|
|
|
{ |
299
|
|
|
//variables load in index.php |
300
|
|
|
global $certificate_min_score; |
301
|
|
|
|
302
|
|
|
$isAllowedToEdit = api_is_allowed_to_edit(); |
303
|
|
|
$hideLinkForStudent = api_get_configuration_value('gradebook_hide_link_to_item_for_student') ?? false; |
304
|
|
|
// determine sorting type |
305
|
|
|
$col_adjust = $isAllowedToEdit ? 1 : 0; |
306
|
|
|
// By id |
307
|
|
|
$this->column = 5; |
308
|
|
|
|
309
|
|
|
switch ($this->column) { |
310
|
|
|
// Type |
311
|
|
|
case 0 + $col_adjust: |
312
|
|
|
$sorting = GradebookDataGenerator::GDG_SORT_TYPE; |
313
|
|
|
break; |
314
|
|
|
case 1 + $col_adjust: |
315
|
|
|
$sorting = GradebookDataGenerator::GDG_SORT_NAME; |
316
|
|
|
break; |
317
|
|
|
case 2 + $col_adjust: |
318
|
|
|
$sorting = GradebookDataGenerator::GDG_SORT_DESCRIPTION; |
319
|
|
|
break; |
320
|
|
|
case 3 + $col_adjust: |
321
|
|
|
$sorting = GradebookDataGenerator::GDG_SORT_WEIGHT; |
322
|
|
|
break; |
323
|
|
|
case 4 + $col_adjust: |
324
|
|
|
$sorting = GradebookDataGenerator::GDG_SORT_DATE; |
325
|
|
|
break; |
326
|
|
|
case 5 + $col_adjust: |
327
|
|
|
$sorting = GradebookDataGenerator::GDG_SORT_ID; |
328
|
|
|
break; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
if ('DESC' === $this->direction) { |
332
|
|
|
$sorting |= GradebookDataGenerator::GDG_SORT_DESC; |
333
|
|
|
} else { |
334
|
|
|
$sorting |= GradebookDataGenerator::GDG_SORT_ASC; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
// Status of user in course. |
338
|
|
|
$user_id = $this->userId; |
339
|
|
|
$course_code = api_get_course_id(); |
340
|
|
|
$session_id = api_get_session_id(); |
341
|
|
|
|
342
|
|
|
$statusToFilter = 0; |
343
|
|
|
if (empty($session_id)) { |
344
|
|
|
$statusToFilter = STUDENT; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
if (empty($this->studentList) && $this->loadStats) { |
348
|
|
|
$studentList = CourseManager::get_user_list_from_course_code( |
349
|
|
|
$course_code, |
350
|
|
|
$session_id, |
351
|
|
|
null, |
352
|
|
|
null, |
353
|
|
|
$statusToFilter |
354
|
|
|
); |
355
|
|
|
$this->studentList = $studentList; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
$this->datagen->userId = $this->userId; |
359
|
|
|
$data_array = $this->datagen->get_data( |
360
|
|
|
$sorting, |
361
|
|
|
$from, |
362
|
|
|
$this->per_page, |
363
|
|
|
false, |
364
|
|
|
$this->studentList, |
365
|
|
|
$this->loadStats |
366
|
|
|
); |
367
|
|
|
|
368
|
|
|
// generate the data to display |
369
|
|
|
$sortable_data = []; |
370
|
|
|
$weight_total_links = 0; |
371
|
|
|
$main_cat = Category::load( |
372
|
|
|
null, |
373
|
|
|
null, |
374
|
|
|
$course_code, |
375
|
|
|
null, |
376
|
|
|
null, |
377
|
|
|
$session_id, |
378
|
|
|
'ORDER BY id' |
379
|
|
|
); |
380
|
|
|
|
381
|
|
|
$total_categories_weight = 0; |
382
|
|
|
$scoredisplay = ScoreDisplay::instance(); |
383
|
|
|
$totalBest = [0, 0]; |
384
|
|
|
$totalAverage = [0, 0]; |
385
|
|
|
|
386
|
|
|
$type = 'detail'; |
387
|
|
|
if ($this->exportToPdf) { |
388
|
|
|
$type = 'simple'; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
$model = ExerciseLib::getCourseScoreModel(); |
392
|
|
|
$userExerciseScoreInCategory = api_get_configuration_value( |
393
|
|
|
'gradebook_use_exercise_score_settings_in_categories' |
394
|
|
|
); |
395
|
|
|
$useExerciseScoreInTotal = api_get_configuration_value('gradebook_use_exercise_score_settings_in_total'); |
396
|
|
|
$course_code = api_get_course_id(); |
397
|
|
|
$session_id = api_get_session_id(); |
398
|
|
|
$defaultData = Session::read($this->getPreloadDataKey()); |
399
|
|
|
$settings = api_get_configuration_value('gradebook_pdf_export_settings'); |
400
|
|
|
$showWeight = true; |
401
|
|
|
if ($this->exportToPdf && isset($settings['hide_score_weight']) && $settings['hide_score_weight']) { |
402
|
|
|
$showWeight = false; |
403
|
|
|
} |
404
|
|
|
$totalAverageList = []; |
405
|
|
|
// Categories. |
406
|
|
|
if (!empty($data_array)) { |
407
|
|
|
foreach ($data_array as $data) { |
408
|
|
|
// list of items inside the gradebook (exercises, lps, forums, etc) |
409
|
|
|
$row = []; |
410
|
|
|
/** @var AbstractLink $item */ |
411
|
|
|
$item = $data[0]; |
412
|
|
|
// If the item is invisible, wrap it in a span with class invisible |
413
|
|
|
$invisibility_span_open = $isAllowedToEdit && $item->is_visible() == '0' ? '<span class="text-muted">' : ''; |
414
|
|
|
$invisibility_span_close = $isAllowedToEdit && $item->is_visible() == '0' ? '</span>' : ''; |
415
|
|
|
|
416
|
|
|
if ($this->teacherView) { |
417
|
|
|
if (false == $this->exportToPdf) { |
418
|
|
|
$row[] = $this->build_id_column($item); |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
// Type. |
423
|
|
|
$row[] = $this->build_type_column($item); |
424
|
|
|
|
425
|
|
|
// Name. |
426
|
|
|
if ('Category' === get_class($item)) { |
427
|
|
|
$row[] = $invisibility_span_open. |
428
|
|
|
'<strong>'.Security::remove_XSS($item->get_name()).'</strong>'.$invisibility_span_close; |
429
|
|
|
$main_categories[$item->get_id()]['name'] = $item->get_name(); |
430
|
|
|
} else { |
431
|
|
|
|
432
|
|
|
// If the item type is 'Evaluation', or the user is not a student, |
433
|
|
|
// or 'gradebook_hide_link_to_item_for_student' it's true, make links |
434
|
|
|
if ($item->get_item_type() === 'E' || $isAllowedToEdit || !$hideLinkForStudent) { |
435
|
|
|
$name = Security::remove_XSS($this->build_name_link($item, $type)); |
436
|
|
|
} else { |
437
|
|
|
$name = Security::remove_XSS( |
438
|
|
|
$item->get_name().' '.Display::label($item->get_type_name(), 'info') |
439
|
|
|
); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
$row[] = $invisibility_span_open.$name.$invisibility_span_close; |
443
|
|
|
$main_categories[$item->get_id()]['name'] = $name; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
$this->dataForGraph['categories'][] = $item->get_name(); |
447
|
|
|
$main_categories[$item->get_id()]['weight'] = $item->get_weight(); |
448
|
|
|
$total_categories_weight += $item->get_weight(); |
449
|
|
|
|
450
|
|
|
// Description. |
451
|
|
|
if (false == $this->exportToPdf) { |
452
|
|
|
$row[] = $invisibility_span_open.$data[2].$invisibility_span_close; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
// Weight. |
456
|
|
|
$weight = $scoredisplay->display_score( |
457
|
|
|
[ |
458
|
|
|
$data['3'], |
459
|
|
|
$this->currentcat->get_weight(), |
460
|
|
|
], |
461
|
|
|
SCORE_SIMPLE, |
462
|
|
|
SCORE_BOTH, |
463
|
|
|
true |
464
|
|
|
); |
465
|
|
|
|
466
|
|
|
if ($showWeight) { |
467
|
|
|
if ($this->teacherView) { |
468
|
|
|
$row[] = $invisibility_span_open. |
469
|
|
|
Display::tag('p', $weight, ['class' => 'score']). |
470
|
|
|
$invisibility_span_close; |
471
|
|
|
} else { |
472
|
|
|
$row[] = $invisibility_span_open.$weight.$invisibility_span_close; |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
$category_weight = $item->get_weight(); |
477
|
|
|
if ($this->teacherView) { |
478
|
|
|
$weight_total_links += $data[3]; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
// Edit (for admins). |
482
|
|
|
if ($this->teacherView) { |
483
|
|
|
$cat = new Category(); |
484
|
|
|
$show_message = $cat->show_message_resource_delete($item->get_course_code()); |
485
|
|
|
if ($show_message === false) { |
486
|
|
|
$row[] = $this->build_edit_column($item); |
487
|
|
|
} |
488
|
|
|
} else { |
489
|
|
|
// Students get the results and certificates columns |
490
|
|
|
$value_data = isset($data[4]) ? $data[4] : null; |
491
|
|
|
$best = isset($data['best']) ? $data['best'] : null; |
492
|
|
|
$average = isset($data['average']) ? $data['average'] : null; |
493
|
|
|
$ranking = isset($data['ranking']) ? $data['ranking'] : null; |
494
|
|
|
|
495
|
|
|
$totalResult = [ |
496
|
|
|
$data['result_score'][0] ?? null, |
497
|
|
|
$data['result_score'][1] ?? null, |
498
|
|
|
]; |
499
|
|
|
|
500
|
|
|
if (empty($model)) { |
501
|
|
|
$totalBest = [ |
502
|
|
|
$scoredisplay->format_score($totalBest[0] + (empty($data['best_score'][0]) ? 0 : $data['best_score'][0])), |
503
|
|
|
$scoredisplay->format_score($totalBest[1] + (empty($data['best_score'][1]) ? 0 : $data['best_score'][1])), |
504
|
|
|
]; |
505
|
|
|
$totalAverage = [0, 0]; |
506
|
|
|
if (isset($data['average_score']) && !empty($data['average_score'])) { |
507
|
|
|
$totalAverage = [ |
508
|
|
|
$data['average_score'][0], |
509
|
|
|
$data['average_score'][1], |
510
|
|
|
]; |
511
|
|
|
} |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
// Score |
515
|
|
|
if (empty($model)) { |
516
|
|
|
$row[] = $value_data; |
517
|
|
|
} else { |
518
|
|
|
$row[] = ExerciseLib::show_score( |
519
|
|
|
$data['result_score'][0], |
520
|
|
|
$data['result_score'][1] |
521
|
|
|
); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
$totalAverageList[$item->get_id()] = $totalAverage; |
525
|
|
|
$mode = SCORE_AVERAGE; |
526
|
|
|
if ($userExerciseScoreInCategory) { |
527
|
|
|
$mode = SCORE_SIMPLE; |
528
|
|
|
$result = ExerciseLib::convertScoreToPlatformSetting($totalAverage[0], $totalAverage[1]); |
529
|
|
|
$totalAverage[0] = $result['score']; |
530
|
|
|
$totalAverage[1] = $result['weight']; |
531
|
|
|
|
532
|
|
|
$result = ExerciseLib::convertScoreToPlatformSetting($totalResult[0], $totalResult[1]); |
533
|
|
|
$totalResult[0] = $result['score']; |
534
|
|
|
$totalResult[1] = $result['weight']; |
535
|
|
|
|
536
|
|
|
$result = ExerciseLib::convertScoreToPlatformSetting( |
537
|
|
|
$data['result_score'][0], |
538
|
|
|
$data['result_score'][1] |
539
|
|
|
); |
540
|
|
|
$data['my_result_no_float'][0] = $result['score']; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
$totalResultAverageValue = strip_tags( |
544
|
|
|
$scoredisplay->display_score($totalResult, $mode, null, false, false, true) |
545
|
|
|
); |
546
|
|
|
$totalAverageValue = strip_tags( |
547
|
|
|
$scoredisplay->display_score($totalAverage, $mode, null, false, false, true) |
548
|
|
|
); |
549
|
|
|
|
550
|
|
|
$this->dataForGraph['my_result'][] = floatval($totalResultAverageValue); |
551
|
|
|
$this->dataForGraph['average'][] = floatval($totalAverageValue); |
552
|
|
|
$this->dataForGraph['my_result_no_float'][] = $data['result_score'][0] ?? null; |
553
|
|
|
|
554
|
|
|
if (empty($model)) { |
555
|
|
|
// Ranking |
556
|
|
|
if (in_array(1, $this->loadStats)) { |
557
|
|
|
$row[] = $ranking; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
// Best |
561
|
|
|
if (in_array(2, $this->loadStats)) { |
562
|
|
|
$row[] = $best; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
// Average |
566
|
|
|
if (in_array(3, $this->loadStats)) { |
567
|
|
|
$row[] = $average; |
568
|
|
|
} |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
if ('Category' === get_class($item)) { |
572
|
|
|
if (false == $this->exportToPdf) { |
573
|
|
|
$row[] = $this->build_edit_column($item); |
574
|
|
|
} |
575
|
|
|
} |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
// Category added. |
579
|
|
|
$sortable_data[] = $row; |
580
|
|
|
|
581
|
|
|
// Loading children |
582
|
|
|
if ('Category' === get_class($item)) { |
583
|
|
|
$parent_id = $item->get_id(); |
584
|
|
|
$cats = Category::load( |
585
|
|
|
$parent_id, |
586
|
|
|
null, |
587
|
|
|
null, |
588
|
|
|
null, |
589
|
|
|
null, |
590
|
|
|
null |
591
|
|
|
); |
592
|
|
|
|
593
|
|
|
if (isset($cats[0])) { |
594
|
|
|
/** @var Category $subCategory */ |
595
|
|
|
$subCategory = $cats[0]; |
596
|
|
|
$allcat = $subCategory->get_subcategories($this->userId, $course_code, $session_id); |
597
|
|
|
$alleval = $subCategory->get_evaluations($this->userId); |
598
|
|
|
$alllink = $subCategory->get_links($this->userId); |
599
|
|
|
|
600
|
|
|
$sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); |
601
|
|
|
$sub_cat_info->exportToPdf = $this->exportToPdf; |
602
|
|
|
$sub_cat_info->preLoadDataKey = $this->getPreloadDataKey(); |
603
|
|
|
$sub_cat_info->userId = $user_id; |
604
|
|
|
|
605
|
|
|
$data_array2 = $sub_cat_info->get_data( |
606
|
|
|
$sorting, |
607
|
|
|
$from, |
608
|
|
|
$this->per_page, |
609
|
|
|
false, |
610
|
|
|
$this->studentList |
611
|
|
|
); |
612
|
|
|
$total_weight = 0; |
613
|
|
|
|
614
|
|
|
// Links. |
615
|
|
|
foreach ($data_array2 as $data) { |
616
|
|
|
$row = []; |
617
|
|
|
$item = $data[0]; |
618
|
|
|
// if the item is invisible, wrap it in a span with class invisible |
619
|
|
|
$invisibility_span_open = $isAllowedToEdit && $item->is_visible() == '0' ? '<span class="text-muted">' : ''; |
620
|
|
|
$invisibility_span_close = $isAllowedToEdit && $item->is_visible() == '0' ? '</span>' : ''; |
621
|
|
|
|
622
|
|
|
if (isset($item)) { |
623
|
|
|
$main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name(); |
624
|
|
|
$main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight(); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
if ($this->teacherView) { |
628
|
|
|
if (false == $this->exportToPdf) { |
629
|
|
|
$row[] = $this->build_id_column($item); |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
// Type |
634
|
|
|
$row[] = $this->build_type_column($item, ['style' => 'padding-left:5px']); |
635
|
|
|
// Name. |
636
|
|
|
$row[] = $invisibility_span_open.' '. |
637
|
|
|
Security::remove_XSS($this->build_name_link($item, $type, 4)).$invisibility_span_close; |
638
|
|
|
|
639
|
|
|
// Description. |
640
|
|
|
if (false == $this->exportToPdf) { |
641
|
|
|
$row[] = $invisibility_span_open.$data[2].$invisibility_span_close; |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
$weight = $data[3]; |
645
|
|
|
$total_weight += $weight; |
646
|
|
|
|
647
|
|
|
// Weight |
648
|
|
|
if ($showWeight) { |
649
|
|
|
$row[] = $invisibility_span_open.$weight.$invisibility_span_close; |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
// Admins get an edit column. |
653
|
|
|
if (api_is_allowed_to_edit(null, true) && |
654
|
|
|
isset($_GET['user_id']) == false && |
655
|
|
|
(isset($_GET['action']) && $_GET['action'] != 'export_all' || !isset($_GET['action'])) |
656
|
|
|
) { |
657
|
|
|
$cat = new Category(); |
658
|
|
|
$show_message = $cat->show_message_resource_delete($item->get_course_code()); |
659
|
|
|
if ($show_message === false) { |
660
|
|
|
if ($this->exportToPdf == false) { |
661
|
|
|
$row[] = $this->build_edit_column($item); |
662
|
|
|
} |
663
|
|
|
} |
664
|
|
|
} else { |
665
|
|
|
// Students get the results and certificates columns |
666
|
|
|
$eval_n_links = array_merge($alleval, $alllink); |
667
|
|
|
if (count($eval_n_links) > 0) { |
668
|
|
|
$value_data = isset($data[4]) ? $data[4] : null; |
669
|
|
|
if (!is_null($value_data)) { |
670
|
|
|
// Result |
671
|
|
|
$row[] = $value_data; |
672
|
|
|
$best = isset($data['best']) ? $data['best'] : null; |
673
|
|
|
$average = isset($data['average']) ? $data['average'] : null; |
674
|
|
|
$ranking = isset($data['ranking']) ? $data['ranking'] : null; |
675
|
|
|
if (empty($model)) { |
676
|
|
|
// Ranking |
677
|
|
|
if (in_array(1, $this->loadStats)) { |
678
|
|
|
$row[] = $ranking; |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
// Best |
682
|
|
|
if (in_array(2, $this->loadStats)) { |
683
|
|
|
$row[] = $best; |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
// Average |
687
|
|
|
if (in_array(3, $this->loadStats)) { |
688
|
|
|
$row[] = $average; |
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
} |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
if (!empty($cats)) { |
695
|
|
|
if (false == $this->exportToPdf) { |
696
|
|
|
$row[] = null; |
697
|
|
|
} |
698
|
|
|
} |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
if (false == $this->exportToPdf) { |
702
|
|
|
$row['child_of'] = $parent_id; |
703
|
|
|
} |
704
|
|
|
$sortable_data[] = $row; |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
// "Warning row" |
708
|
|
|
if (!empty($data_array)) { |
709
|
|
|
if ($this->teacherView) { |
710
|
|
|
// Compare the category weight to the sum of all weights inside the category |
711
|
|
|
if (intval($total_weight) == $category_weight) { |
712
|
|
|
$label = null; |
713
|
|
|
$total = GradebookUtils::score_badges( |
714
|
|
|
[ |
715
|
|
|
$total_weight.' / '.$category_weight, |
716
|
|
|
'100', |
717
|
|
|
] |
718
|
|
|
); |
719
|
|
|
} else { |
720
|
|
|
$label = Display::return_icon( |
721
|
|
|
'warning.png', |
722
|
|
|
sprintf(get_lang('TotalWeightMustBeX'), $category_weight) |
723
|
|
|
); |
724
|
|
|
$total = Display::badge($total_weight.' / '.$category_weight, 'warning'); |
725
|
|
|
} |
726
|
|
|
$row = [ |
727
|
|
|
null, |
728
|
|
|
null, |
729
|
|
|
" <h5>".get_lang('SubTotal').'</h5>', |
730
|
|
|
null, |
731
|
|
|
$total.' '.$label, |
732
|
|
|
'child_of' => $parent_id, |
733
|
|
|
]; |
734
|
|
|
$sortable_data[] = $row; |
735
|
|
|
} |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
} |
739
|
|
|
} |
740
|
|
|
} //end looping categories |
741
|
|
|
|
742
|
|
|
$main_weight = 0; |
743
|
|
|
if (count($main_cat) > 1) { |
744
|
|
|
/** @var Category $myCat */ |
745
|
|
|
foreach ($main_cat as $myCat) { |
746
|
|
|
$myParentId = $myCat->get_parent_id(); |
747
|
|
|
if (0 == $myParentId) { |
748
|
|
|
$main_weight = (int) $myCat->get_weight(); |
749
|
|
|
} |
750
|
|
|
} |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
if ($this->teacherView) { |
754
|
|
|
// Total for teacher. |
755
|
|
|
if (count($main_cat) > 1) { |
756
|
|
|
if (intval($total_categories_weight) == $main_weight) { |
757
|
|
|
$total = GradebookUtils::score_badges( |
758
|
|
|
[ |
759
|
|
|
$total_categories_weight.' / '.$main_weight, |
760
|
|
|
'100', |
761
|
|
|
] |
762
|
|
|
); |
763
|
|
|
} else { |
764
|
|
|
$total = Display::badge($total_categories_weight.' / '.$main_weight, 'warning'); |
765
|
|
|
} |
766
|
|
|
$row = [ |
767
|
|
|
null, |
768
|
|
|
null, |
769
|
|
|
'<strong>'.get_lang('Total').'</strong>', |
770
|
|
|
null, |
771
|
|
|
$total, |
772
|
|
|
]; |
773
|
|
|
$sortable_data[] = $row; |
774
|
|
|
} |
775
|
|
|
} else { |
776
|
|
|
$showPercentage = false === $this->datagen->hidePercentage; |
777
|
|
|
// Total for student. |
778
|
|
|
if (count($main_cat) > 1) { |
779
|
|
|
$main_weight = (int) $main_cat[0]->get_weight(); |
780
|
|
|
$global = null; |
781
|
|
|
$average = null; |
782
|
|
|
$myTotal = 0; |
783
|
|
|
if (!empty($this->dataForGraph)) { |
784
|
|
|
foreach ($this->dataForGraph['my_result_no_float'] as $result) { |
785
|
|
|
$myTotal += $result; |
786
|
|
|
} |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
$totalResult[0] = $myTotal; |
790
|
|
|
// Overwrite main weight |
791
|
|
|
$totalResult[1] = $main_weight; |
792
|
|
|
|
793
|
|
|
if (!empty($model)) { |
794
|
|
|
$totalResult = ExerciseLib::show_score( |
795
|
|
|
$totalResult[0], |
796
|
|
|
$totalResult[1] |
797
|
|
|
); |
798
|
|
|
} else { |
799
|
|
|
$totalResult = $scoredisplay->display_score( |
800
|
|
|
$totalResult, |
801
|
|
|
SCORE_DIV, |
802
|
|
|
null, |
803
|
|
|
false, |
804
|
|
|
false, |
805
|
|
|
true |
806
|
|
|
); |
807
|
|
|
|
808
|
|
|
if ($useExerciseScoreInTotal) { |
809
|
|
|
$totalResult = ExerciseLib::show_score($myTotal, $main_weight, false); |
810
|
|
|
} |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
$row = [ |
814
|
|
|
null, |
815
|
|
|
'<strong>'.get_lang('Total').'</strong>', |
816
|
|
|
]; |
817
|
|
|
|
818
|
|
|
if (!$this->exportToPdf) { |
819
|
|
|
$row[] = null; |
820
|
|
|
} |
821
|
|
|
|
822
|
|
|
if ($showWeight) { |
823
|
|
|
$row[] = $main_weight; |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
$row[] = $totalResult; |
827
|
|
|
$categoryId = $main_cat[0]->get_id(); |
828
|
|
|
|
829
|
|
|
if (empty($model)) { |
830
|
|
|
if (in_array(1, $this->loadStats)) { |
831
|
|
|
if (isset($defaultData[$categoryId]) && isset($defaultData[$categoryId]['ranking'])) { |
832
|
|
|
$totalRanking = $defaultData[$categoryId]['ranking']; |
833
|
|
|
$invalidateRanking = $defaultData[$categoryId]['ranking_invalidate']; |
834
|
|
|
$average = 0; |
835
|
|
|
foreach ($totalRanking as $ranking) { |
836
|
|
|
$average += $ranking; |
837
|
|
|
} |
838
|
|
|
} else { |
839
|
|
|
$totalRanking = []; |
840
|
|
|
$invalidateRanking = true; |
841
|
|
|
$average = 0; |
842
|
|
|
$main_cat[0]->setStudentList($this->studentList); |
843
|
|
|
foreach ($this->studentList as $student) { |
844
|
|
|
$score = $main_cat[0]->calc_score( |
845
|
|
|
$student['user_id'], |
846
|
|
|
null, |
847
|
|
|
$course_code, |
848
|
|
|
$session_id |
849
|
|
|
); |
850
|
|
|
if (!empty($score[0])) { |
851
|
|
|
$invalidateRanking = false; |
852
|
|
|
} |
853
|
|
|
$totalRanking[$student['user_id']] = $score[0]; |
854
|
|
|
$average += $score[0]; |
855
|
|
|
} |
856
|
|
|
$defaultData[$categoryId]['ranking'] = $totalRanking; |
857
|
|
|
$defaultData[$categoryId]['ranking_invalidate'] = $invalidateRanking; |
858
|
|
|
Session::write($this->getPreloadDataKey(), $defaultData); |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
$totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking); |
862
|
|
|
$totalRanking = $scoredisplay->display_score( |
863
|
|
|
$totalRanking, |
864
|
|
|
SCORE_DIV, |
865
|
|
|
SCORE_BOTH, |
866
|
|
|
true, |
867
|
|
|
true, |
868
|
|
|
true |
869
|
|
|
); |
870
|
|
|
|
871
|
|
|
if ($invalidateRanking) { |
872
|
|
|
$totalRanking = null; |
873
|
|
|
} |
874
|
|
|
$row[] = $totalRanking; |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
if (in_array(2, $this->loadStats)) { |
878
|
|
|
if (isset($defaultData[$categoryId]) && isset($defaultData[$categoryId]['best'])) { |
879
|
|
|
$totalBest = $defaultData[$categoryId]['best']; |
880
|
|
|
} else { |
881
|
|
|
// Overwrite main weight |
882
|
|
|
$totalBest[1] = $main_weight; |
883
|
|
|
$defaultData[$categoryId]['best'] = $totalBest; |
884
|
|
|
} |
885
|
|
|
|
886
|
|
|
if ($useExerciseScoreInTotal) { |
887
|
|
|
if (isset($totalBest['score'])) { |
888
|
|
|
$totalBestScore = $totalBest['score']; |
889
|
|
|
} else { |
890
|
|
|
$totalBestScore = $totalBest; |
891
|
|
|
} |
892
|
|
|
|
893
|
|
|
$totalBest = ExerciseLib::show_score($totalBestScore[0], $totalBestScore[1], $showPercentage); |
894
|
|
|
} else { |
895
|
|
|
$totalBest = $scoredisplay->display_score( |
896
|
|
|
$totalBest, |
897
|
|
|
SCORE_DIV, |
898
|
|
|
SCORE_BOTH, |
899
|
|
|
true, |
900
|
|
|
false, |
901
|
|
|
true |
902
|
|
|
); |
903
|
|
|
} |
904
|
|
|
$row[] = $totalBest; |
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
if (in_array(3, $this->loadStats)) { |
908
|
|
|
if (isset($defaultData[$categoryId]) && isset($defaultData[$categoryId]['average'])) { |
909
|
|
|
$totalAverage = $defaultData[$categoryId]['average']; |
910
|
|
|
} else { |
911
|
|
|
$averageWeight = 0; |
912
|
|
|
$categoryAverage = 0; |
913
|
|
|
foreach ($totalAverageList as $averageScore) { |
914
|
|
|
$categoryAverage += $averageScore[0]; |
915
|
|
|
$averageWeight += $averageScore[1]; |
916
|
|
|
} |
917
|
|
|
$categoryAverage = $categoryAverage / count($totalAverageList); |
918
|
|
|
$averageWeight = $averageWeight / count($totalAverageList); |
919
|
|
|
|
920
|
|
|
// Overwrite main weight |
921
|
|
|
//$totalAverage[0] = $average / count($this->studentList); |
922
|
|
|
//$totalAverage[1] = $main_weight; |
923
|
|
|
$totalAverage[0] = $categoryAverage; |
924
|
|
|
$totalAverage[1] = $averageWeight; |
925
|
|
|
//$defaultData[$categoryId]['average'] = $totalBest; |
926
|
|
|
} |
927
|
|
|
|
928
|
|
|
if ($useExerciseScoreInTotal) { |
929
|
|
|
if (isset($totalAverage['score'])) { |
930
|
|
|
$totalAverageScore = $totalAverage['score']; |
931
|
|
|
} else { |
932
|
|
|
$totalAverageScore = $totalAverage; |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
$totalAverage = ExerciseLib::show_score($totalAverageScore[0], $totalAverageScore[1], $showPercentage); |
936
|
|
|
} else { |
937
|
|
|
$totalAverage = $scoredisplay->display_score( |
938
|
|
|
$totalAverage, |
939
|
|
|
SCORE_DIV, |
940
|
|
|
SCORE_BOTH, |
941
|
|
|
true, |
942
|
|
|
false, |
943
|
|
|
true |
944
|
|
|
); |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
$row[] = $totalAverage; |
948
|
|
|
} |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
if (!empty($row)) { |
952
|
|
|
$sortable_data[] = $row; |
953
|
|
|
} |
954
|
|
|
} |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
Session::write('default_data', $defaultData); |
958
|
|
|
|
959
|
|
|
// Warning messages |
960
|
|
|
$view = isset($_GET['view']) ? $_GET['view'] : null; |
961
|
|
|
if ($this->teacherView) { |
962
|
|
|
if (isset($_GET['selectcat']) && |
963
|
|
|
$_GET['selectcat'] > 0 && |
964
|
|
|
$view !== 'presence' |
965
|
|
|
) { |
966
|
|
|
$id_cat = (int) $_GET['selectcat']; |
967
|
|
|
$category = Category::load($id_cat); |
968
|
|
|
$weight_category = (int) $this->build_weight($category[0]); |
969
|
|
|
$course_code = $this->build_course_code($category[0]); |
970
|
|
|
$weight_total_links = round($weight_total_links); |
971
|
|
|
|
972
|
|
|
if ($weight_total_links > $weight_category || |
973
|
|
|
$weight_total_links < $weight_category || |
974
|
|
|
$weight_total_links > $weight_category |
975
|
|
|
) { |
976
|
|
|
$warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); |
977
|
|
|
$modify_icons = |
978
|
|
|
'<a |
979
|
|
|
href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'&id_session='.api_get_session_id().'">'. |
980
|
|
|
Display::return_icon('edit.png', $warning_message, [], ICON_SIZE_SMALL).'</a>'; |
981
|
|
|
$warning_message .= $modify_icons; |
982
|
|
|
echo Display::return_message($warning_message, 'warning', false); |
983
|
|
|
} |
984
|
|
|
|
985
|
|
|
$content_html = DocumentManager::replace_user_info_into_html( |
986
|
|
|
api_get_user_id(), |
987
|
|
|
$course_code, |
988
|
|
|
api_get_session_id() |
989
|
|
|
); |
990
|
|
|
|
991
|
|
|
if (!empty($content_html)) { |
992
|
|
|
$new_content = explode('</head>', $content_html['content']); |
993
|
|
|
} |
994
|
|
|
|
995
|
|
|
if (empty($new_content[0])) { |
996
|
|
|
// Set default certificate |
997
|
|
|
$courseData = api_get_course_info($course_code); |
998
|
|
|
DocumentManager::generateDefaultCertificate($courseData); |
999
|
|
|
} |
1000
|
|
|
} |
1001
|
|
|
|
1002
|
|
|
if (empty($_GET['selectcat'])) { |
1003
|
|
|
$categories = Category::load(); |
1004
|
|
|
$weight_categories = $certificate_min_scores = $course_codes = []; |
1005
|
|
|
foreach ($categories as $category) { |
1006
|
|
|
$course_code_category = $this->build_course_code($category); |
1007
|
|
|
if (!empty($course_code)) { |
1008
|
|
|
if ($course_code_category == $course_code) { |
1009
|
|
|
$weight_categories[] = intval($this->build_weight($category)); |
1010
|
|
|
$certificate_min_scores[] = intval($this->build_certificate_min_score($category)); |
1011
|
|
|
$course_codes[] = $course_code; |
1012
|
|
|
break; |
1013
|
|
|
} |
1014
|
|
|
} else { |
1015
|
|
|
$weight_categories[] = intval($this->build_weight($category)); |
1016
|
|
|
$certificate_min_scores[] = intval($this->build_certificate_min_score($category)); |
1017
|
|
|
$course_codes[] = $course_code_category; |
1018
|
|
|
} |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
if (is_array($weight_categories) && |
1022
|
|
|
is_array($certificate_min_scores) && |
1023
|
|
|
is_array($course_codes) |
1024
|
|
|
) { |
1025
|
|
|
$warning_message = ''; |
1026
|
|
|
for ($x = 0; $x < count($weight_categories); $x++) { |
|
|
|
|
1027
|
|
|
$weight_category = intval($weight_categories[$x]); |
1028
|
|
|
$certificate_min_score = intval($certificate_min_scores[$x]); |
1029
|
|
|
$course_code = $course_codes[$x]; |
1030
|
|
|
|
1031
|
|
|
if (empty($certificate_min_score) || |
1032
|
|
|
($certificate_min_score > $weight_category) |
1033
|
|
|
) { |
1034
|
|
|
$warning_message .= $course_code. |
1035
|
|
|
' - '.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan'). |
1036
|
|
|
' '.$weight_category.'<br />'; |
1037
|
|
|
} |
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
if (!empty($warning_message)) { |
1041
|
|
|
echo Display::return_message($warning_message, 'warning', false); |
1042
|
|
|
} |
1043
|
|
|
} |
1044
|
|
|
} |
1045
|
|
|
} |
1046
|
|
|
|
1047
|
|
|
return $sortable_data; |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
/** |
1051
|
|
|
* @return string |
1052
|
|
|
*/ |
1053
|
|
|
public function getGraph() |
1054
|
|
|
{ |
1055
|
|
|
$data = $this->getDataForGraph(); |
1056
|
|
|
if (!empty($data) && |
1057
|
|
|
isset($data['categories']) && |
1058
|
|
|
isset($data['my_result']) && |
1059
|
|
|
isset($data['average']) |
1060
|
|
|
) { |
1061
|
|
|
$dataSet = new pData(); |
1062
|
|
|
$dataSet->addPoints($data['my_result'], get_lang('Me')); |
1063
|
|
|
// In order to generate random values |
1064
|
|
|
// $data['average'] = array(rand(0,50), rand(0,50)); |
1065
|
|
|
$dataSet->addPoints($data['average'], get_lang('Average')); |
1066
|
|
|
$dataSet->addPoints($data['categories'], 'categories'); |
1067
|
|
|
$dataSet->setAbscissa('categories'); |
1068
|
|
|
$xSize = 700; |
1069
|
|
|
$ySize = 500; |
1070
|
|
|
$pChart = new pImage($xSize, $ySize, $dataSet); |
1071
|
|
|
/* Turn of Antialiasing */ |
1072
|
|
|
$pChart->Antialias = false; |
1073
|
|
|
|
1074
|
|
|
/* Add a border to the picture */ |
1075
|
|
|
$pChart->drawRectangle( |
1076
|
|
|
0, |
1077
|
|
|
0, |
1078
|
|
|
$xSize - 1, |
1079
|
|
|
$ySize - 1, |
1080
|
|
|
["R" => 0, "G" => 0, "B" => 0] |
1081
|
|
|
); |
1082
|
|
|
$pChart->drawText( |
1083
|
|
|
80, |
1084
|
|
|
16, |
1085
|
|
|
get_lang('Results'), |
1086
|
|
|
["FontSize" => 11, "Align" => TEXT_ALIGN_BOTTOMMIDDLE] |
1087
|
|
|
); |
1088
|
|
|
$pChart->setGraphArea(50, 30, $xSize - 50, $ySize - 70); |
1089
|
|
|
$pChart->setFontProperties( |
1090
|
|
|
[ |
1091
|
|
|
'FontName' => api_get_path(SYS_FONTS_PATH).'Harmattan/Harmattan-Regular.ttf', |
1092
|
|
|
/*'FontName' => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',*/ |
1093
|
|
|
'FontSize' => 10, |
1094
|
|
|
] |
1095
|
|
|
); |
1096
|
|
|
|
1097
|
|
|
/* Draw the scale */ |
1098
|
|
|
$scaleSettings = [ |
1099
|
|
|
"XMargin" => AUTO, |
1100
|
|
|
"YMargin" => 10, |
1101
|
|
|
"Floating" => true, |
1102
|
|
|
"GridR" => 200, |
1103
|
|
|
"GridG" => 200, |
1104
|
|
|
"GridB" => 200, |
1105
|
|
|
"DrawSubTicks" => true, |
1106
|
|
|
"CycleBackground" => true, |
1107
|
|
|
'LabelRotation' => 10, |
1108
|
|
|
]; |
1109
|
|
|
$pChart->drawScale($scaleSettings); |
1110
|
|
|
|
1111
|
|
|
/* Draw the line chart */ |
1112
|
|
|
$pChart->drawLineChart(); |
1113
|
|
|
$pChart->drawPlotChart( |
1114
|
|
|
[ |
1115
|
|
|
"DisplayValues" => true, |
1116
|
|
|
"PlotBorder" => true, |
1117
|
|
|
"BorderSize" => 2, |
1118
|
|
|
"Surrounding" => -60, |
1119
|
|
|
"BorderAlpha" => 80, |
1120
|
|
|
] |
1121
|
|
|
); |
1122
|
|
|
|
1123
|
|
|
/* Write the chart legend */ |
1124
|
|
|
$pChart->drawLegend( |
1125
|
|
|
$xSize - 180, |
1126
|
|
|
9, |
1127
|
|
|
[ |
1128
|
|
|
"Style" => LEGEND_NOBORDER, |
1129
|
|
|
"Mode" => LEGEND_HORIZONTAL, |
1130
|
|
|
"FontR" => 0, |
1131
|
|
|
"FontG" => 0, |
1132
|
|
|
"FontB" => 0, |
1133
|
|
|
] |
1134
|
|
|
); |
1135
|
|
|
|
1136
|
|
|
$cachePath = api_get_path(SYS_ARCHIVE_PATH); |
1137
|
|
|
$myCache = new pCache(['CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)]); |
1138
|
|
|
$chartHash = $myCache->getHash($dataSet); |
1139
|
|
|
|
1140
|
|
|
$myCache->writeToCache($chartHash, $pChart); |
1141
|
|
|
$imgSysPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash; |
1142
|
|
|
$myCache->saveFromCache($chartHash, $imgSysPath); |
1143
|
|
|
$imgWebPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash; |
1144
|
|
|
|
1145
|
|
|
if (file_exists($imgSysPath)) { |
1146
|
|
|
$result = '<br /><div id="contentArea" style="text-align: center;" >'; |
1147
|
|
|
$result .= '<img src="'.$imgWebPath.'" >'; |
1148
|
|
|
$result .= '</div>'; |
1149
|
|
|
|
1150
|
|
|
return $result; |
1151
|
|
|
} |
1152
|
|
|
} |
1153
|
|
|
|
1154
|
|
|
return ''; |
1155
|
|
|
} |
1156
|
|
|
|
1157
|
|
|
public static function getExtraStatsColumnsToDisplay(): array |
1158
|
|
|
{ |
1159
|
|
|
if (api_get_configuration_value('gradebook_enable_best_score') === true) { |
1160
|
|
|
return [2]; |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
$gradebookDisplayExtraStats = api_get_configuration_value('gradebook_display_extra_stats'); |
1164
|
|
|
|
1165
|
|
|
/** @see GradebookTable::$loadStats */ |
1166
|
|
|
return $gradebookDisplayExtraStats['columns'] ?? [1, 2, 3]; |
1167
|
|
|
} |
1168
|
|
|
|
1169
|
|
|
/** |
1170
|
|
|
* @return array |
1171
|
|
|
*/ |
1172
|
|
|
private function getDataForGraph() |
1173
|
|
|
{ |
1174
|
|
|
return $this->dataForGraph; |
1175
|
|
|
} |
1176
|
|
|
|
1177
|
|
|
/** |
1178
|
|
|
* @param $item |
1179
|
|
|
* |
1180
|
|
|
* @return mixed |
1181
|
|
|
*/ |
1182
|
|
|
private function build_certificate_min_score($item) |
1183
|
|
|
{ |
1184
|
|
|
return $item->getCertificateMinScore(); |
1185
|
|
|
} |
1186
|
|
|
|
1187
|
|
|
/** |
1188
|
|
|
* @param $item |
1189
|
|
|
* |
1190
|
|
|
* @return mixed |
1191
|
|
|
*/ |
1192
|
|
|
private function build_weight($item) |
1193
|
|
|
{ |
1194
|
|
|
return $item->get_weight(); |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
/** |
1198
|
|
|
* @param $item |
1199
|
|
|
* |
1200
|
|
|
* @return mixed |
1201
|
|
|
*/ |
1202
|
|
|
private function build_course_code($item) |
1203
|
|
|
{ |
1204
|
|
|
return $item->get_course_code(); |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
/** |
1208
|
|
|
* @param $item |
1209
|
|
|
* |
1210
|
|
|
* @return string |
1211
|
|
|
*/ |
1212
|
|
|
private function build_id_column($item) |
1213
|
|
|
{ |
1214
|
|
|
switch ($item->get_item_type()) { |
1215
|
|
|
// category |
1216
|
|
|
case 'C': |
1217
|
|
|
return 'CATE'.$item->get_id(); |
1218
|
|
|
// evaluation |
1219
|
|
|
case 'E': |
1220
|
|
|
return 'EVAL'.$item->get_id(); |
1221
|
|
|
// link |
1222
|
|
|
case 'L': |
1223
|
|
|
return 'LINK'.$item->get_id(); |
1224
|
|
|
} |
1225
|
|
|
} |
1226
|
|
|
|
1227
|
|
|
/** |
1228
|
|
|
* @param $item |
1229
|
|
|
* @param array $attributes |
1230
|
|
|
* |
1231
|
|
|
* @return string |
1232
|
|
|
*/ |
1233
|
|
|
private function build_type_column($item, $attributes = []) |
1234
|
|
|
{ |
1235
|
|
|
return GradebookUtils::build_type_icon_tag($item->get_icon_name(), $attributes); |
1236
|
|
|
} |
1237
|
|
|
|
1238
|
|
|
/** |
1239
|
|
|
* Generate name column. |
1240
|
|
|
* |
1241
|
|
|
* @param GradebookItem $item |
1242
|
|
|
* @param string $type simple|detail |
1243
|
|
|
* |
1244
|
|
|
* @return string |
1245
|
|
|
*/ |
1246
|
|
|
private function build_name_link($item, $type = 'detail', $spaces = 0) |
1247
|
|
|
{ |
1248
|
|
|
$view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null; |
1249
|
|
|
$categoryId = $item->getCategory()->get_id(); |
1250
|
|
|
|
1251
|
|
|
$cat = new Category(); |
1252
|
|
|
|
1253
|
|
|
switch ($item->get_item_type()) { |
1254
|
|
|
case 'C': |
1255
|
|
|
// Category |
1256
|
|
|
$prms_uri = '?selectcat='.$item->get_id().'&view='.$view; |
1257
|
|
|
$isStudentView = api_is_student_view_active(); |
1258
|
|
|
if (isset($is_student) || $isStudentView) { |
1259
|
|
|
$prms_uri = $prms_uri.'&isStudentView=studentview'; |
1260
|
|
|
} |
1261
|
|
|
$show_message = $cat->show_message_resource_delete($item->get_course_code()); |
1262
|
|
|
|
1263
|
|
|
return ' <a href="'.Category::getUrl().$prms_uri.'">' |
1264
|
|
|
.$item->get_name() |
1265
|
|
|
.'</a>' |
1266
|
|
|
.($item->is_course() ? ' ['.$item->get_course_code().']'.$show_message : ''); |
1267
|
|
|
case 'E': |
1268
|
|
|
// Evaluation |
1269
|
|
|
$course_id = CourseManager::get_course_by_category($categoryId); |
1270
|
|
|
$show_message = $cat->show_message_resource_delete($course_id); |
1271
|
|
|
$skills = $item->getSkillsFromItem(); |
1272
|
|
|
|
1273
|
|
|
// course/platform admin can go to the view_results page |
1274
|
|
|
if (api_is_allowed_to_edit() && $show_message === false) { |
1275
|
|
|
if ($item->get_type() == 'presence') { |
1276
|
|
|
return ' ' |
1277
|
|
|
.'<a href="gradebook_view_result.php?cidReq='.$course_id.'&selecteval='.$item->get_id().'">' |
1278
|
|
|
.$item->get_name() |
1279
|
|
|
.'</a>'; |
1280
|
|
|
} else { |
1281
|
|
|
$extra = Display::label(get_lang('Evaluation')); |
1282
|
|
|
if ('simple' === $type) { |
1283
|
|
|
$extra = ''; |
1284
|
|
|
} |
1285
|
|
|
$extra .= $skills; |
1286
|
|
|
|
1287
|
|
|
return ' ' |
1288
|
|
|
.'<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.$item->get_id().'">' |
1289
|
|
|
.$item->get_name() |
1290
|
|
|
.'</a> '.$extra; |
1291
|
|
|
} |
1292
|
|
|
} elseif (ScoreDisplay::instance()->is_custom() && $show_message === false) { |
1293
|
|
|
// students can go to the statistics page (if custom display enabled) |
1294
|
|
|
return ' ' |
1295
|
|
|
.'<a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.$item->get_id().'">' |
1296
|
|
|
.$item->get_name() |
1297
|
|
|
.'</a>'.$skills; |
1298
|
|
|
} elseif ($show_message === false && !api_is_allowed_to_edit() && !ScoreDisplay::instance()->is_custom()) { |
1299
|
|
|
return ' ' |
1300
|
|
|
.'<a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.$item->get_id().'">' |
1301
|
|
|
.$item->get_name() |
1302
|
|
|
.'</a>'.$skills; |
1303
|
|
|
} else { |
1304
|
|
|
return '['.get_lang('Evaluation').'] '.$item->get_name().$show_message.$skills; |
1305
|
|
|
} |
1306
|
|
|
// no break because of return |
1307
|
|
|
case 'L': |
1308
|
|
|
// Link |
1309
|
|
|
$course_id = CourseManager::get_course_by_category($categoryId); |
1310
|
|
|
$show_message = $cat->show_message_resource_delete($course_id); |
1311
|
|
|
|
1312
|
|
|
$url = $item->get_link(); |
1313
|
|
|
$text = $item->get_name(); |
1314
|
|
|
if (isset($url) && false === $show_message) { |
1315
|
|
|
$text = ' <a href="'.$item->get_link().'">' |
1316
|
|
|
.$item->get_name() |
1317
|
|
|
.'</a>'; |
1318
|
|
|
} |
1319
|
|
|
|
1320
|
|
|
$extra = Display::label($item->get_type_name(), 'info'); |
1321
|
|
|
if ('simple' === $type) { |
1322
|
|
|
$extra = ''; |
1323
|
|
|
} |
1324
|
|
|
$extra .= $item->getSkillsFromItem(); |
1325
|
|
|
$text .= " ".$extra.$show_message; |
1326
|
|
|
|
1327
|
|
|
/*if ($item instanceof ExerciseLink) { |
1328
|
|
|
$spaces = str_repeat(' ', $spaces); |
1329
|
|
|
$text .= '<br /><br />'.$spaces.$item->getLpListToString(); |
1330
|
|
|
}*/ |
1331
|
|
|
|
1332
|
|
|
$cc = $this->currentcat->get_course_code(); |
1333
|
|
|
if (empty($cc)) { |
1334
|
|
|
$text .= ' [<a href="'.api_get_path(REL_COURSE_PATH).$item->get_course_code().'/">'.$item->get_course_code().'</a>]'; |
1335
|
|
|
} |
1336
|
|
|
|
1337
|
|
|
return $text; |
1338
|
|
|
} |
1339
|
|
|
} |
1340
|
|
|
|
1341
|
|
|
/** |
1342
|
|
|
* @param AbstractLink $item |
1343
|
|
|
* |
1344
|
|
|
* @return string|null |
1345
|
|
|
*/ |
1346
|
|
|
private function build_edit_column($item) |
1347
|
|
|
{ |
1348
|
|
|
switch ($item->get_item_type()) { |
1349
|
|
|
case 'C': |
1350
|
|
|
// Category |
1351
|
|
|
return GradebookUtils::build_edit_icons_cat($item, $this->currentcat); |
1352
|
|
|
case 'E': |
1353
|
|
|
// Evaluation |
1354
|
|
|
return GradebookUtils::build_edit_icons_eval($item, $this->currentcat->get_id()); |
1355
|
|
|
case 'L': |
1356
|
|
|
// Link |
1357
|
|
|
return GradebookUtils::build_edit_icons_link($item, $this->currentcat->get_id()); |
1358
|
|
|
} |
1359
|
|
|
} |
1360
|
|
|
} |
1361
|
|
|
|