MDL-59287 core_completion: Update API to use less DB calls.

This commit is contained in:
Adrian Greeve 2017-06-29 09:05:46 +08:00
parent 350700bf8b
commit 1930749f46

View File

@ -45,18 +45,23 @@ class api {
*
* @param int $cmid The course module id
* @param string $modulename The name of the module (eg. assign, quiz)
* @param int $instanceid The instance idLOL
* @param stdClass|int $instanceorid The instance object or ID.
* @param int|null $completionexpectedtime The time completion is expected, null if not set
* @return bool
*/
public static function update_completion_date_event($cmid, $modulename, $instanceid, $completionexpectedtime) {
public static function update_completion_date_event($cmid, $modulename, $instanceorid, $completionexpectedtime) {
global $CFG, $DB;
// Required for calendar constant CALENDAR_EVENT_TYPE_ACTION.
require_once($CFG->dirroot . '/calendar/lib.php');
$instance = $DB->get_record($modulename, array('id' => $instanceid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $instance->course), '*', MUST_EXIST);
$instance = null;
if (is_object($instanceorid)) {
$instance = $instanceorid;
} else {
$instance = $DB->get_record($modulename, array('id' => $instanceorid), '*', MUST_EXIST);
}
$course = get_course($instance->course);
$completion = new \completion_info($course);