diff --git a/classes/adler_score.php b/classes/adler_score.php index fb65956..55f9557 100644 --- a/classes/adler_score.php +++ b/classes/adler_score.php @@ -6,7 +6,6 @@ use cm_info; use context_course; use dml_exception; -use local_adler\local\backport\backport_cm_completion_details; use local_adler\local\db\adler_course_module_repository; use local_adler\local\exceptions\not_an_adler_cm_exception; use local_adler\local\exceptions\user_not_enrolled_exception; @@ -66,7 +65,7 @@ public function __construct(cm_info $course_module, int $user_id = null) { * @throws moodle_exception If completion is not enabled for the course module. */ public function get_score_by_completion_state(): float { - $cm_completion_details = backport_cm_completion_details::get_instance( + $cm_completion_details = cm_completion_details::get_instance( get_fast_modinfo($this->course_module->course)->get_cm($this->course_module->id), $this->user_id ); diff --git a/classes/local/backport/backport_cm_completion_details.php b/classes/local/backport/backport_cm_completion_details.php deleted file mode 100644 index 901afca..0000000 --- a/classes/local/backport/backport_cm_completion_details.php +++ /dev/null @@ -1,71 +0,0 @@ -cminfo->completion == COMPLETION_TRACKING_MANUAL; - } - - /** - * Backport from Moodle 4.4 for Moodle versions below 4.3 - * - * Returns whether the overall completion state of this course module should be marked as complete or not. - * This is based on the completion settings of the course module, so when the course module requires a passing grade, - * it will only be marked as complete when the user has passed the course module. Otherwise, it will be marked as complete - * even when the user has failed the course module. - * - * @return bool True when the module can be marked as completed. - */ - public function is_overall_complete(): bool { - $completionstates = []; - if ($this->is_manual()) { - $completionstates = [COMPLETION_COMPLETE]; - } else if ($this->is_automatic()) { - // Successfull completion states depend on the completion settings. - if (property_exists($this->completiondata, 'customcompletion') && !empty($this->completiondata->customcompletion)) { - // If the module has any failed custom completion rule the state could be COMPLETION_COMPLETE_FAIL. - $completionstates = [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]; - } else if (isset($this->completiondata->passgrade)) { - // Passing grade is required. Don't mark it as complete when state is COMPLETION_COMPLETE_FAIL. - $completionstates = [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]; - } else { - // Any grade is required. Mark it as complete even when state is COMPLETION_COMPLETE_FAIL. - $completionstates = [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS, COMPLETION_COMPLETE_FAIL]; - } - } - - return in_array($this->get_overall_completion(), $completionstates); - } - - /** - * From Moodle 4.4 to make backports work, as otherwise the baseclass is returned by this method. - * - * Generates an instance of this class. - * - * @param cm_info $cminfo The course module info instance. - * @param int $userid The user ID that we're fetching completion details for. - * @param bool $returndetails Whether to return completion details or not. - * @return core_cm_completion_details - */ - public static function get_instance(cm_info $cminfo, int $userid, bool $returndetails = true): core_cm_completion_details { - $course = $cminfo->get_course(); - $completioninfo = new \completion_info($course); - return new self($completioninfo, $cminfo, $userid, $returndetails); - } - } -} else { - class backport_cm_completion_details extends core_cm_completion_details {} -} diff --git a/tests/external/trigger_event_cm_viewed_test.php b/tests/external/trigger_event_cm_viewed_test.php index 195ea55..96e09f2 100644 --- a/tests/external/trigger_event_cm_viewed_test.php +++ b/tests/external/trigger_event_cm_viewed_test.php @@ -6,7 +6,6 @@ use local_adler\lib\adler_externallib_testcase; -use local_adler\local\backport\backport_cm_completion_details; use local_adler\local\exceptions\not_an_adler_cm_exception; use local_adler\local\exceptions\not_an_adler_course_exception; use stdClass; @@ -87,12 +86,12 @@ public function test_execute_integration() { // assert both modules are marked as viewed $resource_cm_info = get_fast_modinfo($this->course->id)->get_cm($this->resource_module->cmid); - $resource_view_state = backport_cm_completion_details::get_instance($resource_cm_info, $this->user->id); + $resource_view_state = cm_completion_details::get_instance($resource_cm_info, $this->user->id); $this->assertEquals(1, $resource_view_state->get_details()['completionview']->status); $this->assertTrue($resource_view_state->is_overall_complete()); $h5p_cm_info = get_fast_modinfo($this->course->id)->get_cm($this->h5p_module->cmid); - $h5p_view_state = backport_cm_completion_details::get_instance($h5p_cm_info, $this->user->id); + $h5p_view_state = cm_completion_details::get_instance($h5p_cm_info, $this->user->id); // $this->assertEquals(1, $h5p_view_state->get_details()['completionview']->status); // "viewed" is not tracked if it is not a completion criteria $this->assertFalse($h5p_view_state->is_overall_complete()); diff --git a/tests/local/upgrade/upgrade_3_2_0_to_4_0_0_completionlib_test.php b/tests/local/upgrade/upgrade_3_2_0_to_4_0_0_completionlib_test.php index d699bca..628b8c9 100644 --- a/tests/local/upgrade/upgrade_3_2_0_to_4_0_0_completionlib_test.php +++ b/tests/local/upgrade/upgrade_3_2_0_to_4_0_0_completionlib_test.php @@ -3,7 +3,6 @@ global $CFG; use local_adler\lib\adler_testcase; -use local_adler\local\backport\backport_cm_completion_details; use local_adler\local\exceptions\not_an_adler_course_exception; use local_adler\local\upgrade\upgrade_3_2_0_to_4_0_0_completionlib; @@ -146,7 +145,7 @@ public function test_with_user_attempt() { $completion = new completion_info($course); $completion->update_state(get_fast_modinfo($course)->get_cm($module->cmid), COMPLETION_COMPLETE, $user->id); // verify element is completed for user - $h5p_completion_state = backport_cm_completion_details::get_instance( + $h5p_completion_state = cm_completion_details::get_instance( get_fast_modinfo($course)->get_cm($module->cmid), $user->id ); @@ -162,7 +161,7 @@ public function test_with_user_attempt() { $this->assertEquals(0, $cm->completionview); // verify element is still completed - $h5p_completion_state = backport_cm_completion_details::get_instance( // has to be recreated to reflect completion state change + $h5p_completion_state = cm_completion_details::get_instance( // has to be recreated to reflect completion state change get_fast_modinfo($course)->get_cm($module->cmid), $user->id ); @@ -171,7 +170,7 @@ public function test_with_user_attempt() { // create attempt $this->create_h5p_attempt($module, $course->id, $user->id); // verify element is still completed - $h5p_completion_state = backport_cm_completion_details::get_instance( // has to be recreated to reflect completion state change + $h5p_completion_state = cm_completion_details::get_instance( // has to be recreated to reflect completion state change get_fast_modinfo($course)->get_cm($module->cmid), $user->id );