MDL-44070 Conditional availability enhancements (2): subsystem, API
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
2014-03-26 12:02:30 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class handles conditional availability information for a section.
|
|
|
|
*
|
|
|
|
* @package core_availability
|
|
|
|
* @copyright 2014 The Open University
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace core_availability;
|
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class handles conditional availability information for a section.
|
|
|
|
*
|
|
|
|
* @package core_availability
|
|
|
|
* @copyright 2014 The Open University
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
class info_section extends info {
|
|
|
|
/** @var \section_info Section. */
|
|
|
|
protected $section;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs with item details.
|
|
|
|
*
|
|
|
|
* @param \section_info $section Section object
|
|
|
|
*/
|
|
|
|
public function __construct(\section_info $section) {
|
2014-04-10 20:23:16 +08:00
|
|
|
parent::__construct($section->modinfo->get_course(), $section->visible,
|
MDL-44070 Conditional availability enhancements (2): subsystem, API
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
2014-03-26 12:02:30 +00:00
|
|
|
$section->availability);
|
|
|
|
$this->section = $section;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function get_thing_name() {
|
|
|
|
return get_section_name($this->section->course, $this->section->section);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_context() {
|
|
|
|
return \context_course::instance($this->get_course()->id);
|
|
|
|
}
|
|
|
|
|
2015-01-05 15:46:09 +00:00
|
|
|
protected function get_view_hidden_capability() {
|
2017-01-12 17:16:25 -08:00
|
|
|
return 'moodle/course:ignoreavailabilityrestrictions';
|
2015-01-05 15:46:09 +00:00
|
|
|
}
|
|
|
|
|
MDL-44070 Conditional availability enhancements (2): subsystem, API
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
2014-03-26 12:02:30 +00:00
|
|
|
protected function set_in_database($availability) {
|
|
|
|
global $DB;
|
2017-04-11 12:56:05 +08:00
|
|
|
|
|
|
|
$section = new \stdClass();
|
|
|
|
$section->id = $this->section->id;
|
|
|
|
$section->availability = $availability;
|
|
|
|
$section->timemodified = time();
|
|
|
|
$DB->update_record('course_sections', $section);
|
MDL-44070 Conditional availability enhancements (2): subsystem, API
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
2014-03-26 12:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the section object. Intended for use by conditions.
|
|
|
|
*
|
2014-05-14 14:24:25 +08:00
|
|
|
* @return \section_info Section
|
MDL-44070 Conditional availability enhancements (2): subsystem, API
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
2014-03-26 12:02:30 +00:00
|
|
|
*/
|
|
|
|
public function get_section() {
|
|
|
|
return $this->section;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|