-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
99 lines (82 loc) · 3.28 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
<?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/>.
/**
* Functions used by plugin.
*
* @package local_certifaction
* @copyright 2022 Adrian Perez <me@adrianperez.me>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_certifaction\utils;
/**
* Inject the Certifaction settings into all assign module settings forms.
*
* @param moodleform $formwrapper The Moodle quick form wrapper object.
* @param MoodleQuickForm $mform The actual form object (required to modify the form).
* @throws coding_exception
* @throws dml_exception
*/
function local_certifaction_coursemodule_standard_elements(moodleform $formwrapper, MoodleQuickForm $mform) {
global $DB;
if (!$cm = $formwrapper->get_coursemodule()) {
return;
}
if (!get_config('local_certifaction', 'certifactionenabled')) {
return;
}
$name = get_string('certifactionsubmission', 'local_certifaction');
$mform->addElement('header', 'certifcationsection', get_string('pluginname', 'local_certifaction'));
$mform->addElement('selectyesno', 'certifactionsubmission', $name);
$mform->addHelpButton('certifactionsubmission', 'certifactionsubmission', 'local_certifaction');
if ($config = $DB->get_record(utils::CONFIG_TABLE, ['cmid' => $cm->id, 'name' => utils::SUBMISSION_SETTING])) {
$mform->setDefault('certifactionsubmission', $config->value);
}
}
/**
* Hook to save Certifaction specific settings on an assign settings page.
*
* @param stdClass $data
* @param stdClass $course
* @return stdClass
* @throws dml_exception
*/
function local_certifaction_coursemodule_edit_post_actions(stdClass $data, stdClass $course): stdClass {
global $DB, $USER;
if (!get_config('local_certifaction', 'certifactionenabled')) {
return $data;
}
if (!isset($data->certifactionsubmission)) {
return $data;
}
$record = $DB->get_record(utils::CONFIG_TABLE, ['cmid' => $data->coursemodule, 'name' => utils::SUBMISSION_SETTING]);
if (!$record) {
$record = new stdClass();
$record->cmid = $data->coursemodule;
$record->name = utils::SUBMISSION_SETTING;
$record->value = $data->certifactionsubmission;
$record->usermodified = $USER->id;
$record->timecreated = $record->timemodified = time();
$DB->insert_record(utils::CONFIG_TABLE, $record);
return $data;
}
if ($record->value !== $data->certifactionsubmission) {
$record->value = $data->certifactionsubmission;
$record->usermodified = $USER->id;
$record->timemodified = time();
$DB->update_record(utils::CONFIG_TABLE, $record);
}
return $data;
}