When we unlock completion criteria and save changes 'viewed' criteria
still should be completed if user has viewed activity before. Seems
that that was broken by recent changes. Fixing here.
For hidden grade items we used to mark students as completed if
they have any grade. But this was not working correctly when we
also set pass grade for activity and completion criteria based
on pass grade. So we will have these completion states
Competion criteria 'Receive grade':
No grade - COMPLETION_INCOMPLETE
Grade visible, achieved passing grade - COMPLETION_COMPLETE_PASS
Grade visible, failed passing grade - COMPLETION_COMPLETE_FAIL
Grade hidden - COMPLETION_COMPLETE
Completion criteris 'Receive passing grade'
No grade - COMPLETION_INCOMPLETE
Grade visible, achieved passing grade - COMPLETION_COMPLETE_PASS
Grade visible, failed passing grade - COMPLETION_COMPLETE_FAIL
Grade hidden, achieved passing grade - COMPLETION_COMPLETE_PASS
Grade hidden, failed passing grade - COMPLETION_COMPLETE_FAIL_HIDDEN
PHP before version 8.1 automatically converted stdClass or 'false' to arrays if
function parameter expects array (for example, "reset").
PHP 8.1 shows notices in these situations
When the site uses custom user text fields that would show up in a
user list, the filter for firstname or lastname didnt work anymore.
If a filter was used, no result would show up. Users where shown only
when the course reports where used without filters.
Prior to this patch, the code was fetching all completion data for all
activities in a course, even when the activity was not requested. This
leads to recursion issues as the data has not been added to the cache
before this operation occurs.
To handle this situation, only the requested CM is fetched in full, and
a boolean flag is used to store whether the full data has been fetched.
When returning a partially fetched value from the cache, the flag is
used to determine whether more data must be fetched, and the cache
updated.
The flag is filtered out before the value is returned.
Note: Many of the tests were updated as these were inspecting private
features of the API which should not really be tested.
MDL-71899 produces a regression. When an activity plugin is not present
but it has activities in the DB the course view returns an exception.
With this patch the code will ignore missing modules when calculating
the completion.
- Modified SQL in get_data() to get the activity completion of all course modules without calling get_fast_modinfo() to reduce the DB queries.
- Building activity completion cache for the whole course in one time instead of building the cache for each course module by passing $wholecourse = true to get_data()
Activity modules may not have the associated grade_item created yet. It
used to throw fatal error in that case - even when trying to view the
course or edit the activity. So there was no easy way to recover from
this situation.
The patch is based on reasoning that an activity without grade item is
same as activity without any grades. And as such it is considered
incomplete.
A new unit test is added to cover this specific scenario. The existing
unit test is modified and it does not expect the exception any more.
There does not seem to be any good reason why this situation should be
exceptional.
When an automatic completion condition may have had its state change,
we now unset the cached value for the user's completion in the relevant
activity, so up-to-date values are re-fetched and available to students.
The previous behaviour was that custom conditions would remain cached
until the activity reached overall completion.
* *_get_completion_state() callback functions have been deprecated and
should no longer be used. Plugins that define custom completion rules
must implement the mod_[modname]\completion\custom_completion class that
extends the \core_completion\activity_custom_completion base class.
This class would belong more appropriately within the 'user' API
(core_user) instead of within the 'core' API, since it is
directly related to user data.
Since the class has only just been added to Moodle, now is a good
time to move it.
We should be able to fetch the grade completion status for modules
that do not have custom completion configured. This also improves
unit testing coverage.
Since cm_info::customdata can be of any type, we need to cast it to an
array first before checking for custom completion rules. Otherwise,
an exception can be thrown (e.g. customdata has been set as an stdClass)
In all cases changes have been kept to a minimum while not making
the code completely horrible. For example, there are many instances
where it would probably be better to rewrite a query entirely, but
I have not done that (in order to reduce the risk of changes).
* Update completion_info::get_data() to add other completion
information from a new method called get_other_cm_completion_data().
This allows the storage of the completion statuses of the following
completion rules to completion_info objects:
- 'Students must receive a grade' completion rule.
- Any custom completion rule defined by an activity.
This allows detailed completion information to be fetched for course
modules.
It also allows custom completion statuses to be cached which will help
reduce DB queries when fetching completion statuses.
* Update update_state() to fetch overall completion state from the
module's activity_custom_completion implementation. Falls back to the
*_get_completion_state() callback function.
* Update internal_set_data() to include the other cm completion data
in the updated cache data for the module instance.
Move the current logic for determining the completion status for the
"Student must receive grade" completion rule to a function so it cann
be reused.
Unit test included.
Changes:
- Activities with auto completion and a completion status overridden to
COMPLETION_COMPLETE are no longer processed by normal completion
triggers.
- All activities can still be completed by students when their
completion status has been overridden to COMPLETION_INCOMPLETE, via
either auto or manual triggers.
- Completion unit tests updated
The completion cache is currently not marked as simpledata. On the
course page it is frequently retrieved hundreds of times which results
in many calls to the slow unserialize function. By making a slight
change to the data format (using arrays instead of objects) we can
mark it as simpledata, which will avoid using unserialize.