Completed
Push — 1.10.x ( 123d3d...a32a3a )
by
unknown
52:30
created

BBBPlugin::validateCourseSetting()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 13
rs 9.4285
1
<?php
2
/* For licensing terms, see /license.txt */
3
/* To show the plugin course icons you need to add these icons:
4
 * main/img/icons/22/plugin_name.png
5
 * main/img/icons/64/plugin_name.png
6
 * main/img/icons/64/plugin_name_na.png
7
*/
8
/**
9
 * Videoconference plugin with BBB
10
 */
11
//namespace Chamilo\Plugin\BBB;
12
/**
13
 * Class BBBPlugin
14
 */
15
class BBBPlugin extends Plugin
16
{
17
    public $isCoursePlugin = true;
18
19
    // When creating a new course this settings are added to the course
20
    public $course_settings = [
21
        [
22
            'name' => 'big_blue_button_record_and_store',
23
            'type' => 'checkbox',
24
        ],
25
        [
26
            'name' => 'bbb_enable_conference_in_groups',
27
            'type' => 'checkbox',
28
        ]
29
    ];
30
31
    /**
32
     * BBBPlugin constructor.
33
     */
34
    protected function __construct()
35
    {
36
        parent::__construct(
37
            '2.4',
38
            'Julio Montoya, Yannick Warnier',
39
            [
40
                'tool_enable' => 'boolean',
41
                'host' => 'text',
42
                'salt' => 'text',
43
                'enable_global_conference' => 'boolean',
44
                'enable_conference_in_course_groups' => 'boolean',
45
            ]
46
        );
47
    }
48
49
    /**
50
     * @param string $variable
51
     * @return bool
52
     */
53
    public function validateCourseSetting($variable)
54
    {
55
        if ($variable == 'bbb_enable_conference_in_groups') {
56
            if ($this->get('enable_conference_in_course_groups') === 'true') {
57
58
                return true;
59
            } else {
60
                return false;
61
            }
62
        }
63
64
        return true;
65
    }
66
67
    /**
68
     * @return BBBPlugin|null
69
     */
70
    public static function create()
71
    {
72
        static $result = null;
73
        return $result ? $result : $result = new self();
74
    }
75
76
    /**
77
     * Install
78
     */
79
    public function install()
80
    {
81
        $table = Database::get_main_table('plugin_bbb_meeting');
82
        $sql = "CREATE TABLE IF NOT EXISTS $table (
83
                id INT unsigned NOT NULL auto_increment PRIMARY KEY,
84
                c_id INT unsigned NOT NULL DEFAULT 0,
85
                group_id INT unsigned NOT NULL DEFAULT 0,
86
                meeting_name VARCHAR(255) NOT NULL DEFAULT '',
87
                attendee_pw VARCHAR(255) NOT NULL DEFAULT '',
88
                moderator_pw VARCHAR(255) NOT NULL DEFAULT '',
89
                record INT NOT NULL DEFAULT 0,
90
                status INT NOT NULL DEFAULT 0,
91
                created_at VARCHAR(255) NOT NULL,
92
                closed_at VARCHAR(255) NOT NULL,
93
                calendar_id INT DEFAULT 0,
94
                welcome_msg VARCHAR(255) NOT NULL DEFAULT '',
95
                session_id INT unsigned DEFAULT 0,
96
                remote_id CHAR(30),
97
                visibility TINYINT NOT NULL DEFAULT 1,
98
                voice_bridge INT NOT NULL DEFAULT 1
99
                )";
100
        Database::query($sql);
101
102
        // Installing course settings
103
        $this->install_course_fields_in_all_courses();
104
    }
105
106
    /**
107
     * Uninstall
108
     */
109
    public function uninstall()
110
    {
111
        $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
112
        $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
113
        $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
114
115
        $variables = [
116
            'bbb_salt',
117
            'bbb_host',
118
            'bbb_tool_enable',
119
            'enable_global_conference',
120
            'enable_conference_in_course_groups',
121
            'bbb_plugin',
122
            'bbb_plugin_host',
123
            'bbb_plugin_salt'
124
        ];
125
126
        foreach ($variables as $variable) {
127
            $sql = "DELETE FROM $t_settings WHERE variable = '$variable'";
128
            Database::query($sql);
129
        }
130
131
        $sql = "DELETE FROM $t_options WHERE variable  = 'bbb_plugin'";
132
        Database::query($sql);
133
134
        // hack to get rid of Database::query warning (please add c_id...)
135
        $sql = "DELETE FROM $t_tool WHERE name = 'bbb' AND c_id != 0";
136
        Database::query($sql);
137
138
        $t = Database::get_main_table('plugin_bbb_meeting');
139
        $sql = "DROP TABLE IF EXISTS $t";
140
        Database::query($sql);
141
142
        // Deleting course settings
143
        $this->uninstall_course_fields_in_all_courses($this->course_settings);
144
    }
145
}
146