MDL-44070 Conditional availability enhancements (1): availability fields

Adds a new field 'availability' to the course_modules and
course_sections tables. This will be used to store JSON format
data about a tree of availability restrictions.

Includes changes to modinfolib so that the new fields are available,
and to the editing forms so that they can be entered and modified.
There are unit tests for the back-end (modinfolib).
MDL-44070 Conditional availability enhancements (2): subsystem/plugin

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).
MDL-44070 Conditional availability enhancements (3): API/tests

Implements the new availability/plugin API. This represents a
Boolean tree structure that controls the availability of an
item.

In this commit, the new API is not yet connected to the rest of
Moodle, so it doesn't do anything yet.
MDL-44070 Conditional availability enhancements (4): Backup support

Adds backup and restore support including unit tests. Plugins have
the ability to update necessary IDs after the restore.
MDL-44070 Conditional availability enhancements (5): date condition

Adds date condition (back-end only). Includes new component and unit
tests.

AMOS BEGIN
 MOV [requires_date,core_condition],[from,availability_date]
 MOV [requires_date_before,core_condition],[until,availability_date]
AMOS END
MDL-44070 Conditional availability enhancements (6): grade condition

Adds grade condition (back-end only). Includes new component and unit tests.

AMOS BEGIN
 MOV [requires_grade_any,core_condition],[requires_any,availability_grade]
 MOV [requires_grade_max,core_condition],[requires_max,availability_grade]
 MOV [requires_grade_min,core_condition],[requires_min,availability_grade]
 MOV [requires_grade_range,core_condition],[requires_range,availability_grade]
 MOV [cachedef_gradecondition,core_cache],[cachedef_scores,availability_grade]
AMOS END
MDL-44070 Conditional availability enhancements (7): user profile condition

Adds user profile condition (back-end only). Includes new component and unit tests.

AMOS BEGIN
 MOV [requires_user_field_contains,core_condition],[requires_contains,availability_profile]
 MOV [requires_user_field_doesnotcontain,core_condition],[requires_doesnotcontain,availability_profile]
 MOV [requires_user_field_endswith,core_condition],[requires_endswith,availability_profile]
 MOV [requires_user_field_isempty,core_condition],[requires_isempty,availability_profile]
 MOV [requires_user_field_isequalto,core_condition],[requires_isequalto,availability_profile]
 MOV [requires_user_field_isnotempty,core_condition],[requires_isnotempty,availability_profile]
 MOV [requires_user_field_startswith,core_condition],[requires_startswith,availability_profile]
AMOS END
MDL-44070 Conditional availability enhancements (8): completion condition

Adds activity completion condition (back-end only). Includes new component and
unit tests.

AMOS BEGIN
 MOV [requires_completion_0,core_condition],[requires_0,availability_completion]
 MOV [requires_completion_1,core_condition],[requires_1,availability_completion]
 MOV [requires_completion_2,core_condition],[requires_2,availability_completion]
 MOV [requires_completion_3,core_condition],[requires_3,availability_completion]
AMOS END
MDL-44070 Conditional availability enhancements (9): grouping condition

Adds grouping condition (back-end only). Includes new component and
unit tests.
MDL-44070 Conditional availability enhancements (?): group condition

Adds group condition (back-end only). Includes new component and
unit tests.

(This is a new feature as previously you could only restrict access
on grouping. I thought it made sense to add group support especially
for the 'any group' case which is now needed when handling
groupmembersonly, on an activity without grouping.)
MDL-44070 Conditional availability enhancements (?): core access

Changes core code to use new API instead of the old one when
checking user access to activities and sections.
MDL-44070 Conditional availability enhancements (?): upgrade data

Upgrades existing data to new format. Includes unit test for the
function that does most of the work. Manual testing will also be
required for this point.