mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-57878 mod_*: added inclusion of completion event and callbacks
Part of MDL-55611 epic.
This commit is contained in:
parent
88d14007b3
commit
b3bd7a66a0
12 changed files with 487 additions and 5 deletions
|
@ -88,7 +88,12 @@ function book_add_instance($data, $mform) {
|
|||
$data->customtitles = 0;
|
||||
}
|
||||
|
||||
return $DB->insert_record('book', $data);
|
||||
$id = $DB->insert_record('book', $data);
|
||||
|
||||
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
|
||||
\core_completion\api::update_completion_date_event($data->coursemodule, 'book', $id, $completiontimeexpected);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,6 +117,9 @@ function book_update_instance($data, $mform) {
|
|||
$book = $DB->get_record('book', array('id'=>$data->id));
|
||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||
|
||||
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
|
||||
\core_completion\api::update_completion_date_event($data->coursemodule, 'book', $book->id, $completiontimeexpected);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -128,6 +136,9 @@ function book_delete_instance($id) {
|
|||
return false;
|
||||
}
|
||||
|
||||
$cm = get_coursemodule_from_instance('book', $id);
|
||||
\core_completion\api::update_completion_date_event($cm->id, 'book', $id, null);
|
||||
|
||||
$DB->delete_records('book_chapters', array('bookid'=>$book->id));
|
||||
$DB->delete_records('book', array('id'=>$book->id));
|
||||
|
||||
|
@ -686,3 +697,37 @@ function mod_book_get_fontawesome_icon_map() {
|
|||
'mod_book:nav_exit' => 'fa-arrow-up',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles creating actions for events.
|
||||
*
|
||||
* @param \core_calendar\event $event
|
||||
* @param \core_calendar\action_factory $factory
|
||||
* @return \core_calendar\local\event\value_objects\action|\core_calendar\local\interfaces\action_interface|null
|
||||
*/
|
||||
function mod_book_core_calendar_provide_event_action(\core_calendar\event $event,
|
||||
\core_calendar\action_factory $factory) {
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['book'][$event->instance];
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
if (!has_capability('mod/book:read', $context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$course = new stdClass();
|
||||
$course->id = $event->courseid;
|
||||
$completion = new \completion_info($course);
|
||||
|
||||
$completiondata = $completion->get_data($cm, false);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $factory->create_instance(
|
||||
get_string('view'),
|
||||
new \moodle_url('/mod/book/view.php', ['id' => $cm->id]),
|
||||
1,
|
||||
true
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue