This has been generated running the following Sniff,
part of the Moodle's CodeSniffer standard:
- PSR2.Methods.MethodDeclaration
It just ensures all the function declarations have
the correct order for:
- abstract and final.
- visibility (public, protected, private).
- static.
So, all the lines modified by this commit are function declarations
and the only changes are in the positions of those keywords.
This has been generated running the following Sniffs, all
them part of the Moodle's CodeSniffer standard:
- PSR12.Functions.ReturnTypeDeclaration
- PSR12.Functions.NullableTypeDeclaration
- moodle.Methods.MethodDeclarationSpacing
- Squiz.Whitespace.ScopeKeywordSpacing
All them are, exclusively, about correct spacing, so the changes
are, all them, only white space changes.
Only exceptions to the above are 3 changes what were setting the
return type in a new line, and, when that happens, the closing
parenthesis (bracket) has to go to the same line than the colon.
Previously, groups with GROUP_VISIBILITY_NONE could be selected for an
availability condition, but as the group API did not return a user's own
groups with this visibility, the condition's is_available check always
failed.
This change uses the new $includehidden parameter to get all of a user's
groups from groups_get_user_groups when evaluating the condition, so
these groups work as expected. Due to the enforced hiding of conditions
containing these groups, they will never be seen by the user.
* Changing the name of an activity should change the access restriction messages.
* Introduction of a marker as data-cm-name-for to be able to change any
occurence of a course module name in the page when this one changes.
- Remove 'showmore' logic from the base availability_info renderable.
Other components rendering the availability information should handle the showmore/showless behaviour themselves.
- Deprecate JS module and string.
- Move availability_info header generation logic to a new protected function to improve code readability.
This allows an availability plugin to indicate that a selected condition
should be considered "private", and therefore should never be shown to
users who don't satisfy the criteria. The availability_groups plugin
uses this to protect visibility of groups that are not visible to
non-members.
The availability condition get_description method is called while
gathering data for the modinfo object. As such it is not safe to
call other functions which might rely on modinfo, such as format_string
(if using filters which access modinfo).
This change provides a mechanism to call format_string later, and also
a general callback to do other stuff later as well if needed. It uses
the same approach already taken to make activity names work correctly
in the availability_condition class.
These recursive calls didn't work in PHP 7.3 and below, but in PHP
7.4 they also cause a fatal error which means if you have invalid
availability data, the whole page might die.
1) There is no need to store the 'timemodified' value of
the section when backing up a course module, they do
not refer to the same time.
2) When creating a new course section during restore use
the current time.
3) Added timemodified value to more places when updating
the 'course_sections' table.
Static variables do not behave the way you might expect when accessing
them through the classes inheritance. When accessing a method via self::
or static:: operators, even though the method is inherited, its variable
scope is not. So the method unique_sql_parameter() was using the scope
of the child class and each child class had its own sequence of usp1,
usp2, usp3, ... placeholders. This led to "Incorrect number of query
parameters" error when multiuple condition classes were contributing to
a single SQL query.
All credit should go to Adam Olley who debugged and described the
essence of the problem in the tracker.
When filtering a user list, if there is an OR tree where one of the
conditions does not restrict user lists such as a date condition,
then the overall result should include all users (not be filtered).
This was not working correctly.
There was a fatal error when calendar event linked to non-extant activities.
Now, instead of throwing an exception when a course_module does not exist, is_user_visible() will print a debug statement.
As part of the unit test modifications for this change, I added the get_json
function to the availability conditions that didn't have it. (This is a function
for use in unit tests.)
If a cm isn't in modinfo's cm list, then the user shouldn't be able to see that cm.
This fixes an issue where hidden activities would cause users to be unable to use moodle.
The previous API included a facility to filter a list of users
to include only those who are allowed to access an activity, i.e.
only people who belong to the required groups etc.
This change adds a new API function to return SQL that obtains
this list of users, so that it can be combined with other
queries.
Previously there was no way in PHP to create the JSON values used for
availability, except by manually hard-coding them (the main code to
do this normally is in JavaScript).
This makes unit tests hard to read, so I have implemented static
functions tree::get_root_json and tree::get_nested_json which allow
for easier-to-read unit tests.
Remove groupmembersonly usage in the core_availability API, and change
the update code (used in backup) so that it considers groupmembersonly
when restoring old backups.
If there is invalid data in the availability condition (note: this
should not happen, but can do in unusual situations, such as
specifying a date after 2038 in 32-bit PHP), this should not
leave the course so broken that users cannot edit the activity and
update it.
Includes all the conditions that were in previous Moodle versions:
* Date
* Grade
* Completion (of another activity)
* User profile field
Also includes conditions that are used to reimplement
groupmembersonly:
* Grouping
* Group
For each condition, the component plus unit tests are included.
PLEASE NOTE: The code to actually check each condition is reused
from previous Moodle versions and has not been modified except to
pass codechecker. This is intentional, to reduce the risk of the
change and maximise the chance that behaviour is preserved. Some
of this code might not be very good and might need updating but
that can happen separately.
AMOS BEGIN
CPY [contains,core_condition],[op_contains,availability_profile]
CPY [doesnotcontain,core_condition],[op_doesnotcontain,availability_profile]
CPY [endswith,core_condition],[op_endswith,availability_profile]
CPY [isempty,core_condition],[op_isempty,availability_profile]
CPY [isequalto,core_condition],[op_isequalto,availability_profile]
CPY [isnotempty,core_condition],[op_isnotempty,availability_profile]
CPY [startswith,core_condition],[op_startswith,availability_profile]
CPY [completion_fail,core_condition],[option_fail,availability_completion]
CPY [completion_pass,core_condition],[option_pass,availability_completion]
CPY [completion_complete,core_condition],[option_complete,availability_completion]
CPY [completion_incomplete,core_condition],[option_incomplete,availability_completion]
AMOS END
This commit defines the new /availability root folder, with
/availability/classes, /availability/tests, and
/availability/condition where the condition plugins will live.
Condition plugin prefix is availability_, e.g. availability_date.
Rationale for this organisation:
1. I was originally going to put this in /lib/availability but
it has been pointed out that putting even more junk in lib
is probably bad.
2. 'availability' and 'condition' are the two names used in code
to refer to this system ($CFG->enableavailability).
3. The prefix has to be short enough to allow database tables
(although in practice I assume that condition plugins will not
normally contain database tables).
The new API includes a Boolean tree structure that controls the
availability of an item.
AMOS BEGIN
CPY [availabilityconditions,core_condition],[restrictaccess,core_availability]
CPY [enableavailability,core_condition],[enableavailability,core_availability]
CPY [configenableavailability,core_condition],[enableavailability_desc,core_availability]
AMOS END