MDL-55158 mod_data: Add calendar events for database activities

This commit is contained in:
Stephen Bourget
2016-07-18 18:35:37 -04:00
parent 5a1728df39
commit 87d6e85a9a
4 changed files with 182 additions and 2 deletions
+47 -2
View File
@@ -904,7 +904,8 @@ function data_tags_check($dataid, $template) {
* @return int intance id
*/
function data_add_instance($data, $mform = null) {
global $DB;
global $DB, $CFG;
require_once($CFG->dirroot.'/mod/data/locallib.php');
if (empty($data->assessed)) {
$data->assessed = 0;
@@ -919,6 +920,9 @@ function data_add_instance($data, $mform = null) {
$data->id = $DB->insert_record('data', $data);
// Add calendar events if necessary.
data_set_events($data);
data_grade_item_update($data);
return $data->id;
@@ -932,7 +936,8 @@ function data_add_instance($data, $mform = null) {
* @return bool
*/
function data_update_instance($data) {
global $DB, $OUTPUT;
global $DB, $CFG;
require_once($CFG->dirroot.'/mod/data/locallib.php');
$data->timemodified = time();
$data->id = $data->instance;
@@ -952,6 +957,9 @@ function data_update_instance($data) {
$DB->update_record('data', $data);
// Add calendar events if necessary.
data_set_events($data);
data_grade_item_update($data);
return true;
@@ -992,6 +1000,13 @@ function data_delete_instance($id) { // takes the dataid
$DB->delete_records('data_records', array('dataid'=>$id));
$DB->delete_records('data_fields', array('dataid'=>$id));
// Remove old calendar events.
$events = $DB->get_records('event', array('modulename' => 'data', 'instance' => $id));
foreach ($events as $event) {
$event = calendar_event::load($event);
$event->delete();
}
// Delete the instance itself
$result = $DB->delete_records('data', array('id'=>$id));
@@ -3965,3 +3980,33 @@ function data_process_submission(stdClass $mod, $fields, stdClass $datarecord) {
return $result;
}
/**
* This standard function will check all instances of this module
* and make sure there are up-to-date events created for each of them.
* If courseid = 0, then every data event in the site is checked, else
* only data events belonging to the course specified are checked.
* This function is used, in its new format, by restore_refresh_events()
*
* @param int $courseid
* @return bool
*/
function data_refresh_events($courseid = 0) {
global $DB, $CFG;
require_once($CFG->dirroot.'/mod/data/locallib.php');
if ($courseid) {
if (! $data = $DB->get_records("data", array("course" => $courseid))) {
return true;
}
} else {
if (! $data = $DB->get_records("data")) {
return true;
}
}
foreach ($data as $datum) {
data_set_events($datum);
}
return true;
}