-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
97 lines (84 loc) · 3.63 KB
/
Copy pathlib.php
File metadata and controls
97 lines (84 loc) · 3.63 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
<?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/>.
/**
* Library callbacks for local_spaceit.
*
* Injects the teacher consent controls (spec §13) into the activity settings
* form and persists them. Currently scoped to mod_quiz, the fully wired grade
* source.
*
* @package local_spaceit
* @copyright 2026 Fynn Scharpey
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use local_spaceit\repository\consent_repository;
/** Module types that show the SpaceIt consent controls. */
const LOCAL_SPACEIT_CONSENT_MODNAMES = ['quiz'];
/**
* Add the SpaceIt consent fields to the activity settings form.
*
* @param \moodleform_mod $formwrapper The activity settings form wrapper.
* @param \MoodleQuickForm $mform The raw form being built.
* @return void
*/
function local_spaceit_coursemodule_standard_elements($formwrapper, $mform): void {
$modname = $formwrapper->get_current()->modulename ?? '';
if (!in_array($modname, LOCAL_SPACEIT_CONSENT_MODNAMES, true)) {
return;
}
$mform->addElement('header', 'spaceit_consent', get_string('consent:header', 'local_spaceit'));
$mform->addElement('advcheckbox', 'spaceit_allowed', get_string('consent:spaceitallowed', 'local_spaceit'));
$mform->addHelpButton('spaceit_allowed', 'consent:spaceitallowed', 'local_spaceit');
$mform->setDefault('spaceit_allowed', 0);
$mform->addElement('advcheckbox', 'llm_allowed', get_string('consent:llmallowed', 'local_spaceit'));
$mform->addHelpButton('llm_allowed', 'consent:llmallowed', 'local_spaceit');
$mform->setDefault('llm_allowed', 0);
// LLM grading is only meaningful when SpaceIt tracking is enabled.
$mform->disabledIf('llm_allowed', 'spaceit_allowed', 'notchecked');
// Pre-fill from the stored consent when editing an existing activity.
if ($cm = $formwrapper->get_coursemodule()) {
$consent = (new consent_repository())->get_for_cm((int) $cm->id);
if ($consent !== null) {
$mform->setDefault('spaceit_allowed', $consent->spaceit_allowed);
$mform->setDefault('llm_allowed', $consent->llm_allowed);
}
}
}
/**
* Persist the SpaceIt consent after the activity has been saved.
*
* @param \stdClass $moduleinfo The saved module info (incl. our submitted fields).
* @param \stdClass $course The course.
* @return \stdClass The (unmodified) module info.
*/
function local_spaceit_coursemodule_edit_post_actions($moduleinfo, $course): \stdClass {
global $USER;
if (!in_array($moduleinfo->modulename ?? '', LOCAL_SPACEIT_CONSENT_MODNAMES, true)) {
return $moduleinfo;
}
// Only act when our fields were actually part of the submitted form.
if (!property_exists($moduleinfo, 'spaceit_allowed')) {
return $moduleinfo;
}
(new consent_repository())->set(
(int) $moduleinfo->coursemodule,
(bool) $moduleinfo->spaceit_allowed,
(bool) ($moduleinfo->llm_allowed ?? 0),
(int) $USER->id,
);
return $moduleinfo;
}