Issues (2037)

main/gradebook/lib/fe/displaygradebook.php (1 issue)

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * Class DisplayGradebook.
7
 */
8
class DisplayGradebook
9
{
10
    /**
11
     * Displays the header for the result page containing the navigation tree and links.
12
     *
13
     * @param Evaluation $evalobj
14
     * @param int        $selectcat
15
     * @param string     $page
16
     */
17
    public static function display_header_result($evalobj, $selectcat, $page)
18
    {
19
        $header = null;
20
        if (api_is_allowed_to_edit(null, true)) {
21
            $header = '<div class="actions">';
22
            if ('statistics' !== $page) {
23
                $header .= '<a href="'.Category::getUrl().'selectcat='.$selectcat.'">'.
24
                    Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM)
25
                    .'</a>';
26
                if (($evalobj->get_course_code() != null) && !$evalobj->has_results()) {
27
                    $header .= '<a href="gradebook_add_result.php?'.api_get_cidreq().'&selectcat='.$selectcat.'&selecteval='.$evalobj->get_id().'">
28
    				'.Display::return_icon('evaluation_rate.png', get_lang('AddResult'), '', ICON_SIZE_MEDIUM).'</a>';
29
                }
30
31
                if (api_is_platform_admin() || $evalobj->is_locked() == false) {
32
                    $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&import=">'.
33
                        Display::return_icon('import_evaluation.png', get_lang('ImportResult'), '', ICON_SIZE_MEDIUM).'</a>';
34
                }
35
36
                if ($evalobj->has_results()) {
37
                    $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&export=">'.
38
                        Display::return_icon('export_evaluation.png', get_lang('ExportResult'), '', ICON_SIZE_MEDIUM).'</a>';
39
40
                    if (api_is_platform_admin() || $evalobj->is_locked() == false) {
41
                        $header .= '<a href="gradebook_edit_result.php?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'">'.
42
                            Display::return_icon('edit.png', get_lang('EditResult'), '', ICON_SIZE_MEDIUM).'</a>';
43
                        $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&deleteall=" onclick="return confirmationall();">'.
44
                            Display::return_icon('delete.png', get_lang('DeleteResult'), '', ICON_SIZE_MEDIUM).'</a>';
45
                    }
46
                }
47
                $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&print=&selecteval='.$evalobj->get_id().'" target="_blank">'.
48
                    Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
49
            } else {
50
                $header .= '<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '.
51
                    Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM).'</a>';
52
            }
53
            $header .= '</div>';
54
        }
55
56
        $scoredisplay = ScoreDisplay::instance();
57
        $student_score = '';
58
        $average = '';
59
        if ($evalobj->has_results()) {
60
            // TODO this check needed ?
61
            $score = $evalobj->calc_score();
62
            if (null != $score) {
63
                $model = ExerciseLib::getCourseScoreModel();
64
                if (empty($model)) {
65
                    $average = get_lang('Average').' :<b> '.$scoredisplay->display_score($score, SCORE_AVERAGE).'</b>';
66
                    $student_score = $evalobj->calc_score(api_get_user_id());
67
                    $student_score = Display::tag(
68
                        'h3',
69
                        get_lang('Score').': '.$scoredisplay->display_score($student_score, SCORE_DIV_PERCENT)
70
                    );
71
72
                    $allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts');
73
                    if ($allowMultipleAttempts) {
74
                        $results = Result::load(null, api_get_user_id(), $evalobj->get_id());
75
                        if (!empty($results)) {
76
                            /** @var Result $resultData */
77
                            foreach ($results as $resultData) {
78
                                $student_score .= ResultTable::getResultAttemptTable($resultData);
79
                            }
80
                        }
81
                    }
82
                }
83
            }
84
        }
85
86
        $description = '';
87
        if ('' == !$evalobj->get_description()) {
88
            $description = get_lang('Description').' :<b> '.Security::remove_XSS($evalobj->get_description()).'</b><br>';
89
        }
