-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
217 lines (186 loc) · 6.66 KB
/
Copy pathlib.php
File metadata and controls
217 lines (186 loc) · 6.66 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?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/>.
/**
* Library of interface functions and constants.
*
* @package mod_siyavulaassignment
* @copyright 2026 Siyavula
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/filter/siyavula/lib.php');
/**
* Return if the plugin supports $feature.
*
* @param string $feature Constant representing the feature.
* @return true | null True if the feature is supported, null otherwise.
*/
function siyavulaassignment_supports($feature) {
switch ($feature) {
case FEATURE_GRADE_HAS_GRADE:
return true;
case FEATURE_MOD_INTRO:
return true;
default:
return null;
}
}
/**
* Saves a new instance of the mod_siyavulaassignment into the database.
*
* @param object $moduleinstance An object from the form.
* @param mod_siyavulaassignment_mod_form $mform The form.
* @return int The id of the newly inserted record.
*/
function siyavulaassignment_add_instance($moduleinstance, $mform = null) {
global $DB;
$moduleinstance->timecreated = time();
$moduleinstance->timemodified = time();
$id = $DB->insert_record('siyavulaassignment', $moduleinstance);
$moduleinstance->id = $id;
siyavulaassignment_grade_item_update($moduleinstance);
return $id;
}
/**
* Updates an instance of the mod_siyavulaassignment in the database.
*
* @param object $moduleinstance An object from the form in mod_form.php.
* @param mod_siyavulaassignment_mod_form $mform The form.
* @return bool True if successful, false otherwise.
*/
function siyavulaassignment_update_instance($moduleinstance, $mform = null) {
global $DB;
$moduleinstance->timemodified = time();
$moduleinstance->id = $moduleinstance->instance;
$result = $DB->update_record('siyavulaassignment', $moduleinstance);
siyavulaassignment_grade_item_update($moduleinstance);
return $result;
}
/**
* Removes an instance of the mod_siyavulaassignment from the database.
*
* @param int $id Id of the module instance.
* @return bool True if successful, false on failure.
*/
function siyavulaassignment_delete_instance($id) {
global $DB;
$exists = $DB->get_record('siyavulaassignment', array('id' => $id));
if (!$exists) {
return false;
}
siyavulaassignment_grade_item_delete($exists);
$DB->delete_records('siyavulaassignment', array('id' => $id));
return true;
}
/**
* Is a given scale used by the instance of mod_siyavulaassignment?
*
* @param int $moduleinstanceid ID of an instance of this module.
* @param int $scaleid ID of the scale.
* @return bool Always false — this module uses value grades, not scales.
*/
function siyavulaassignment_scale_used($moduleinstanceid, $scaleid) {
return false;
}
/**
* Checks if scale is being used by any instance of mod_siyavulaassignment.
*
* @param int $scaleid ID of the scale.
* @return bool Always false — this module uses value grades, not scales.
*/
function siyavulaassignment_scale_used_anywhere($scaleid) {
return false;
}
/**
* Creates or updates grade item for the given mod_siyavulaassignment instance.
*
* @param stdClass $moduleinstance Instance object.
* @param mixed $grades Optional grades to write, or 'reset'.
* @return int grade_update() return code.
*/
function siyavulaassignment_grade_item_update($moduleinstance, $grades = null) {
global $CFG;
if (!function_exists('grade_update')) {
require_once($CFG->libdir . '/gradelib.php');
}
$params = [
'itemname' => $moduleinstance->name,
'idnumber' => $moduleinstance->id,
'gradetype' => GRADE_TYPE_VALUE,
'grademax' => 100,
'grademin' => 0,
];
if ($grades === 'reset') {
$params['reset'] = true;
$grades = null;
}
return grade_update('mod/siyavulaassignment', $moduleinstance->course, 'mod', 'siyavulaassignment',
$moduleinstance->id, 0, $grades, $params);
}
/**
* Delete grade item for given mod_siyavulaassignment instance.
*
* @param stdClass $moduleinstance Instance object.
* @return int grade_update() return code.
*/
function siyavulaassignment_grade_item_delete($moduleinstance) {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
return grade_update('mod/siyavulaassignment', $moduleinstance->course, 'mod', 'siyavulaassignment',
$moduleinstance->id, 0, null, ['deleted' => 1]);
}
/**
* Update mod_siyavulaassignment grades in the gradebook.
*
* Needed by {@see grade_update_mod_grades()}.
*
* @param stdClass $moduleinstance Instance object.
* @param int $userid Update grade of specific user only, 0 means all participants.
*/
function siyavulaassignment_update_grades($moduleinstance, $userid = 0) {
// Grades are written directly via the AJAX service; nothing to pull from an external source.
siyavulaassignment_grade_item_update($moduleinstance);
}
/**
* Sets activity completion state based on score and gradepass.
*
* @param stdClass $moduleinstance Instance object.
* @param int $userid User ID.
* @param float $score The score achieved (0-100).
*/
function siyavulaassignment_set_completion($moduleinstance, $userid, $score = 0) {
$course = new stdClass();
$course->id = $moduleinstance->course;
$completion = new completion_info($course);
if (!$completion->is_enabled()) {
return;
}
$cm = get_coursemodule_from_instance('siyavulaassignment', $moduleinstance->id, $moduleinstance->course);
if (empty($cm) || !$completion->is_enabled($cm)) {
return;
}
if ($cm->completion == COMPLETION_TRACKING_AUTOMATIC) {
if ($score > 0) {
if ($score >= $moduleinstance->gradepass) {
$completion->update_state($cm, COMPLETION_COMPLETE_PASS, $userid);
} else {
$completion->update_state($cm, COMPLETION_COMPLETE_FAIL, $userid);
}
} else {
$completion->update_state($cm, COMPLETION_COMPLETE, $userid);
}
}
}