-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
83 lines (67 loc) · 2.76 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Prints an instance of mod_cobra.
*
* @package mod_cobra
* @copyright 2016 onwards - Cellule TICE - University of Namur
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/mod/cobra/locallib.php');
use mod_cobra\output\cobratext;
// Course_module ID.
$id = required_param('id', PARAM_INT);
list($course, $cm) = get_course_and_cm_from_cmid($id, 'cobra');
$cobra = $DB->get_record('cobra', ['id' => $cm->instance], '*', MUST_EXIST);
$context = context_module::instance($cm->id);
require_login($course, true, $cm);
require_capability('mod/cobra:view', $context);
// Add event management here.
$event = \mod_cobra\event\course_module_viewed::create([
'objectid' => $cobra->id,
'context' => $context,
]);
$event->add_record_snapshot('course', $PAGE->course);
$event->add_record_snapshot($cm->modname, $cobra);
$event->trigger();
// Completion.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Keep userid and cmid for ajax calls.
global $USER;
$cobra->user = $USER->id;
$cobra->cmid = $id;
$cobra->encodeclic = user_has_role_assignment($USER->id, 5, $context->id);
$PAGE->set_url('/mod/cobra/view.php', ['id' => $cm->id]);
$PAGE->set_title($course->shortname . ': ' . format_string($cobra->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->force_settings_menu();
$PAGE->add_body_class('noblocks');
$PAGE->set_context($context);
// Add css and js requires.
$PAGE->requires->js_call_amd('mod_cobra/cobra', 'initData', [json_encode($cobra)]);
$PAGE->requires->js_call_amd('mod_cobra/cobra', 'entryOnClick');
$PAGE->requires->js_call_amd('mod_cobra/cobra', 'concordanceOnClick');
$PAGE->requires->js_call_amd('mod_cobra/cobra', 'textGlossaryActions');
$output = $PAGE->get_renderer('mod_cobra');
$cobratext = new cobratext($cobra);
$content = $output->render($cobratext);
echo $output->header();
echo $output->heading(get_string('textreading', 'cobra'));
echo $content;
$PAGE->requires->js_call_amd('mod_cobra/cobra', 'initUi');
echo $output->footer();