-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_revisionmanager.php
More file actions
151 lines (123 loc) · 5.1 KB
/
block_revisionmanager.php
File metadata and controls
151 lines (123 loc) · 5.1 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Block revisionmanager is defined here.
*
* @package block_revisionmanager
* @copyright 2025 Your Name <you@example.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/libclasstracker.php');
class block_revisionmanager extends block_base {
/**
* Initializes class member variables.
*/
public function init() {
// Needed by Moodle to differentiate between blocks.
$this->title = get_string('pluginname', 'block_revisionmanager');
}
/**
* Returns the block contents.
*
* @return stdClass The block contents.
*/
public function get_content() {
global $OUTPUT, $PAGE, $COURSE, $DB;
// Show blank if not logged in or is a guest user.
if (!isloggedin() || isguestuser()) {
return null;
}
$context = context_course::instance($COURSE->id);
$isteacher = has_capability('moodle/course:update', $context);
// Block only visible on mod_lesson view.php pages.
// TODO: Extend this block to be visible on other activity pages
if (($PAGE->cm->modname !== 'page') && ($PAGE->cm->modname !== 'book')) {
return null;
}
if ($this->content !== null) {
return $this->content;
}
if (empty($this->instance)) {
$this->content = '';
return $this->content;
}
$this->content = new stdClass();
$this->content->items = [];
$this->content->icons = [];
$this->content->footer = '';
// Add a footer gear icon linking to course plugin page.
$url = new moodle_url('/blocks/revisionmanager/summary.php', ['courseid' => $COURSE->id]);
// $gearicon = $OUTPUT->pix_icon('i/settings', get_string('settings'));
// $this->content->footer = html_writer::link($url, "Course Review Dashboard", []);
$chapterid = null;
// get default chapterid
if (optional_param('chapterid', 0, PARAM_INT)) {
$chapterid = optional_param('chapterid', 0, PARAM_INT);
} else if ($PAGE->cm->modname === 'book') {
// No chapter specified, get first chapter
$cm = get_coursemodule_from_id('book', $PAGE->cm->id, 0, false, MUST_EXIST);
$book = $DB->get_record('book', ['id' => $cm->instance], '*', MUST_EXIST);
$chapters = $DB->get_records('book_chapters', ['bookid' => $book->id], 'pagenum ASC');
$firstchapter = reset($chapters);
$chapterid = $firstchapter->id;
}
if (!empty($this->config->text)) {
$this->content->text = $this->config->text;
} else {
$text = $OUTPUT->render_from_template('block_revisionmanager/learningtracker',
['dashboardurl'=>$url]);
$pageid = $PAGE->cm->id;
$classdata = block_revisionmanager_get_class_engagement_data($COURSE->id, $pageid, $chapterid);
$classdata['isteacher'] = $isteacher;
$text .= $OUTPUT->render_from_template('block_revisionmanager/classtracker',$classdata);
$this->content->text = $text;
}
$params = [
'courseid' => $COURSE->id,
'pagetitle' => $PAGE->title,
'pageid' => $PAGE->cm->id,
'chapterid' =>$chapterid
];
$PAGE->requires->js_call_amd('block_revisionmanager/databasecommunicator', 'init', [$params]);
$PAGE->requires->js_call_amd('block_revisionmanager/boooktocmarker', 'init', [$params]);
$PAGE->requires->css('/blocks/revisionmanager/styles.css');
$PAGE->requires->js_call_amd('block_revisionmanager/classEngagement', 'init', []);
return $this->content;
}
/**
* Defines configuration data.
*
* The function is called immediately after init().
*/
public function specialization() {
// Load user defined title and make sure it's never empty.
if (empty($this->config->title)) {
$this->title = get_string('pluginname', 'block_revisionmanager');
} else {
$this->title = $this->config->title;
}
}
/**
* Sets the applicable formats for the block.
*
* @return string[] Array of pages and permissions.
*/
public function applicable_formats() {
return [
'' => true,
];
}
}