Completed
Push — master ( b48e3c...e53ab2 )
by Jesus
34:53
created

mobile::mobile_course_view()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 12
nop 1
dl 0
loc 50
rs 8.4686
c 0
b 0
f 0
1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * Mobile output class for bigbluebuttonbn
19
 *
20
 * @package    mod_bigbluebuttonbn
21
 * @copyright  2018 onwards, Blindside Networks Inc
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @author     Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
24
 */
25
26
namespace mod_bigbluebuttonbn\output;
27
28
defined('MOODLE_INTERNAL') || die();
29
30
use context_module;
31
use mod_bigbluebuttonbn_external;
32
33
/**
34
 * Mobile output class for bigbluebuttonbn
35
 *
36
 * @package    mod_bigbluebuttonbn
37
 * @copyright  2018 onwards, Blindside Networks Inc
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 * @author     Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
40
 */
41
class mobile {
42
43
    /**
44
     * Returns the bigbluebuttonbn course view for the mobile app.
45
     * @param  array $args Arguments from tool_mobile_get_content WS
46
     *
47
     * @return array       HTML, javascript and otherdata
48
     */
49
    public static function mobile_course_view($args) {
50
        global $OUTPUT, $USER, $DB;
51
52
        $args = (object) $args;
53
        $cm = get_coursemodule_from_id('bigbluebuttonbn', $args->cmid);
54
55
        // Capabilities check.
56
        require_login($args->courseid , false , $cm, true, true);
57
58
        $context = context_module::instance($cm->id);
59
60
        require_capability ('mod/bigbluebuttonbn:view', $context);
61
        if ($args->userid != $USER->id) {
62
            require_capability('mod/bigbluebuttonbn:manage', $context);
63
        }
64
        $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance));
65
66
        $showget = true;
67
        if ($bigbluebuttonbn->requiredtime && !has_capability('mod/bigbluebuttonbn:manage', $context)) {
68
            if (bigbluebuttonbn_get_course_time($bigbluebuttonbn->course) < ($bigbluebuttonbn->requiredtime * 60)) {
69
                $showget = false;
70
            }
71
        }
72
73
        $bigbluebuttonbn->name = format_string($bigbluebuttonbn->name);
74
        list($bigbluebuttonbn->intro, $bigbluebuttonbn->introformat) =
75
                        external_format_text($bigbluebuttonbn->intro, $bigbluebuttonbn->introformat, $context->id,
76
                                                'mod_bigbluebuttonbn', 'intro');
77
        $data = array(
78
            'bigbluebuttonbn' => $bigbluebuttonbn,
79
            'showget' => $showget && count($issues) > 0,
0 ignored issues
show
Bug introduced by
The variable $issues does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
80
            'issues' => $issues,
81
            'issue' => $issues[0],
82
            'numissues' => count($issues),
83
            'cmid' => $cm->id,
84
            'courseid' => $args->courseid
85
        );
86
87
        return array(
88
            'templates' => array(
89
                array(
90
                    'id' => 'main',
91
                    'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_page', $data),
92
                ),
93
            ),
94
            'javascript' => '',
95
            'otherdata' => '',
96
            'files' => $issues
97
        );
98
    }
99
100
    /**
101
     * Returns the bigbluebuttonbn issues view for the mobile app.
102
     * @param  array $args Arguments from tool_mobile_get_content WS
103
     *
104
     * @return array       HTML, javascript and otherdata
105
     */
106
    public static function mobile_issues_view($args) {
107
        global $OUTPUT, $USER, $DB;
108
109
        $args = (object) $args;
110
        $cm = get_coursemodule_from_id('bigbluebuttonbn', $args->cmid);
111
112
        // Capabilities check.
113
        require_login($args->courseid , false , $cm, true, true);
114
115
        $context = context_module::instance($cm->id);
116
117
        require_capability ('mod/bigbluebuttonbn:view', $context);
118
        if ($args->userid != $USER->id) {
119
            require_capability('mod/bigbluebuttonbn:manage', $context);
120
        }
121
        $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance));
0 ignored issues
show
Unused Code introduced by
$bigbluebuttonbn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
122
123
        // Get bigbluebuttonbns from external (taking care of exceptions).
124
        try {
125
            $issued = mod_bigbluebuttonbn_external::issue_bigbluebuttonbn($cm->instance);
0 ignored issues
show
Unused Code introduced by
$issued is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
126
            $bigbluebuttonbns = mod_bigbluebuttonbn_external::get_issued_bigbluebuttonbns($cm->instance);
127
            $issues = array_values($bigbluebuttonbns['issues']); // Make it mustache compatible.
128
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class mod_bigbluebuttonbn\output\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
129
            $issues = array();
130
        }
131
132
        $data = array(
133
            'issues' => $issues
134
        );
135
136
        return array(
137
            'templates' => array(
138
                array(
139
                    'id' => 'main',
140
                    'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_issues', $data),
141
                ),
142
            ),
143
            'javascript' => '',
144
            'otherdata' => ''
145
        );
146
    }
147
}
148