Completed
Push — master ( c9546d...95f607 )
by Julito
09:41
created

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