mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-58665 mod_scorm: cache times in modinfo for performance
This commit is contained in:
parent
e1577187ed
commit
cd477f8c3e
@ -1627,12 +1627,21 @@ function scorm_refresh_events($courseid = 0) {
|
||||
*/
|
||||
function mod_scorm_core_calendar_provide_event_action(calendar_event $event,
|
||||
\core_calendar\action_factory $factory) {
|
||||
global $CFG, $DB;
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/scorm/locallib.php');
|
||||
|
||||
$cm = get_fast_modinfo($event->courseid)->instances['scorm'][$event->instance];
|
||||
$scorm = $DB->get_record('scorm', array('id' => $event->instance));
|
||||
|
||||
if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < time()) {
|
||||
// The scorm has closed so the user can no longer submit anything.
|
||||
return null;
|
||||
}
|
||||
|
||||
// Restore scorm object from cached values in $cm, we only need id, timeclose and timeopen.
|
||||
$customdata = $cm->customdata ?: [];
|
||||
$customdata['id'] = $cm->instance;
|
||||
$scorm = (object)($customdata + ['timeclose' => 0, 'timeopen' => 0]);
|
||||
|
||||
// Check that the SCORM activity is open.
|
||||
list($actionable, $warnings) = scorm_get_availability_status($scorm);
|
||||
@ -1660,7 +1669,8 @@ function scorm_get_coursemodule_info($coursemodule) {
|
||||
global $DB;
|
||||
|
||||
$dbparams = ['id' => $coursemodule->instance];
|
||||
$fields = 'id, name, intro, introformat, completionstatusrequired, completionscorerequired, completionstatusallscos';
|
||||
$fields = 'id, name, intro, introformat, completionstatusrequired, completionscorerequired, completionstatusallscos, '.
|
||||
'timeopen, timeclose';
|
||||
if (!$scorm = $DB->get_record('scorm', $dbparams, $fields)) {
|
||||
return false;
|
||||
}
|
||||
@ -1679,6 +1689,13 @@ function scorm_get_coursemodule_info($coursemodule) {
|
||||
$result->customdata['customcompletionrules']['completionscorerequired'] = $scorm->completionscorerequired;
|
||||
$result->customdata['customcompletionrules']['completionstatusallscos'] = $scorm->completionstatusallscos;
|
||||
}
|
||||
// Populate some other values that can be used in calendar or on dashboard.
|
||||
if ($scorm->timeopen) {
|
||||
$result->customdata['timeopen'] = $scorm->timeopen;
|
||||
}
|
||||
if ($scorm->timeclose) {
|
||||
$result->customdata['timeclose'] = $scorm->timeclose;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -242,12 +242,8 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
|
||||
// Decorate action event.
|
||||
$actionevent = mod_scorm_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Confirm the event was decorated.
|
||||
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
|
||||
$this->assertEquals(get_string('enter', 'scorm'), $actionevent->get_name());
|
||||
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
|
||||
$this->assertEquals(1, $actionevent->get_item_count());
|
||||
$this->assertFalse($actionevent->is_actionable());
|
||||
// No event on the dashboard if module is closed.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_scorm_core_calendar_provide_event_action_open_in_future() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user