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
|
@ -78,7 +78,12 @@ function survey_add_instance($survey) {
|
|||
$survey->timecreated = time();
|
||||
$survey->timemodified = $survey->timecreated;
|
||||
|
||||
return $DB->insert_record("survey", $survey);
|
||||
$id = $DB->insert_record("survey", $survey);
|
||||
|
||||
$completiontimeexpected = !empty($survey->completionexpected) ? $survey->completionexpected : null;
|
||||
\core_completion\api::update_completion_date_event($survey->coursemodule, 'survey', $id, $completiontimeexpected);
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
@ -102,6 +107,9 @@ function survey_update_instance($survey) {
|
|||
$survey->questions = $template->questions;
|
||||
$survey->timemodified = time();
|
||||
|
||||
$completiontimeexpected = !empty($survey->completionexpected) ? $survey->completionexpected : null;
|
||||
\core_completion\api::update_completion_date_event($survey->coursemodule, 'survey', $survey->id, $completiontimeexpected);
|
||||
|
||||
return $DB->update_record("survey", $survey);
|
||||
}
|
||||
|
||||
|
@ -121,6 +129,9 @@ function survey_delete_instance($id) {
|
|||
return false;
|
||||
}
|
||||
|
||||
$cm = get_coursemodule_from_instance('survey', $id);
|
||||
\core_completion\api::update_completion_date_event($cm->id, 'survey', $id, null);
|
||||
|
||||
$result = true;
|
||||
|
||||
if (! $DB->delete_records("survey_analysis", array("survey"=>$survey->id))) {
|
||||
|
@ -1074,3 +1085,37 @@ function survey_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
|||
}
|
||||
return $updates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_survey_core_calendar_provide_event_action(\core_calendar\event $event,
|
||||
\core_calendar\action_factory $factory) {
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['survey'][$event->instance];
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
if (!has_capability('mod/survey:participate', $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/survey/view.php', ['id' => $cm->id]),
|
||||
1,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue