MDL-65517 block_timeline: Hide completed course modules in Timeline
When some activities are manually completed by students, some are still showing in students' timeline. This commit fix that for module assign,chat,choice,feedback,lesson,quiz,scorm and workshop.
This commit is contained in:
@@ -1555,6 +1555,14 @@ function mod_assign_core_calendar_provide_event_action(calendar_event $event,
|
||||
$cm = get_fast_modinfo($event->courseid, $userid)->instances['assign'][$event->instance];
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$assign = new assign($context, $cm, null);
|
||||
|
||||
// Apply overrides.
|
||||
|
||||
@@ -667,6 +667,71 @@ class mod_assign_lib_testcase extends advanced_testcase {
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_assign_core_calendar_provide_event_action_already_completed() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$assign = $this->create_instance($course,
|
||||
['completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS]);
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('assign', $assign->get_instance()->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course, $assign,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_assign_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_assign_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$assign = $this->create_instance($course,
|
||||
['completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS]);
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('assign', $assign->get_instance()->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course, $assign,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_assign_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
@@ -1401,6 +1401,14 @@ function mod_chat_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$chattime = $DB->get_field('chat', 'chattime', array('id' => $event->instance));
|
||||
$usertimezone = core_date::get_user_timezone($user);
|
||||
$chattimemidnight = usergetmidnight($chattime, $usertimezone);
|
||||
|
||||
@@ -635,6 +635,69 @@ class mod_chat_lib_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
public function test_chat_core_calendar_provide_event_action_already_completed() {
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('chat', $chat->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $chat->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_chat_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_chat_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('chat', $chat->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $chat->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_chat_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
@@ -1166,6 +1166,14 @@ function mod_choice_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
|
||||
if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < $now) {
|
||||
|
||||
@@ -714,6 +714,71 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertTrue($actionevent->is_actionable());
|
||||
}
|
||||
|
||||
public function test_choice_core_calendar_provide_event_action_already_completed() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$choice = $this->getDataGenerator()->create_module('choice', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('choice', $choice->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $choice->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_choice_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_choice_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$choice = $this->getDataGenerator()->create_module('choice', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('choice', $choice->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $choice->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_choice_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
@@ -3029,6 +3029,14 @@ function mod_feedback_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$feedbackcompletion = new mod_feedback_completion(null, $cm, 0, false, null, null, $userid);
|
||||
|
||||
if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < time()) {
|
||||
|
||||
@@ -541,6 +541,71 @@ class mod_feedback_lib_testcase extends advanced_testcase {
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_feedback_core_calendar_provide_event_action_already_completed() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$feedback = $this->getDataGenerator()->create_module('feedback', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $feedback->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_feedback_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_feedback_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$feedback = $this->getDataGenerator()->create_module('feedback', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $feedback->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_feedback_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
@@ -1501,6 +1501,14 @@ function mod_lesson_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
|
||||
|
||||
if ($lesson->count_user_retries($userid)) {
|
||||
|
||||
@@ -648,6 +648,71 @@ class mod_lesson_lib_testcase extends advanced_testcase {
|
||||
$this->assertNull($action);
|
||||
}
|
||||
|
||||
public function test_lesson_core_calendar_provide_event_action_already_completed() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$lesson = $this->getDataGenerator()->create_module('lesson', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('lesson', $lesson->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $lesson->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_lesson_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_lesson_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$lesson = $this->getDataGenerator()->create_module('lesson', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('lesson', $lesson->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $lesson->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_lesson_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
@@ -2073,6 +2073,14 @@ function mod_quiz_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
quiz_update_effective_access($quiz, $userid);
|
||||
|
||||
// Check if quiz is closed, if so don't display it.
|
||||
|
||||
@@ -846,6 +846,71 @@ class mod_quiz_lib_testcase extends advanced_testcase {
|
||||
$this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id));
|
||||
}
|
||||
|
||||
public function test_quiz_core_calendar_provide_event_action_already_completed() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $quiz->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_quiz_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_quiz_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $quiz->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
@@ -1660,6 +1660,14 @@ function mod_scorm_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!empty($cm->customdata['timeclose']) && $cm->customdata['timeclose'] < time()) {
|
||||
// The scorm has closed so the user can no longer submit anything.
|
||||
return null;
|
||||
|
||||
@@ -408,6 +408,71 @@ class mod_scorm_lib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertTrue($actionevent->is_actionable());
|
||||
}
|
||||
|
||||
public function test_scorm_core_calendar_provide_event_action_already_completed() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $scorm->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_scorm_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_scorm_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $scorm->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_scorm_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
@@ -1807,6 +1807,14 @@ function mod_workshop_core_calendar_provide_event_action(calendar_event $event,
|
||||
return null;
|
||||
}
|
||||
|
||||
$completion = new \completion_info($cm->get_course());
|
||||
|
||||
$completiondata = $completion->get_data($cm, false, $userid);
|
||||
|
||||
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $factory->create_instance(
|
||||
get_string('viewworkshopsummary', 'workshop'),
|
||||
new \moodle_url('/mod/workshop/view.php', array('id' => $cm->id)),
|
||||
|
||||
@@ -309,6 +309,71 @@ class mod_workshop_lib_testcase extends advanced_testcase {
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_workshop_core_calendar_provide_event_action_already_completed() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('workshop', $workshop->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $workshop->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event.
|
||||
$actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
public function test_workshop_core_calendar_provide_event_action_already_completed_for_user() {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablecompletion', 1);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create the activity.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
|
||||
|
||||
// Enrol a student in the course.
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Get some additional data.
|
||||
$cm = get_coursemodule_from_instance('workshop', $workshop->id);
|
||||
|
||||
// Create a calendar event.
|
||||
$event = $this->create_action_event($course->id, $workshop->id,
|
||||
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
|
||||
|
||||
// Mark the activity as completed for the student.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm, $student->id);
|
||||
|
||||
// Create an action factory.
|
||||
$factory = new \core_calendar\action_factory();
|
||||
|
||||
// Decorate action event for the student.
|
||||
$actionevent = mod_workshop_core_calendar_provide_event_action($event, $factory, $student->id);
|
||||
|
||||
// Ensure result was null.
|
||||
$this->assertNull($actionevent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action event.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user