Completed
Push — master ( f77763...d3c71d )
by Julito
11:18
created

Justification   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
dl 0
loc 94
rs 10
c 1
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getJustification() 0 8 1
A getList() 0 6 1
A uninstall() 0 7 1
A create() 0 5 2
A __construct() 0 8 1
A getUserJustification() 0 8 1
A getUserJustificationList() 0 8 1
A install() 0 20 1
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.1',
10
            'Julio Montoya',
11
            [
12
                'tool_enable' => 'boolean',
13
                'default_course_id' => 'text',
14
            ]
15
        );
16
    }
17
18
    /**
19
     * @return $this
20
     */
21
    public static function create()
22
    {
23
        static $result = null;
24
25
        return $result ? $result : $result = new self();
26
    }
27
28
    public function getJustification($id)
29
    {
30
        $id = (int) $id;
31
32
        $sql = 'SELECT * FROM justification_document WHERE id = '.$id;
33
        $query = Database::query($sql);
34
35
        return Database::fetch_array($query, 'ASSOC');
36
    }
37
38
    public function getUserJustificationList($userId)
39
    {
40
        $userId = (int) $userId;
41
42
        $sql = "SELECT * FROM justification_document_rel_users WHERE user_id = $userId ";
43
        $query = Database::query($sql);
44
45
        return Database::store_result($query, 'ASSOC');
46
    }
47
48
    public function getUserJustification($id)
49
    {
50
        $id = (int) $id;
51
52
        $sql = "SELECT * FROM justification_document_rel_users WHERE id = $id ";
53
        $query = Database::query($sql);
54
55
        return Database::fetch_array($query, 'ASSOC');
56
    }
57
58
    public function getList()
59
    {
60
        $sql = 'SELECT * FROM justification_document ORDER BY name ';
61
        $query = Database::query($sql);
62
63
        return Database::store_result($query, 'ASSOC');
64
    }
65
66
    /**
67
     * Install.
68
     */
69
    public function install()
70
    {
71
        $sql = "CREATE TABLE IF NOT EXISTS justification_document (
72
            id INT unsigned NOT NULL auto_increment PRIMARY KEY,
73
            code TEXT NULL,
74
            name TEXT NULL,
75
            validity_duration INT,
76
            comment TEXT NULL,
77
            date_manual_on INT
78
        )";
79
        Database::query($sql);
80
81
        $sql = "CREATE TABLE IF NOT EXISTS justification_document_rel_users (
82
            id INT unsigned NOT NULL auto_increment PRIMARY KEY,
83
            justification_document_id INT NOT NULL,
84
            file_path VARCHAR(255),
85
            user_id INT,
86
            date_validity DATE
87
        )";
88
        Database::query($sql);
89
    }
90
91
    public function uninstall()
92
    {
93
        $sql = 'DROP TABLE IF EXISTS justification_document';
94
        Database::query($sql);
95
96
        $sql = 'DROP TABLE IF EXISTS justification_document_rel_users';
97
        Database::query($sql);
98
    }
99
}
100