932b094134
- Created sectiondelegatemodule abstract class for those delegated sections managed by a module - This class will override get_parent_section from the base class, retrieving the parent section from the module
91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?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/>.
|
|
|
|
namespace core_courseformat;
|
|
|
|
use cm_info;
|
|
use section_info;
|
|
use stdClass;
|
|
|
|
/**
|
|
* Class sectiondelegatemodule
|
|
*
|
|
* @package core_courseformat
|
|
* @copyright 2024 Mikel Martín <mikel@moodle.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
abstract class sectiondelegatemodule extends sectiondelegate {
|
|
/** @var section_info $sectioninfo The section_info object of the delegated section module */
|
|
|
|
/** @var cm_info|null $cm The cm_info object of the delegated section module */
|
|
private $cm = null;
|
|
|
|
/** @var stdClass|null $course The course object of the delegated section module */
|
|
private $course = null;
|
|
|
|
/**
|
|
* Constructor.
|
|
* @param section_info $sectioninfo
|
|
*/
|
|
public function __construct(
|
|
protected section_info $sectioninfo
|
|
) {
|
|
parent::__construct($sectioninfo);
|
|
|
|
[$this->course, $this->cm] = get_course_and_cm_from_instance(
|
|
$this->sectioninfo->itemid,
|
|
$this->get_module_name(),
|
|
$this->sectioninfo->course,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the parent section of the current delegated section.
|
|
*
|
|
* @return section_info|null
|
|
*/
|
|
public function get_parent_section(): ?section_info {
|
|
return $this->cm->get_section_info();
|
|
}
|
|
|
|
/**
|
|
* Get the course object.
|
|
*
|
|
* @return cm_info
|
|
*/
|
|
public function get_cm(): cm_info {
|
|
return $this->cm;
|
|
}
|
|
|
|
/**
|
|
* Get the course object.
|
|
*
|
|
* @return stdClass
|
|
*/
|
|
public function get_course(): stdClass {
|
|
return $this->course;
|
|
}
|
|
|
|
/**
|
|
* Get the module name from the section component frankenstyle name.
|
|
*
|
|
* @return string
|
|
*/
|
|
private function get_module_name(): string {
|
|
return \core_component::normalize_component($this->sectioninfo->component)[1];
|
|
}
|
|
}
|