Passed
Push — master ( fe7dcd...466ab7 )
by Angel Fernando Quiroz
08:26
created

Justification::get_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For license terms, see /license.txt */
3
4
class Justification extends Plugin
5
{
6
    protected function __construct()
7
    {
8
        parent::__construct(
9
            '1.2',
10
            'Julio Montoya, Nicolas Ducoulombier',
11
            [
12
                'tool_enable' => 'boolean',
13
                'notification_to_creator_only' => 'boolean',
14
                'access_for_session_admin' => 'boolean',
15
                'default_course_id' => 'text',
16
            ]
17
        );
18
    }
19
20
    /**
21
     * @return $this
22
     */
23
    public static function create()
24
    {
25
        static $result = null;
26
27
        return $result ? $result : $result = new self();
28
    }
29
30
    public function getJustification($id)
31
    {
32
        $id = (int) $id;
33
34
        $sql = 'SELECT * FROM justification_document WHERE id = '.$id;
35
        $query = Database::query($sql);
36
37
        return Database::fetch_assoc($query);
38
    }
39
40
    public function getUserJustificationList($userId)
41
    {
42
        $userId = (int) $userId;
43
44
        $sql = "SELECT * FROM justification_document_rel_users WHERE user_id = $userId ";
45
        $query = Database::query($sql);
46
47
        return Database::store_result($query, 'ASSOC');
48
    }
49
50
    public function getUserJustification($id)
51
    {
52
        $id = (int) $id;
53
54
        $sql = "SELECT * FROM justification_document_rel_users WHERE id = $id ";
55
        $query = Database::query($sql);
56
57
        return Database::fetch_assoc($query);
58
    }
59
60
    public function getList()
61
    {
62
        $sql = 'SELECT * FROM justification_document ORDER BY name ';
63
        $query = Database::query($sql);
64
65
        return Database::store_result($query, 'ASSOC');
66
    }
67
68
    /**
69
     * Install.
70
     */
71
    public function install()
72
    {
73
        $sql = "CREATE TABLE IF NOT EXISTS justification_document (
74
            id INT unsigned NOT NULL auto_increment PRIMARY KEY,
75
            code TEXT NULL,
76
            name TEXT NULL,
77
            validity_duration INT,
78
            comment TEXT NULL,
79
            date_manual_on INT
80
        )";
81
        Database::query($sql);
82
83
        $sql = "CREATE TABLE IF NOT EXISTS justification_document_rel_users (
84
            id INT unsigned NOT NULL auto_increment PRIMARY KEY,
85
            justification_document_id INT NOT NULL,
86
            file_path VARCHAR(255),
87
            user_id INT,
88
            date_validity DATE
89
        )";
90
        Database::query($sql);
91
    }
92
93
    public function uninstall()
94
    {
95
        $sql = 'DROP TABLE IF EXISTS justification_document';
96
        Database::query($sql);
97
98
        $sql = 'DROP TABLE IF EXISTS justification_document_rel_users';
99
        Database::query($sql);
100
    }
101
102
    public function get_name()
103
    {
104
        return 'Justification';
105
    }
106
}
107