Skip to content

Commit 73422f4

Browse files
authored
Merge pull request #31 from bdecentgmbh/dev
Call it 1.3
2 parents fd2de58 + 48daed2 commit 73422f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2494
-626
lines changed

.github/workflows/moodle-ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
jobs:
66
test:
7-
runs-on: ubuntu-22.04
7+
runs-on: ubuntu-latest
88

99
services:
1010
postgres:
@@ -16,7 +16,7 @@ jobs:
1616
- 5432:5432
1717
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
1818
mariadb:
19-
image: mariadb:10.6.7
19+
image: mariadb:10.6
2020
env:
2121
MYSQL_USER: 'root'
2222
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
@@ -29,11 +29,11 @@ jobs:
2929
matrix:
3030
include:
3131
- php: '8.3'
32-
moodle-branch: 'MOODLE_405_STABLE'
33-
database: 'pgsql'
34-
- php: '8.2'
3532
moodle-branch: 'MOODLE_405_STABLE'
3633
database: 'mariadb'
34+
- php: '8.3'
35+
moodle-branch: 'MOODLE_405_STABLE'
36+
database: 'pgsql'
3737

3838
steps:
3939
- name: Check out repository code

classes/output/general_action_bar.php

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
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+
namespace local_learningtools\output;
18+
19+
use moodle_url;
20+
use core\output\select_menu;
21+
use core\output\comboboxsearch;
22+
23+
/**
24+
* Renderable class for the general action bar in the gradebook pages.
25+
*
26+
* This class is responsible for rendering the general navigation select menu in the gradebook pages.
27+
*
28+
* @package local_learningtools
29+
* @copyright 2021 bdecent gmbh <https://bdecent.de>
30+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31+
*/
32+
class general_action_bar {
33+
34+
/** @var moodle_url $activeurl The URL that should be set as active in the URL selector element. */
35+
protected $activeurl;
36+
37+
/**
38+
* The type of the current gradebook page (report, settings, import, export, scales, outcomes, letters).
39+
*
40+
* @var string $activetype
41+
*/
42+
protected $activetype;
43+
44+
/** @var string $activeplugin The plugin of the current gradebook page (grader, fullview, ...). */
45+
protected $activeplugin;
46+
47+
/**
48+
* Summary of context
49+
* @var \context
50+
*/
51+
protected $context;
52+
53+
/**
54+
* Course id.
55+
* @var int
56+
*/
57+
protected $courseid;
58+
59+
/**
60+
* Section id.
61+
* @var int
62+
*/
63+
protected $sectionid;
64+
65+
/**
66+
* Activity
67+
* @var int
68+
*/
69+
protected $activity;
70+
71+
/**
72+
* The class constructor.
73+
*
74+
* @param \context $context The context object.
75+
* @param moodle_url $activeurl The URL that should be set as active in the URL selector element.
76+
* @param string $activetype The type of the current gradebook page (report, settings, import, export, scales,
77+
* outcomes, letters).
78+
* @param string $activeplugin The plugin of the current gradebook page (grader, fullview, ...).
79+
* @param int $courseid Course ID.
80+
* @param int $sectionid Section ID.
81+
* @param int $activity Activity ID.
82+
*/
83+
public function __construct(\context $context, moodle_url $activeurl, string $activetype, string $activeplugin, int $courseid,
84+
int $sectionid, int $activity) {
85+
$this->activeurl = $activeurl;
86+
$this->activetype = $activetype;
87+
$this->activeplugin = $activeplugin;
88+
$this->context = $context;
89+
$this->courseid = $courseid;
90+
$this->sectionid = $sectionid;
91+
$this->activity = $activity;
92+
}
93+
94+
/**
95+
* Export the data for the mustache template.
96+
*
97+
* @param \renderer_base $output renderer to be used to render the action bar elements.
98+
* @return array
99+
*/
100+
public function export_for_template(\renderer_base $output): array {
101+
global $USER, $DB;
102+
$selectmenu = $this->get_action_selector();
103+
104+
if (is_null($selectmenu)) {
105+
return [];
106+
}
107+
108+
$collapsemenudirection = right_to_left() ? 'dropdown-menu-left' : 'dropdown-menu-right';
109+
110+
$collapse = new comboboxsearch(
111+
true,
112+
get_string('collapsedcolumns', 'gradereport_grader', 0),
113+
null,
114+
'collapse-columns',
115+
'collapsecolumn',
116+
'collapsecolumndropdown p-3 flex-column ' . $collapsemenudirection,
117+
null,
118+
true,
119+
get_string('aria:dropdowncolumns', 'gradereport_grader'),
120+
'collapsedcolumns'
121+
);
122+
123+
$course = get_course($this->courseid);
124+
125+
$sections = $this->get_sections();
126+
$activities = $this->get_activities();
127+
128+
$viewpageurl = new moodle_url('/local/learningtools/ltool/note/view.php', ['id' => $this->courseid]);
129+
130+
$collapsedcolumns = [
131+
'classes' => 'd-none',
132+
'content' => $collapse->export_for_template($output),
133+
'viewpageurl' => $viewpageurl->out(false),
134+
'sections' => !empty($sections) ? $sections : [],
135+
'activities' => !empty($activities) ? $activities : [],
136+
];
137+
138+
return [
139+
'generalnavselector' => $selectmenu->export_for_template($output),
140+
'collapsedcolumns' => $collapsedcolumns,
141+
];
142+
}
143+
144+
/**
145+
* Returns the template for the action bar.
146+
*
147+
* @return string
148+
*/
149+
public function get_template(): string {
150+
return 'local_learningtools/tertiary_navigation';
151+
}
152+
153+
/**
154+
* Returns the URL selector object.
155+
*
156+
* @return \select_menu|null The URL select object.
157+
*/
158+
private function get_action_selector(): ?select_menu {
159+
if ($this->context->contextlevel !== CONTEXT_COURSE) {
160+
return null;
161+
}
162+
163+
$courseid = $this->context->instanceid;
164+
$menus = [];
165+
166+
// Get all available learning tool subplugins.
167+
$subplugins = local_learningtools_get_subplugins();
168+
169+
// Add each subplugin to the menus.
170+
foreach ($subplugins as $shortname => $toolobj) {
171+
172+
// Check if user has capability to view this tool.
173+
if ($shortname == 'note') {
174+
// Get tool-specific URL if the tool has a navigation method.
175+
if (method_exists($toolobj, 'get_navigation_url')) {
176+
$toolurl = $toolobj->get_navigation_url($courseid);
177+
} else {
178+
// Default URL pattern for tools.
179+
$toolurl = new moodle_url('/local/learningtools/ltool/'.$shortname.'/view.php',
180+
['id' => $courseid]);
181+
}
182+
183+
// Get tool name.
184+
$toolname = get_string('toolname', 'ltool_'.$shortname);
185+
186+
// Add to menus.
187+
$menus[$toolurl->out(false)] = $toolname;
188+
}
189+
}
190+
191+
$selectmenu = new select_menu('learningtoolsselect', $menus, $this->activeurl->out(false));
192+
$selectmenu->set_label(get_string('learningtools', 'local_learningtools'), ['class' => 'sr-only']);
193+
194+
return $selectmenu;
195+
}
196+
197+
/**
198+
* Get the related sections.
199+
*
200+
* @return array
201+
*/
202+
public function get_sections() {
203+
global $USER, $DB;
204+
$course = get_course($this->courseid);
205+
$data = [];
206+
207+
$sql = "SELECT n.*, cm.id as cmid, m.name as modulename
208+
FROM {ltool_note_data} n
209+
LEFT JOIN {course_modules} cm ON cm.id = n.coursemodule
210+
LEFT JOIN {modules} m ON m.id = cm.module
211+
WHERE n.course = :courseid AND n.pagetype = :pagetype
212+
AND n.userid = :userid
213+
ORDER BY n.timecreated DESC";
214+
$params = [
215+
'courseid' => $this->courseid,
216+
'userid' => $USER->id,
217+
'pagetype' => 'course-view-section-' . $course->format,
218+
];
219+
220+
$notes = $DB->get_records_sql($sql, $params);
221+
222+
foreach ($notes as $note) {
223+
$sectionurl = new \moodle_url($note->pageurl);
224+
$sectionid = $sectionurl->get_param('id');
225+
226+
if (!isset($data[$sectionid])) {
227+
$section = $DB->get_record('course_sections', ['course' => $this->courseid, 'id' => $sectionid]);
228+
if ($section) {
229+
$sectionname = $section->name ?: (
230+
$section->section == 0
231+
? get_string('general')
232+
: get_string('section', 'local_learningtools') . ' ' . $section->section
233+
);
234+
235+
$filterurl = new \moodle_url('/local/learningtools/ltool/note/view.php', [
236+
'id' => $this->courseid,
237+
'sectionid' => $section->id,
238+
'filter' => 'section',
239+
]);
240+
241+
$data[$sectionid] = [
242+
'sectionname' => $sectionname,
243+
'sectionid' => $section->id,
244+
'filterurl' => $filterurl->out(false),
245+
'selected' => ($section->id == $this->sectionid) ? "selected" : "",
246+
];
247+
}
248+
}
249+
}
250+
251+
return array_values($data); // Re-index to return a clean list.
252+
}
253+
254+
/**
255+
* Gets the activity selected record.
256+
* @return array course activity selector records.
257+
*/
258+
public function get_activities() {
259+
global $DB, $USER;
260+
261+
$sql = "SELECT lnd.coursemodule, lnd.course
262+
FROM {ltool_note_data} lnd
263+
LEFT JOIN {course_modules} cm ON cm.id = lnd.coursemodule
264+
WHERE cm.deletioninprogress = 0
265+
AND lnd.course = :course
266+
AND lnd.coursemodule != 0
267+
AND lnd.userid = :userid";
268+
269+
$params = [
270+
'course' => $this->courseid,
271+
'userid' => $USER->id,
272+
];
273+
274+
if (!empty($this->sectionid)) {
275+
$sql .= " AND cm.section = :sectionid";
276+
$params['sectionid'] = $this->sectionid;
277+
}
278+
279+
$sql .= " GROUP BY lnd.coursemodule, lnd.course";
280+
281+
$records = $DB->get_records_sql($sql, $params);
282+
$data = [];
283+
284+
if (!empty($records)) {
285+
foreach ($records as $record) {
286+
$record->courseid = $record->course;
287+
$list['mod'] = local_learningtools_get_module_name($record);
288+
$filterurl = new moodle_url('/local/learningtools/ltool/note/view.php', ['id' => $this->courseid,
289+
'activity' => $record->coursemodule,
290+
'filter' => 'activity']);
291+
$list['filterurl'] = $filterurl->out(false);
292+
if ($record->coursemodule == $this->activity) {
293+
$list['selected'] = "selected";
294+
} else {
295+
$list['selected'] = "";
296+
}
297+
$data[] = $list;
298+
}
299+
300+
}
301+
return $data;
302+
}
303+
}

classes/output/renderer.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
* Renderer for learning tools
19+
*
20+
* @package local_learningtools
21+
* @copyright 2023 Your Name
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace local_learningtools\output;
26+
27+
use plugin_renderer_base;
28+
use stdClass;
29+
30+
/**
31+
* Renderer class for learning tools.
32+
*/
33+
class renderer extends plugin_renderer_base {
34+
/**
35+
* Renders the action bar for a given page.
36+
*
37+
* @param general_action_bar $actionbar
38+
* @return string The HTML output
39+
*/
40+
public function render_action_bar(general_action_bar $actionbar): string {
41+
$data = $actionbar->export_for_template($this);
42+
return $this->render_from_template($actionbar->get_template(), $data);
43+
}
44+
}

classes/privacy/provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class provider implements \core_privacy\local\metadata\null_provider {
3434
*
3535
* @return string
3636
*/
37-
public static function get_reason() : string {
37+
public static function get_reason(): string {
3838

3939
return 'privacy:metadata';
4040
}

0 commit comments

Comments
 (0)