-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.php
73 lines (56 loc) · 1.74 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
<?php
/**
* @package mod_readingspeed
* @copyright 2019, alterego developer {@link https://alteregodeveloper.github.io}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Add readingspeed instance.
*
* @param stdClass $data
* @param stdClass $mform
* @return int new readingspeed instance id
*/
function readingspeed_add_instance($data, $mform) {
global $DB;
$data->timecreated = time();
$data->timemodified = $data->timecreated;
if (!isset($data->customtitles)) {
$data->customtitles = 0;
}
$id = $DB->insert_record('readingspeed', $data);
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($data->coursemodule, 'readingspeed', $id, $completiontimeexpected);
return $id;
}
/**
* Update readingspeed instance.
*
* @param stdClass $data
* @param stdClass $mform
* @return bool true
*/
function readingspeed_update_instance($data, $mform) {
global $DB;
$data->timemodified = time();
$data->id = $data->instance;
$result = $DB->update_record('readingspeed', $data);
return true;
}
/**
* Delete readingspeed instance.
* @param int $id
* @return bool true
*/
function readingspeed_delete_instance($id) {
global $DB;
if (!$readingspeed = $DB->get_record('readingspeed', array('id'=>$id))) {
return false;
}
$cm = get_coursemodule_from_instance('readingspeed', $id);
\core_completion\api::update_completion_date_event($cm->id, 'readingspeed', $id, null);
// note: all context files are deleted automatically
$DB->delete_records('readingspeed', array('id'=>$readingspeed->id));
return true;
}