Skip to content

Commit

Permalink
Merge branch 'MDL-68717-400' of https://github.com/laurentdavid/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_400_STABLE
  • Loading branch information
sarjona committed Aug 30, 2022
2 parents 76102e0 + ce372c1 commit 401c26a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
9 changes: 7 additions & 2 deletions calendar/classes/local/event/container.php
Expand Up @@ -180,8 +180,13 @@ function ($dbrow) {
$course = new \stdClass();
$course->id = $dbrow->courseid;
$completion = new \completion_info($course);

return (bool) !$completion->is_enabled($cm);
if ($completion->is_enabled($cm)) {
// Check if the event is completed, then in this case we do not need to complete it.
// Make sure we're using a cm_info object.
$completiondata = $completion->get_data($cm);
return intval($completiondata->completionstate) === COMPLETION_COMPLETE;
}
return true;
}

return false;
Expand Down
36 changes: 36 additions & 0 deletions calendar/tests/container_test.php
Expand Up @@ -23,6 +23,7 @@
use core_calendar\local\event\factories\event_factory_interface;
use core_calendar\local\event\mappers\event_mapper;
use core_calendar\local\event\mappers\event_mapper_interface;
use core_completion\api;

defined('MOODLE_INTERNAL') || die();

Expand Down Expand Up @@ -366,6 +367,41 @@ public function test_event_factory_with_completion_related_event() {
$this->assertNull($factory->create_instance($event));
}

/**
* Checks that completed activities events do not show.
* @covers \core_calendar\local\event::init
*/
public function test_event_factory_with_completed_module_related_event() {
global $CFG, $DB;

$this->setAdminUser();

// Create a course.
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);
$user = $this->getDataGenerator()->create_and_enrol($course);
// Create an assign activity with a time set.
$time = time();
$assign = $this->getDataGenerator()->create_module(
'assign', ['course' => $course->id, 'completion' => COMPLETION_TRACKING_MANUAL]);

// Create the event but set it to tomorrow.
$CFG->enablecompletion = true;
api::update_completion_date_event($assign->cmid, 'assign', $assign,
$time + DAYSECS);

$this->setUser($user);
// Check that we get should be completed event.
$this->assertCount(1, \core_calendar\local\event\container::get_event_vault()->get_events());
// Then Complete the activity.
$completion = new \completion_info($course);
$cmassign = get_coursemodule_from_id('assign', $assign->cmid);
// This should trigger another call to the update_completion_date_event.
$completion->update_state($cmassign, COMPLETION_COMPLETE, $user->id);
// Check that we do not see the event anymore.
$this->assertCount(0, \core_calendar\local\event\container::get_event_vault()->get_events());
}


/**
* Test that the event factory only returns an event if the logged in user
* is enrolled in the course.
Expand Down

0 comments on commit 401c26a

Please sign in to comment.