. namespace core_courseformat\output\local\state; use core_courseformat\base as course_format; use section_info; use renderable; use stdClass; /** * Contains the ajax update section structure. * * @package core_course * @copyright 2021 Ferran Recio * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class section implements renderable { /** @var course_format the course format class */ protected $format; /** @var section_info the course section class */ protected $section; /** * Constructor. * * @param course_format $format the course format * @param section_info $section the section info */ public function __construct(course_format $format, section_info $section) { $this->format = $format; $this->section = $section; } /** * Export this data so it can be used as state object in the course editor. * * @param renderer_base $output typically, the renderer that's calling this function * @return array data context for a mustache template */ public function export_for_template(\renderer_base $output): stdClass { $format = $this->format; $course = $format->get_course(); $section = $this->section; $modinfo = $format->get_modinfo(); $data = (object)[ 'id' => $section->id, 'section' => $section->section, 'number' => $section->section, 'title' => $format->get_section_name($section), 'rawtitle' => $section->name, 'cmlist' => [], 'visible' => !empty($section->visible), 'sectionurl' => course_get_url($course, $section->section)->out(), 'current' => $format->is_section_current($section), ]; if (empty($modinfo->sections[$section->section])) { return $data; } foreach ($modinfo->sections[$section->section] as $modnumber) { $mod = $modinfo->cms[$modnumber]; if ($mod->is_visible_on_course_page()) { $data->cmlist[] = $mod->id; } } return $data; } }