2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Class handles conditional availability information for a section.
20 * @package core_availability
21 * @copyright 2014 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_availability
;
27 defined('MOODLE_INTERNAL') ||
die();
30 * Class handles conditional availability information for a section.
32 * @package core_availability
33 * @copyright 2014 The Open University
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class info_section
extends info
{
37 /** @var \section_info Section. */
41 * Constructs with item details.
43 * @param \section_info $section Section object
45 public function __construct(\section_info
$section) {
46 parent
::__construct($section->modinfo
->get_course(), $section->visible
,
47 $section->availability
);
48 $this->section
= $section;
51 protected function get_thing_name() {
52 return get_section_name($this->section
->course
, $this->section
->section
);
55 public function get_context() {
56 return \context_course
::instance($this->get_course()->id
);
59 protected function get_view_hidden_capability() {
60 return 'moodle/course:ignoreavailabilityrestrictions';
63 protected function set_in_database($availability) {
66 $section = new \
stdClass();
67 $section->id
= $this->section
->id
;
68 $section->availability
= $availability;
69 $section->timemodified
= time();
70 $DB->update_record('course_sections', $section);
74 * Gets the section object. Intended for use by conditions.
76 * @return \section_info Section
78 public function get_section() {
79 return $this->section
;