Completed
Push — master ( 7a25dd...1c4a3d )
by Jacob
01:41
created

audiortc.php ➔ get_output()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 60
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 51
nc 1
nop 0
dl 0
loc 60
rs 9.5555
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * @package    tinymce_recordrtc
19
 * @author     Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
20
 * @copyright  2016 to present, Blindside Networks Inc.
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
24
require_once(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))).'/config.php');
25
require_once(dirname(__FILE__).'/lib.php');
26
27
$contextid = required_param('contextid', PARAM_INT);
28
29
list($context, $course, $cm) = get_context_info_array($contextid);
30
require_login($course, false, $cm);
31
require_sesskey();
32
33
$PAGE->set_context($context);
34
$PAGE->set_url(MOODLE_TINYMCE_RECORDRTC_ROOT.'audiortc.php');
35
$PAGE->set_cacheable(false);
36
$title = '';
37
if (isset($cm->name)) {
38
    $title = $cm->name;
39
}
40
$PAGE->set_title($title);
41
$PAGE->set_heading($title);
42
43
// Reset page layout for inside editor.
44
$PAGE->set_pagelayout('embedded');
45
46
$PAGE->requires->css(new moodle_url($CFG->wwwroot.MOODLE_TINYMCE_RECORDRTC_ROOT.'tinymce/css/style.css'));
47
$PAGE->requires->js(new moodle_url($CFG->wwwroot.MOODLE_TINYMCE_RECORDRTC_ROOT.'tinymce/js/bowser.js'), true);
48
$PAGE->requires->js(new moodle_url($CFG->wwwroot.MOODLE_TINYMCE_RECORDRTC_ROOT.'tinymce/js/adapter.js'), true);
49
$PAGE->requires->js(new moodle_url($CFG->wwwroot.MOODLE_TINYMCE_RECORDRTC_ROOT.'tinymce/js/commonmodule.js'), true);
50
51
$jsvars = array(
52
    'contextid' => $contextid,
53
    'icon32' => $CFG->wwwroot.MOODLE_TINYMCE_RECORDRTC_ROOT.'tinymce/img/audiortc.png'
54
);
55
$PAGE->requires->data_for_js('recordrtc', $jsvars);
56
57
$jsmodule = array(
58
    'name'     => 'tinymce_recordrtc',
59
    'fullpath' => MOODLE_TINYMCE_RECORDRTC_ROOT.'tinymce/js/audiomodule.js'
60
);
61
$PAGE->requires->js_init_call('M.tinymce_recordrtc.view_init', array(), false, $jsmodule);
62
63
// Get localized strings for use in JavaScript.
64
$stringmanager = get_string_manager();
65
$strings = $stringmanager->load_component_strings('tinymce_recordrtc', $USER->lang);
66
$PAGE->requires->strings_for_js(array_keys($strings), 'tinymce_recordrtc');
67
68
echo $OUTPUT->header();
69
70
echo get_audiortc_output();
71
72
echo $OUTPUT->footer();
73
74
75
function get_audiortc_output() {
76
    $out  = '<div class="container-fluid">'."\n";
77
    $out .= '  <div class="row hide">'."\n";
78
    $out .= '    <div class="col-sm-12">'."\n";
79
    $out .= '      <div id="alert-warning" class="alert alert-warning"><strong>'
80
                   .get_string('browseralert_title', 'tinymce_recordrtc').'</strong> '
81
                   .get_string('browseralert', 'tinymce_recordrtc').'</div>'."\n";
82
    $out .= '    </div>'."\n";
83
    $out .= '  </div>'."\n";
84
    $out .= '  <div class="row hide">'."\n";
85
    $out .= '    <div class="col-sm-12">'."\n";
86
    $out .= '      <div id="alert-danger" class="alert alert-danger"></div>'."\n";
87
    $out .= '    </div>'."\n";
88
    $out .= '  </div>'."\n";
89
    $out .= '  <div class="row hide">'."\n";
90
    $out .= '    <div class="col-sm-1">'."\n";
91
    $out .= '    </div>'."\n";
92
    $out .= '    <div class="col-sm-10">'."\n";
93
    $out .= '      <audio id="player"></audio>'."\n";
94
    $out .= '    </div>'."\n";
95
    $out .= '    <div class="col-sm-1">'."\n";
96
    $out .= '    </div>'."\n";
97
    $out .= '  </div>'."\n";
98
    $out .= '  <div class="row">'."\n";
99
    $out .= '    <div class="col-sm-1">'."\n";
100
    $out .= '    </div>'."\n";
101
    $out .= '    <div class="col-sm-10">'."\n";
102
    $out .= '      <button id="start-stop" class="btn btn-lg btn-outline-danger btn-block">'
103
                   .get_string('startrecording', 'tinymce_recordrtc').'</button>'."\n";
104
    $out .= '    </div>'."\n";
105
    $out .= '    <div class="col-sm-1">'."\n";
106
    $out .= '    </div>'."\n";
107
    $out .= '  </div>'."\n";
108
    $out .= '  <div class="row hide">'."\n";
109
    $out .= '    <div class="col-sm-3">'."\n";
110
    $out .= '    </div>'."\n";
111
    $out .= '    <div class="col-sm-6">'."\n";
112
    $out .= '      <button id="upload" class="btn btn-primary btn-block">'
113
                   .get_string('attachrecording', 'tinymce_recordrtc').'</button>'."\n";
114
    $out .= '    </div>'."\n";
115
    $out .= '    <div class="col-sm-3">'."\n";
116
    $out .= '    </div>'."\n";
117
    $out .= '  </div>'."\n";
118
    $out .= '</div>'."\n";
119
120
    // Because there is no relative path to TinyMCE, we have to use JavaScript
121
    // to work out correct path from the .js files from TinyMCE. Only files
122
    // inside this plugin can be included with relative path (below).
123
    $out .= '<script type="text/javascript">'."\n";
124
    $out .= '   var editor_tinymce_include = function(path) {'."\n";
125
    $out .= '       document.write(\'<script type="text/javascript" src="\' + parent.tinyMCE.baseURL + \'/\' + path + \'"></\' +
126
                                   \'script>\');'."\n";
127
    $out .= '   };'."\n";
128
    $out .= '   editor_tinymce_include(\'tiny_mce_popup.js\');'."\n";
129
    $out .= '   editor_tinymce_include(\'utils/validate.js\');'."\n";
130
    $out .= '   editor_tinymce_include(\'utils/form_utils.js\');'."\n";
131
    $out .= '   editor_tinymce_include(\'utils/editable_selects.js\');'."\n";
132
    $out .= '</script>'."\n";
133
    return $out;
134
}
135