90
91
        if ($evalobj->get_course_code() == null) {
92
            $course = get_lang('CourseIndependent');
93
        } else {
94
            $course = CourseManager::getCourseNameFromCode($evalobj->get_course_code());
95
        }
96
97
        $evalinfo = '<table width="100%" border="0"><tr><td>';
98
        $evalinfo .= '<h2>'.Security::remove_XSS($evalobj->get_name()).'</h2><hr>';
99
        $evalinfo .= $description;
100
        $evalinfo .= get_lang('Course').' :<b> '.$course.'</b><br />';
101
        if (empty($model)) {
102
            $evalinfo .= get_lang('QualificationNumeric').' :<b> '.$evalobj->get_max().'</b><br>'.$average;
103
        }
104
105
        if (!api_is_allowed_to_edit()) {
106
            $evalinfo .= $student_score;
107
        }
108
109
        if (!$evalobj->has_results()) {
110
            $evalinfo .= '<br /><i>'.get_lang('NoResultsInEvaluation').'</i>';
111
        }
112
113
        if ($page != 'statistics') {
114
            if (api_is_allowed_to_edit(null, true)) {
115
                $evalinfo .= '<br /><a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '.
116
                    Display::return_icon(
117
                        'statistics.png',
118
                        get_lang('ViewStatistics'),
119
                        '',
120
                        ICON_SIZE_MEDIUM
121
                    ).'</a>';
122
            }
123
        }
124
        $evalinfo .= '</td><td>'.
125
            Display::return_icon(
126
                'tutorial.gif',
127
                '',
128
                ['style' => 'float:right; position:relative;']
129
            )
130
            .'</td></table>';
131
        echo $evalinfo;
132
        echo $header;
133
    }
134
135
    /**
136
     * Displays the header for the flatview page containing filters.
137
     *
138
     * @param $catobj
139
     * @param $showeval
140
     * @param $showlink
141
     */
142
    public static function display_header_reduce_flatview($catobj, $showeval, $showlink, $simple_search_form)
143
    {
144
        $header = '<div class="actions">';
145
        if ($catobj->get_parent_id() == 0) {
146
            $select_cat = $catobj->get_id();
147
            $url = Category::getUrl();
148
        } else {
149
            $select_cat = $catobj->get_parent_id();
150
            $url = 'gradebook_flatview.php';
151
        }
152
        $header .= '<a href="'.$url.'?'.api_get_cidreq().'&selectcat='.$select_cat.'">'.
153
            Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM).'</a>';
154
155
        $pageNum = isset($_GET['flatviewlist_page_nr']) ? (int) $_GET['flatviewlist_page_nr'] : null;
156
        $perPage = isset($_GET['flatviewlist_per_page']) ? (int) $_GET['flatviewlist_per_page'] : null;
157
        $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
158
159
        $exportCsvUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
160
            'export_format' => 'csv',
161
            'export_report' => 'export_report',
162
            'selectcat' => $catobj->get_id(),
163
        ]);
164
165
        $scoreRanking = ScoreDisplay::instance()->get_custom_score_display_settings();
166
        $attributes = [];
167
        if (!empty($scoreRanking)) {
168
            $attributes = ['class' => 'export_opener'];
169
        }
170
171
        $header .= Display::url(
172
            Display::return_icon(
173
                'export_csv.png',
174
                get_lang('ExportAsCSV'),
175
                '',
176
                ICON_SIZE_MEDIUM
177
            ),
178
            $exportCsvUrl,
179
            $attributes
180
        );
181
182
        $exportXlsUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
183
            'export_format' => 'xls',
184
            'export_report' => 'export_report',
185
            'selectcat' => $catobj->get_id(),
186
        ]);
187
188
        $header .= Display::url(
189
            Display::return_icon(
190
                'export_excel.png',
191
                get_lang('ExportAsXLS'),
192
                '',
193
                ICON_SIZE_MEDIUM
194
            ),
195
            $exportXlsUrl,
196
            $attributes
197
        );
198
199
        $exportDocUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
200
            'export_format' => 'doc',
201
            'export_report' => 'export_report',
