Skip to content

[Issues #172 and 174] Improved course completion condition - #176

Open
Fragonite wants to merge 9 commits into
MOODLE_404_STABLEfrom
course_completion_MOODLE_404_STABLE
Open

[Issues #172 and 174] Improved course completion condition#176
Fragonite wants to merge 9 commits into
MOODLE_404_STABLEfrom
course_completion_MOODLE_404_STABLE

Conversation

@Fragonite

@Fragonite Fragonite commented May 27, 2026

Copy link
Copy Markdown
Contributor

This enhanced condition allows selecting multiple courses at once, improving performance and UX.

It migrates legacy course completion entries to the new format.

Resolves issues #172 and #174.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the legacy single-course completion conditions with a new multi-course “Course completion” condition, and adds an upgrade step intended to migrate existing rule condition records to the new format.

Changes:

  • Introduces course_completion condition supporting multiple courses, “any/all” selection, and before/after date filtering.
  • Adds an upgrade step to migrate legacy course_completed / course_not_completed condition records to the new condition/config format.
  • Removes legacy condition classes and their unit tests, replacing them with a new course_completion test suite.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
version.php Bumps plugin version/release for the upgrade step.
db/upgrade.php Adds migration from legacy course completion conditions to the new course_completion condition.
lang/en/tool_dynamic_cohorts.php Replaces legacy condition strings with new course_completion strings.
classes/local/tool_dynamic_cohorts/condition/course_completion.php New condition implementation (form UI, description, SQL generation, broken checks, event subscriptions).
classes/local/tool_dynamic_cohorts/condition/course_completed.php Removes legacy “course completed” condition.
classes/local/tool_dynamic_cohorts/condition/course_not_completed.php Removes legacy “course not completed” condition.
tests/local/tool_dynamic_cohorts/condition/course_completion_test.php Adds unit tests for the new course_completion condition.
tests/local/tool_dynamic_cohorts/condition/course_completed_test.php Removes legacy tests.
tests/local/tool_dynamic_cohorts/condition/course_not_completed_test.php Removes legacy tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread db/upgrade.php
Comment thread db/upgrade.php
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php
@Fragonite
Fragonite force-pushed the course_completion_MOODLE_404_STABLE branch from 67cd783 to 45d1100 Compare May 27, 2026 04:16
@Fragonite Fragonite changed the title Improved course completion condition [Issues #172 and 174] Improved course completion condition May 27, 2026
@Fragonite

Copy link
Copy Markdown
Contributor Author

Hi @dmitriim this is ready for review. I have looked into the test failures and they are unrelated to this patch.

Comment thread db/upgrade.php Outdated
Comment thread lang/en/tool_dynamic_cohorts.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php Outdated
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php
Comment thread classes/local/tool_dynamic_cohorts/condition/course_completion.php
@Fragonite

Copy link
Copy Markdown
Contributor Author

@copilot are you able to submit a commit that resolves the issues @dmitriim raised?

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown

@copilot are you able to submit a commit that resolves the issues @dmitriim raised?

Done — I pushed commit 2110f3a addressing @dmitriim’s requested fixes: removed the extra upgrade.php blank line, deleted obsolete lang strings, fixed invalid string component usage, fixed missing-course description handling, reduced duplication in course validation logic, and added test coverage for invalid operators plus date-filtered HAVE_NOT_COMPLETED/PERIOD_AFTER SQL paths.

Comment thread lang/en/tool_dynamic_cohorts.php Outdated
$string['condition:course_completion:have_completed'] = 'have completed';
$string['condition:course_completion:have_not_completed'] = 'have not completed';
$string['condition:course_completion:malformed'] = 'Condition configuration is malformed.';
$string['condition:course_completion:missingcourse'] = 'A configured course no longer exists.';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fragonite

I was testing your last changes.

In the following example I have 3 courses configured for the condition. I deleted one of the courses and now I see the following error.

image

It's informative - no doubt, but really doesn't give you all information you would like to have:

  1. Missing other configured courses.
  2. Doesn't actually say what course no longer exists. This is important as you may would like to know what was set up and now is broken.

I'd recommend to modify the message so it has all required information - error, exact course id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, it now reports all errors found along with relevant info such as course id.

Comment thread lang/en/tool_dynamic_cohorts.php Outdated
$string['condition:course_completed_description'] = 'Users who have completed course "{$a->course}" {$a->operator} {$a->timecompleted}';
$string['condition:course_not_completed'] = 'Course not completed';
$string['condition:course_not_completed_description'] = 'Users who have not completed course "{$a->course}"';
$string['condition:course_completion:completionisdisabled'] = 'Completion tracking is disabled for a configured course.';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Image

I have one of the courses with disabled completion, but the message doesn't show me exact course. Would be nice to modify the message and bring all details.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@dmitriim dmitriim Jul 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fragonite it still doesn't show me all configured courses. Only displays one with the error. Which is misleading. Also if you're really trying to make it useful and consistent, I'd recommend to stick with the same display pattern as you do for the courses with enabled completion: display name + link to the course. So the "broken" course still exists and we will provide a link to fix it. Also it will be easy to identify the course id you'd like to remove it form the list of configured course. With just ID it's hard to find out what course is actually broken.

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also when I try to fix the condition it still let me to save it even one of the courses has disabled completion.

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should fail validation and let the user what course is missing completion setting.

@dmitriim

dmitriim commented Jul 7, 2026

Copy link
Copy Markdown
Member

@Fragonite can you please update README to reflect changes?

@dmitriim

dmitriim commented Jul 7, 2026

Copy link
Copy Markdown
Member

@Fragonite can you please fix CI complains related to this change?

@Fragonite
Fragonite force-pushed the course_completion_MOODLE_404_STABLE branch from 1f7bd3d to f61b15a Compare July 8, 2026 05:09
@Fragonite
Fragonite force-pushed the course_completion_MOODLE_404_STABLE branch from ed409d7 to 30fb761 Compare July 8, 2026 05:35
@Fragonite

Copy link
Copy Markdown
Contributor Author

@dmitriim CI is green and the readme has been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants