Passed
Push — 1.11.x ( 036fa1...927d0d )
by Julito
14:55
created

MyStudents::getBlockForSkills()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
class MyStudents
6
{
7
    public static function userCareersTable(int $studentId): string
8
    {
9
        if (!api_get_configuration_value('allow_career_users')) {
10
            return '';
11
        }
12
13
        $careers = UserManager::getUserCareers($studentId);
14
15
        if (empty($careers)) {
16
            return '';
17
        }
18
19
        return self::getCareersTable($careers);
20
    }
21
22
    public static function getCareersTable(array $careers): string
23
    {
24
        if (empty($careers)) {
25
            return '';
26
        }
27
28
        $webCodePath = api_get_path(WEB_CODE_PATH);
29
        $iconDiagram = Display::return_icon('multiplicate_survey.png', get_lang('Diagram'));
30
31
        $headers = [
32
            get_lang('Career'),
33
            get_lang('Diagram'),
34
        ];
35
36
        $data = array_map(
37
            function (array $careerInfo) use ($webCodePath, $iconDiagram) {
38
                $url = $webCodePath.'user/career_diagram.php?career_id='.$careerInfo['id'];
39
40
                return [
41
                    $careerInfo['name'],
42
                    Display::url($iconDiagram, $url),
43
                ];
44
            },
45
            $careers
46
        );
47
48
        $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
49
        $table->setHeaders($headers);
50
        $table->setData($data);
51
52
        return $table->toHtml();
53
    }
54
55
56
    public static function getBlockForSkills(int $studentId, int $courseId, int $sessionId): string
57
    {
58
        $allowAll = api_get_configuration_value('allow_teacher_access_student_skills');
59
60
        if ($allowAll) {
61
            // Show all skills
62
            return Tracking::displayUserSkills($studentId, 0, 0, true);
63
        }
64
65
        // Default behaviour - Show all skills depending the course and session id
66
        return Tracking::displayUserSkills($studentId, $courseId, $sessionId);
67
    }
68
69
    public static function getBlockForClasses($studentId): ?string
70
    {
71
        $userGroupManager = new UserGroup();
72
        $userGroups = $userGroupManager->getNameListByUser(
73
            $studentId,
74
            UserGroup::NORMAL_CLASS
75
        );
76
77
        if (empty($userGroups)) {
78
            return null;
79
        }
80
81
        $headers = [get_lang('Classes')];
82
        $data = array_map(
83
            function ($class) {
84
                return [$class];
85
            },
86
            $userGroups
87
        );
88
89
        $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
90
        $table->setHeaders($headers);
91
        $table->setData($data);
92
93
        return $table->toHtml();
94
    }
95
}
96