202
            'selectcat' => $catobj->get_id(),
203
        ]);
204
205
        $header .= Display::url(
206
            Display::return_icon(
207
                'export_doc.png',
208
                get_lang('ExportAsDOC'),
209
                '',
210
                ICON_SIZE_MEDIUM
211
            ),
212
            $exportDocUrl,
213
            $attributes
214
        );
215
216
        $exportPrintUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
217
                'print' => '',
218
                'selectcat' => $catobj->get_id(),
219
            ]);
220
221
        $header .= Display::url(
222
            Display::return_icon(
223
                'printer.png',
224
                get_lang('Print'),
225
                '',
226
                ICON_SIZE_MEDIUM
227
            ),
228
            $exportPrintUrl,
229
            ['target' => '_blank']
230
        );
231
232
        $exportPdfUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
233
            'exportpdf' => '',
234
            'selectcat' => $catobj->get_id(),
235
            'offset' => $offset,
236
            'flatviewlist_page_nr' => $pageNum,
237
            'flatviewlist_per_page' => $perPage,
238
        ]);
239
240
        $header .= Display::url(
241
            Display::return_icon(
242
                'pdf.png',
243
                get_lang('ExportToPDF'),
244
                '',
245
                ICON_SIZE_MEDIUM
246
            ),
247
            $exportPdfUrl
248
        );
249
250
        $header .= '</div>';
251
252
        $dialog = '';
253
        if (!empty($scoreRanking)) {
254
            $dialog = '<div id="dialog-confirm" style="display:none" title="'.get_lang('ConfirmYourChoice').'">';
255
            $form = new FormValidator(
256
                'report',
257
                'post',
258
                null,
259
                null,
260
                ['class' => 'form-vertical']
261
            );
262
            $form->addCheckBox(
263
                'only_score',
264
                null,
265
                get_lang('OnlyNumbers')
266
            );
267
            $dialog .= $form->returnForm();
268
            $dialog .= '</div>';
269
        }
270
271
        echo $header.$dialog;
272
    }
273
274
    /**
275
     * Displays the header for the gradebook containing the navigation tree and links.
276
     *
277
     * @param Category $catobj
278
     * @param int      $showtree '1' will show the browse tree and naviation buttons
279
     * @param $selectcat
280
     * @param bool  $is_course_admin
281
     * @param bool  $is_platform_admin
282
     * @param bool  $simple_search_form
283
     * @param bool  $show_add_qualification Whether to show or not the link to add a new qualification
284
     *                                      (we hide it in case of the course-embedded tool where we have only one
285
     *                                      per course or session)
286
     * @param bool  $show_add_link          Whether to show or not the link to add a new item inside
287
     *                                      the qualification (we hide it in case of the course-embedded tool
288
     *                                      where we have only one qualification per course or session)
289
     * @param array $certificateLinkInfo
290
     */
