Skip to content

Commit

Permalink
MDL-65517 block_timeline: Hide completed course modules in Timeline
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
John Yao committed Jul 11, 2019
1 parent f7e1084 commit 96e4446
Show file tree
Hide file tree
Showing 16 changed files with 582 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mod/assign/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
65 changes: 65 additions & 0 deletions mod/assign/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,71 @@ public function test_assign_core_calendar_provide_event_action_duedate_for_stude
$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.
*
Expand Down
8 changes: 8 additions & 0 deletions mod/chat/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 63 additions & 0 deletions mod/chat/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,69 @@ public function test_chat_get_sessions_multiple() {
}
}

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.
*
Expand Down
8 changes: 8 additions & 0 deletions mod/choice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
65 changes: 65 additions & 0 deletions mod/choice/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,71 @@ public function test_choice_core_calendar_provide_event_action_no_time_specified
$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.
*
Expand Down
8 changes: 8 additions & 0 deletions mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
65 changes: 65 additions & 0 deletions mod/feedback/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,71 @@ public function test_feedback_core_calendar_provide_event_action_already_submitt
$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.
*
Expand Down
8 changes: 8 additions & 0 deletions mod/lesson/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading

0 comments on commit 96e4446

Please sign in to comment.