Passed
Push — 1.11.x ( b6143c...fc2306 )
by Julito
09:35
created

Justification   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 100
rs 10
wmc 10

9 Methods

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