291
    public static function header(
292
        $catobj,
293
        $showtree,
294
        $selectcat,
295
        $is_course_admin,
296
        $is_platform_admin,
297
        $simple_search_form,
298
        $show_add_qualification = true,
299
        $show_add_link = true,
300
        $certificateLinkInfo = []
301
    ) {
302
        $userId = api_get_user_id();
303
        $courseId = api_get_course_int_id();
304
        $sessionId = api_get_session_id();
305
        if (!$is_course_admin) {
306
            $model = ExerciseLib::getCourseScoreModel();
307
            if (!empty($model)) {
308
                return '';
309
            }
310
        }
311
312
        // Student.
313
        $status = CourseManager::getUserInCourseStatus($userId, $courseId);
314
        $sessionStatus = 0;
315
316
        if (!empty($sessionId)) {
317
            $sessionStatus = SessionManager::get_user_status_in_course_session(
318
                $userId,
319
                $courseId,
320
                $sessionId
321
            );
322
        }
323
324
        $objcat = new Category();
325
        $course_id = CourseManager::get_course_by_category($selectcat);
326
        $message_resource = $objcat->show_message_resource_delete($course_id);
327
        $grade_model_id = $catobj->get_grade_model_id();
328
        $header = null;
329
        if (isset($catobj) && !empty($catobj)) {
330
            $categories = Category::load(
331
                null,
332
                null,
333
                null,
334
                $catobj->get_id(),
335
                null,
336
                $sessionId
337
            );
338
        }
339
340
        if (!$is_course_admin && ($status != 1 || $sessionStatus == 0) && $selectcat != 0) {
341
            $catcourse = Category::load($catobj->get_id());
342
            /** @var Category $category */
343
            $category = $catcourse[0];
344
            $main_weight = $category->get_weight();
345
            $scoredisplay = ScoreDisplay::instance();
346
            $allevals = $category->get_evaluations($userId, true);
347
            $alllinks = $category->get_links($userId, true);
348
            $allEvalsLinks = array_merge($allevals, $alllinks);
349
            $item_value_total = 0;
350
            $scoreinfo = null;
351
352
            for ($count = 0; $count < count($allEvalsLinks); $count++) {
353
                $item = $allEvalsLinks[$count];
354
                $score = $item->calc_score($userId);
355
                if (!empty($score)) {
356
                    $divide = $score[1] == 0 ? 1 : $score[1];
357
                    $item_value = $score[0] / $divide * $item->get_weight();
358
                    $item_value_total += $item_value;
359
                }
360
            }
361
362
            $item_total = $main_weight;
363
            $total_score = [$item_value_total, $item_total];
364
            $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
365
366
            if (!$catobj->get_id() == '0' && !isset($_GET['studentoverview']) && !isset($_GET['search'])) {
367
                $additionalButtons = null;
368
                if (!empty($certificateLinkInfo)) {
369
                    $additionalButtons .= '<div class="btn-group pull-right">';
370
                    $additionalButtons .= isset($certificateLinkInfo['certificate_link']) ? $certificateLinkInfo['certificate_link'] : '';
371
                    $additionalButtons .= isset($certificateLinkInfo['badge_link']) ? $certificateLinkInfo['badge_link'] : '';
372
                    $additionalButtons .= '</div>';
373
                }
374
                $scoreinfo .= '<strong>'.sprintf(get_lang('TotalX'), $scorecourse_display.$additionalButtons).'</strong>';
375
            }
376
            echo Display::return_message($scoreinfo, 'normal', false);
377
        }
378
379
        // show navigation tree and buttons?
380
        if ($showtree == '1' || isset($_GET['studentoverview'])) {
381
            $header = '<div class="actions"><table>';
382
            $header .= '<tr>';
383
            if (!$selectcat == '0') {
384
                $header .= '<td><a href="'.api_get_self().'?selectcat='.$catobj->get_parent_id().'">'.
385
                    Display::return_icon(
386
                        'back.png',
387
                        get_lang('BackTo').' '.get_lang('RootCat'),
388
                        '',
389
                        ICON_SIZE_MEDIUM
390
                    ).
391
                    '</a></td>';
392
            }
393
            $header .= '<td>'.get_lang('CurrentCategory').'</td>'.
394
                    '<td><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
395
            $cats = Category::load();
396
397
            $tree = $cats[0]->get_tree();
398
            unset($cats);
399
            $line = null;
400
            foreach ($tree as $cat) {
401
                for ($i = 0; $i < $cat[2]; $i++) {
402
                    $line .= '&mdash;';
403
                }
404
                $line = isset($line) ? $line : '';
405
                if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) {
406
                    $header .= '<option selected value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
407
                } else {
408
                    $header .= '<option value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
409
                }
410
                $line = '';
411
            }
412
            $header .= '</select></form></td>';
413
            if (!empty($simple_search_form) && $message_resource === false) {
414
                $header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>';
415
            } else {
416
                $header .= '<td></td>';
417
            }
418
            if (!($is_course_admin &&
419
                $message_resource === false &&
420
                isset($_GET['selectcat']) && $_GET['selectcat'] != 0) &&
421
                isset($_GET['studentoverview'])
422
            ) {
423
                $header .= '<td style="vertical-align: top;">
424
                                <a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">
425
							 '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
426
							'.get_lang('ExportPDF').'</a>';
427
            }
428
            $header .= '</td></tr>';
429
            $header .= '</table></div>';
430
        }
