-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
133 lines (115 loc) · 4.13 KB
/
lib.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
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
<?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/>.
/**
* Lib.
*
* @package local_assess_type
* @copyright 2024 onwards University College London {@link https://www.ucl.ac.uk/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Stuart Lamour <s.lamour@ucl.ac.uk>
*/
use local_assess_type\assess_type;
/**
* Add Formative or Summative select options to mods.
*
* @param moodleform $formwrapper
* @param MoodleQuickForm $mform
*/
function local_assess_type_coursemodule_standard_elements($formwrapper, $mform) {
global $DB;
// Do not show assessment type options in activity's editing page if not enabled.
if (!get_config('local_assess_type', 'enabled')) {
return;
}
$cm = $formwrapper->get_current();
// Check list of mods where this is enabled.
if (!assess_type::canbesummative($cm->modulename)) {
return; // Exit if not enabled.
}
// Flag if new cm.
$newcm = true;
if ($cmid = $cm->coursemodule) {
$newcm = false;
}
// Flag if locked (normally by SITS marks transfer plugin).
$locked = false;
if ($cmid) {
$locked = assess_type::is_locked($cmid);
}
// Mform element.
$options = [];
$options[''] = get_string('defaultoption', 'local_assess_type');
$options['0'] = get_string('formativeoption', 'local_assess_type');
$options['1'] = get_string('summativeoption', 'local_assess_type');
$options['2'] = get_string('dummyoption', 'local_assess_type');
$attributes = [];
$attributes['required'] = 'required';
// Disable changes when locked.
if ($locked) {
$attributes['disabled'] = 'disabled';
}
$select = $mform->createElement(
'select',
'assessment_type',
get_string('fieldlabel', 'local_assess_type'),
$options,
$attributes
);
// Set to summative when locked.
if ($locked) {
$select->setSelected(1);
}
// Set existing option from db (when not locked or new).
if (!$locked && $cmid) {
if ($record = $DB->get_record('local_assess_type', ['cmid' => $cmid], 'type')) {
$select->setSelected($record->type);
}
}
// Link to edit when cm exists.
$link = '';
if ($cmid) {
$url = new \moodle_url('/local/sitsgradepush/dashboard.php', ['id' => $cm->course]);
$link = '<br>
<a href="' . $url . '" target="_blank">'
. get_string('editinsits', 'local_assess_type') .
'</a>';
}
$info = $mform->createElement('html',
'<div class="col-md-9 offset-md-3 pb-3">'
. get_string('info', 'local_assess_type') . $link .
'</div>');
// Add form elements to the dom.
$mform->insertElementBefore($select, 'introeditor');
$mform->insertElementBefore($info, 'introeditor');
}
/**
* Save Formative or Summative select options.
*
* @param stdClass $data Data from the form submission.
* @param stdClass $course The course.
*/
function local_assess_type_coursemodule_edit_post_actions($data, $course): stdClass {
// Check assessment_type is in $data.
// It is impossible to not be set in GUI, but Behat throws a wobly without this.
if (!isset($data->assessment_type)) {
return $data;
}
// We have data, update the assessment type.
// N.B. Casting (int)assessment_type to stop core Behat error.
assess_type::update_type($course->id, (int)$data->assessment_type, $data->coursemodule);
// Carry on with other form things.
return $data;
}