Passed
Push — 1.11.x ( 01ed20...42b81c )
by Julito
12:04
created

Justification   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 63
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getList() 0 6 1
A uninstall() 0 7 1
A create() 0 5 2
A __construct() 0 7 1
A install() 0 20 1
1
<?php
2
/* For license terms, see /license.txt */
3
4
use ChamiloSession as Session;
5
6
class Justification extends Plugin
7
{
8
    protected function __construct()
9
    {
10
        parent::__construct(
11
            '1.1',
12
            'Julio Montoya',
13
            [
14
                'tool_enable' => 'boolean',
15
            ]
16
        );
17
    }
18
19
    /**
20
     * @return $this
21
     */
22
    public static function create()
23
    {
24
        static $result = null;
25
26
        return $result ? $result : $result = new self();
27
    }
28
29
    public function getList()
30
    {
31
        $sql = 'SELECT * FROM justification_document ';
32
        $query = Database::query($sql);
33
34
        return Database::store_result($query, 'ASSOC');
35
    }
36
37
    /**
38
     * Install
39
     */
40
    public function install()
41
    {
42
        $sql = "CREATE TABLE IF NOT EXISTS justification_document (
43
            id INT unsigned NOT NULL auto_increment PRIMARY KEY,
44
            code TEXT NULL,
45
            name TEXT NULL,
46
            validity_duration INT,
47
            comment TEXT NULL,
48
            date_manual_on INT
49
        )";
50
        Database::query($sql);
51
52
        $sql = "CREATE TABLE IF NOT EXISTS justification_document_users (
53
            id INT unsigned NOT NULL auto_increment PRIMARY KEY,
54
            justification_document_id INT NOT NULL,
55
            document_id INT,
56
            user_id INT,
57
            date_validity DATE
58
        )";
59
        Database::query($sql);
60
    }
61
62
    public function uninstall()
63
    {
64
        $sql = 'DROP TABLE justification_document';
65
        Database::query($sql);
66
67
        $sql = 'DROP TABLE justification_document_users';
68
        Database::query($sql);
69
    }
70
}
71