431
432
        // for course admin & platform admin add item buttons are added to the header
433
        $actionsLeft = '';
434
        $actionsRight = '';
435
        $my_api_cidreq = api_get_cidreq();
436
        $isCoach = api_is_coach(api_get_session_id(), api_get_course_int_id());
437
        $accessToRead = api_is_allowed_to_edit(null, true) || $isCoach;
438
        $accessToEdit = api_is_allowed_to_edit(null, true);
439
        $courseCode = api_get_course_id();
440
441
        if ($accessToRead) {
442
            $my_category = $catobj->showAllCategoryInfo($catobj->get_id());
443
            if ($selectcat != '0' && $accessToEdit) {
444
                if ($my_api_cidreq == '') {
445
                    $my_api_cidreq = 'cidReq='.$my_category['course_code'];
446
                }
447
                if ($show_add_link && !$message_resource) {
448
                    $actionsLeft .= '<a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'" >'.
449
                        Display::return_icon('new_evaluation.png', get_lang('NewEvaluation'), '',
450
                            ICON_SIZE_MEDIUM).'</a>';
451
                    $cats = Category::load($selectcat);
452
453
                    if ($cats[0]->get_course_code() != null && !$message_resource) {
454
                        $actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
455
                            Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '',
456
                                ICON_SIZE_MEDIUM).'</a>';
457
                    } else {
458
                        $actionsLeft .= '<a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
459
                            Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '',
460
                                ICON_SIZE_MEDIUM).'</a>';
461
                    }
462
                }
463
            }
464
            if ((empty($grade_model_id) || $grade_model_id == -1) && $accessToEdit) {
465
                $actionsLeft .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.
466
                    Display::return_icon(
467
                        'new_folder.png',
468
                        get_lang('AddGradebook'),
469
                        [],
470
                        ICON_SIZE_MEDIUM
471
                    ).'</a></td>';
472
            }
473
474
            if ($selectcat != '0' && $accessToRead) {
475
                if (!$message_resource) {
476
                    $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
477
                        Display::return_icon('statistics.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).'</a>';
478
479
                    if ($my_category['generate_certificates'] == 1) {
480
                        $actionsLeft .= Display::url(
481
                            Display::return_icon(
482
                                'certificate_list.png',
483
                                get_lang('GradebookSeeListOfStudentsCertificates'),
484
                                '',
485
                                ICON_SIZE_MEDIUM
486
                            ),
487
                            "gradebook_display_certificate.php?$my_api_cidreq&cat_id=".$selectcat
488
                        );
489
                    }
490
491
                    $actionsLeft .= Display::url(
492
                        Display::return_icon(
493
                            'user.png',
494
                            get_lang('GradebookListOfStudentsReports'),
495
                            '',
496
                            ICON_SIZE_MEDIUM
497
                        ),
498
                        "gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat
499
                    );
500
501
                    $allow = api_get_configuration_value('gradebook_custom_student_report');
502
                    if ($allow) {
503
                        $actionsLeft .= Display::url(
504
                            get_lang('GenerateCustomReport'),
505
                            api_get_path(WEB_AJAX_PATH)."gradebook.ajax.php?$my_api_cidreq&a=generate_custom_report",
506
                            ['class' => 'btn btn-default ajax']
507
                        );
508
                    }
509
510
                    // Right icons
511
                    if ($accessToEdit) {
512
                        $actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id(
513
                            ).'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
514
                            Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>';
515
516
                        if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') === 'true' &&
517
                            api_get_course_setting('customcertificate_course_enable') == 1
518
                        ) {
519
                            $actionsRight .= '<a href="'.api_get_path(
520
                                    WEB_PLUGIN_PATH
521
                                ).'customcertificate/src/index.php?'.
522
                                $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
523
                                Display::return_icon(
524
                                    'certificate.png',
525
                                    get_lang('AttachCertificate'),
526
                                    '',
527
                                    ICON_SIZE_MEDIUM
528
                                ).'</a>';
529
                        } else {
530
                            $actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH).
531
                                'document/document.php?curdirpath=/certificates&'.
532
                                $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
533
                                Display::return_icon(
534
                                    'certificate.png',
535
                                    get_lang('AttachCertificate'),
536
                                    '',
537
                                    ICON_SIZE_MEDIUM
538
                                ).'</a>';
539
                        }
540
541
                        if (empty($categories)) {
542
                            $actionsRight .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id(
543
                                ).'&'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
544
                                Display::return_icon(
545
                                    'percentage.png',
546
                                    get_lang('EditAllWeights'),
547
                                    '',
548
                                    ICON_SIZE_MEDIUM
549
                                ).'</a>';
550
                        }
551
                        $score_display_custom = api_get_setting('gradebook_score_display_custom');
552
                        if (api_get_setting('teachers_can_change_score_settings') == 'true' &&
553
                            $score_display_custom['my_display_custom'] == 'true'
554
                        ) {
555
                            $actionsRight .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
556
                                Display::return_icon('ranking.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM).'</a>';
557
                        }
558
                    }
559
                }
560
            }
