-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
114 lines (96 loc) · 3.38 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
<?php
/**
* Library of interface functions and constants.
*
* @package mod_nosferatu
* @copyright 2021 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use mod_nosferatu\manager;
/**
* Checks if the activity supports a specific feature.
*
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, false if not, null if doesn't know
*/
function nosferatu_supports(string $feature): ?bool {
switch ($feature) {
case FEATURE_MOD_INTRO:
return true;
case FEATURE_SHOW_DESCRIPTION:
return true;
default:
return null;
}
}
/**
* Saves a new instance of the mod_nosferatu into the database.
*
* Given an object containing all the necessary data, (defined by the form
* in mod_form.php) this function will create a new instance and return the id
* number of the instance.
*
* @param stdClass $data An object from the form.
* @param mod_nosferatu_mod_form $mform The form.
* @return int The id of the newly inserted record.
*/
function nosferatu_add_instance(stdClass $data, mod_nosferatu_mod_form $mform = null): int {
global $DB;
$data->timecreated = time();
$data->timemodified = $data->timecreated;
$cmid = $data->coursemodule;
$data->id = $DB->insert_record(manager::MODULE, $data);
// We need to use context now, so we need to make sure all needed info is already in db.
$DB->set_field('course_modules', 'instance', $data->id, ['id' => $cmid]);
// Extra fields required in grade related functions.
$data->cmid = $data->coursemodule;
return $data->id;
}
/**
* Updates an instance of the mod_nosferatu in the database.
*
* Given an object containing all the necessary data (defined in mod_form.php),
* this function will update an existing instance with new data.
*
* @param stdClass $data An object from the form in mod_form.php.
* @param mod_nosferatu_mod_form $mform The form.
* @return bool True if successful, false otherwise.
*/
function nosferatu_update_instance(stdClass $data, mod_nosferatu_mod_form $mform = null): bool {
global $DB;
$data->timemodified = time();
$data->id = $data->instance;
// Update gradings if grading method or tracking are modified.
$data->cmid = $data->coursemodule;
return $DB->update_record(manager::MODULE, $data);
}
/**
* Removes an instance of the mod_nosferatu from the database.
*
* @param int $id Id of the module instance.
* @return bool True if successful, false on failure.
*/
function nosferatu_delete_instance(int $id): bool {
global $DB;
$activity = $DB->get_record(manager::MODULE, ['id' => $id]);
if (!$activity) {
return false;
}
$DB->delete_records(manager::MODULE, ['id' => $id]);
return true;
}
/**
* Return a list of page types
*
* @param string $pagetype current page type
* @param stdClass|null $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
* @return array array of page types and it's names
*/
function nosferatu_page_type_list(string $pagetype, ?stdClass $parentcontext, stdClass $currentcontext): array {
$modulepagetype = [
'mod-' . manager::MODULE . '-*' => get_string('page-mod-' . manager::MODULE . '-x', manager::MODULE),
];
return $modulepagetype;
}