diff --git a/mod/data/lib.php b/mod/data/lib.php index 4bedd87c42e..fba383982f6 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -4298,21 +4298,19 @@ function data_check_updates_since(cm_info $cm, $from, $filter = array()) { */ function mod_data_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) { - global $DB; $cm = get_fast_modinfo($event->courseid)->instances['data'][$event->instance]; - $data = $DB->get_record('data', array('id' => $event->instance), 'id, timeavailablefrom, timeavailableto'); + $now = time(); - if ($data->timeavailablefrom && $data->timeavailableto) { - $actionable = (time() >= $data->timeavailablefrom) && (time() <= $data->timeavailableto); - } else if ($data->timeavailableto) { - $actionable = time() < $data->timeavailableto; - } else if ($data->timeavailablefrom) { - $actionable = time() >= $data->timeavailablefrom; - } else { - $actionable = true; + if (!empty($cm->customdata['timeavailableto']) && $cm->customdata['timeavailableto'] < $now) { + // The module has closed so the user can no longer submit anything. + return null; } + // The module is actionable if we don't have a start time or the start time is + // in the past. + $actionable = (empty($cm->customdata['timeavailablefrom']) || $cm->customdata['timeavailablefrom'] <= $now); + return $factory->create_instance( get_string('add', 'data'), new \moodle_url('/mod/data/view.php', array('id' => $cm->id)), @@ -4336,7 +4334,7 @@ function data_get_coursemodule_info($coursemodule) { global $DB; $dbparams = ['id' => $coursemodule->instance]; - $fields = 'id, name, intro, introformat, completionentries'; + $fields = 'id, name, intro, introformat, completionentries, timeavailablefrom, timeavailableto'; if (!$data = $DB->get_record('data', $dbparams, $fields)) { return false; } @@ -4353,6 +4351,13 @@ function data_get_coursemodule_info($coursemodule) { if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) { $result->customdata['customcompletionrules']['completionentries'] = $data->completionentries; } + // Other properties that may be used in calendar or on dashboard. + if ($data->timeavailablefrom) { + $result->customdata['timeavailablefrom'] = $data->timeavailablefrom; + } + if ($data->timeavailableto) { + $result->customdata['timeavailableto'] = $data->timeavailableto; + } return $result; } diff --git a/mod/data/tests/lib_test.php b/mod/data/tests/lib_test.php index d2a525dc620..ca6e0bedf8c 100644 --- a/mod/data/tests/lib_test.php +++ b/mod/data/tests/lib_test.php @@ -1099,12 +1099,8 @@ class mod_data_lib_testcase extends advanced_testcase { // Decorate action event. $actionevent = mod_data_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('add', 'data'), $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_data_core_calendar_provide_event_action_open_in_future() {