561
        } elseif (isset($_GET['search'])) {
562
            echo $header = '<b>'.get_lang('SearchResults').' :</b>';
563
        }
564
565
        $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
566
            api_get_user_id(),
567
            api_get_course_info()
568
        );
569
570
        if ($isDrhOfCourse) {
571
            $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
572
                Display::return_icon(
573
                    'statistics.png',
574
                    get_lang('FlatView'),
575
                    '',
576
                    ICON_SIZE_MEDIUM
577
                ).
578
                '</a>';
579
        }
580
581
        if ($isCoach || api_is_allowed_to_edit(null, true)) {
582
            echo $toolbar = Display::toolbarAction(
583
                'gradebook-actions',
584
                [$actionsLeft, $actionsRight]
585
            );
586
        }
587
588
        if ($accessToEdit || api_is_allowed_to_edit(null, true)) {
589
            $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0;
590
            $weight = '<strong>'.get_lang('TotalWeight').' : </strong>'.$weight;
591
            $min_certification = intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0;
592
593
            if (!empty($min_certification)) {
594
                $model = ExerciseLib::getCourseScoreModel();
595
                if (!empty($model)) {
596
                    $defaultCertification = api_number_format($min_certification, 2);
597
                    $questionWeighting = $catobj->get_weight();
598
                    foreach ($model['score_list'] as $item) {
599
                        $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
600
                        $model = ExerciseLib::getModelStyle($item, $i);
601
                        if ($defaultCertification == $i) {
602
                            $min_certification = $model;
603
                            break;
604
                        }
605
                    }
606
                }
607
            }
608
609
            $min_certification = get_lang('CertificateMinScore').' : '.$min_certification;
610
            $edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
611
                Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
612
613
            $msg = $weight.' - '.$min_certification.$edit_icon;
614
            //@todo show description
615
            $description = (($catobj->get_description() == '' || is_null($catobj->get_description())) ? '' : '<strong>'.get_lang('GradebookDescriptionLog').'</strong>'.': '.$catobj->get_description());
616
            echo Display::return_message($msg, 'normal', false);
617
            if (!empty($description)) {
618
                echo Display::div($description, []);
619
            }
620
        }
621
    }
622
623
    /**
624
     * @param Category $catobj
625
     * @param $is_course_admin
626
     * @param $is_platform_admin
627
     * @param $simple_search_form
628
     * @param bool $show_add_qualification
629
     * @param bool $show_add_link
630
     */
631
    public function display_reduce_header_gradebook(
632
        $catobj,
633
        $is_course_admin,
634
        $is_platform_admin,
635
        $simple_search_form,
636
        $show_add_qualification = true,
637
        $show_add_link = true
638
    ) {
639
        //student
640
        if (!$is_course_admin) {
641
            $user = api_get_user_info(api_get_user_id());
642
            $catcourse = Category::load($catobj->get_id());
643
            $scoredisplay = ScoreDisplay::instance();
644
            $scorecourse = $catcourse[0]->calc_score(api_get_user_id());
645
            $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable');
646
            $cattotal = Category::load(0);
647
            $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
648
            $scoretotal_display = isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable');
649
            $scoreinfo = get_lang('StatsStudent').' :<b> '.$user['complete_name'].'</b><br />';
650
            if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
651
                $scoreinfo .= '<br />'.get_lang('TotalForThisCategory').' : <b>'.$scorecourse_display.'</b>';
652
            }
653
            $scoreinfo .= '<br />'.get_lang('Total').' : <b>'.$scoretotal_display.'</b>';
654
            Display::addFlash(
655
                Display::return_message($scoreinfo, 'normal', false)
656
            );
657
        }
658
        // show navigation tree and buttons?
659
        $header = '<div class="actions">';
660
661
        if ($is_course_admin) {
662
            $header .= '<a href="gradebook_flatview.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.
663
                Display::return_icon('statistics.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).'</a>';
664
            $header .= '<a href="gradebook_scoring_system.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.
665
                Display::return_icon('settings.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM).'</a>';
666
        } elseif (!(isset($_GET['studentoverview']))) {
667
            $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&selectcat='.$catobj->get_id().'">'.
668
                Display::return_icon('view_list.gif', get_lang('FlatView')).' '.get_lang('FlatView').'</a>';
669
        } else {
670
            $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">'.
671
                Display::return_icon('pdf.png', get_lang('ExportPDF'), '', ICON_SIZE_MEDIUM).'</a>';
672
        }
673
        $header .= '</div>';
674
        echo $header;
675
    }
676
677
    /**
678
     * @param int $userId
679
     * @param int $categoryId
680
     *
681
     * @return string
682
     */
683
    public static function display_header_user($userId, $categoryId)
684
    {
685
        $user = api_get_user_info($userId);
686
        if (empty($user)) {
687
            return '';
688
        }
689
690
        $catcourse = Category::load($categoryId);
691
        $scoredisplay = ScoreDisplay::instance();
692
693
        // generating the total score for a course
694
        $allevals = $catcourse[0]->get_evaluations(
695
            $userId,
696
            true,
697
            api_get_course_id()
698
        );
699
        $alllinks = $catcourse[0]->get_links(
700
            $userId,
701
            true,
702
            api_get_course_id()
703
        );
704
        $evals_links = array_merge($allevals, $alllinks);
705
        $item_value = 0;
706
        $item_total = 0;
707
        for ($count = 0; $count < count($evals_links); $count++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
708
            $item = $evals_links[$count];
709
            $score = $item->calc_score($userId);
710
            if ($score) {
711
                $my_score_denom = ($score[1] == 0) ? 1 : $score[1];
712
                $item_value += $score[0] / $my_score_denom * $item->get_weight();
713
            }
714
            $item_total += $item->get_weight();
715
        }
716
        $item_value = api_number_format($item_value, 2);
717
        $total_score = [$item_value, $item_total];
718
        $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
719
720
        $info = '<div class="row"><div class="col-md-3">';
721
        $info .= '<div class="thumbnail"><img src="'.$user['avatar'].'" /></div>';
722
        $info .= '</div>';
723
        $info .= '<div class="col-md-6">';
724
        $info .= get_lang('Name').' :  '.$user['complete_name_with_message_link'].'<br />';
725
726
        if (api_get_setting('show_email_addresses') === 'true') {
727
            $info .= get_lang('Email').' : <a href="mailto:'.$user['email'].'">'.$user['email'].'</a><br />';
728
        }
729
730
        $info .= get_lang('TotalUser').' : <b>'.$scorecourse_display.'</b>';
731
        $info .= '</div>';
732
        $info .= '</div>';
733
        echo $info;
734
    }
735
}
736