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 * The modchooser renderable.
20 * @package core_course
21 * @copyright 2016 Frédéric Massart - FMCorz.net
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_course\output;
26 defined('MOODLE_INTERNAL') || die();
28 use core\output\chooser;
29 use core\output\chooser_section;
38 * The modchooser renderable class.
40 * @package core_course
41 * @copyright 2016 Frédéric Massart - FMCorz.net
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44 class modchooser extends chooser {
46 /** @var stdClass The course. */
52 * @param stdClass $course The course.
53 * @param stdClass[] $modules The modules.
55 public function __construct(stdClass $course, array $modules) {
56 $this->course = $course;
59 $context = context_course::instance($course->id);
62 $activities = array_filter($modules, function($mod) {
63 return ($mod->archetype !== MOD_ARCHETYPE_RESOURCE && $mod->archetype !== MOD_ARCHETYPE_SYSTEM);
65 if (count($activities)) {
66 $sections[] = new chooser_section('activities', new lang_string('activities'),
67 array_map(function($module) use ($context) {
68 return new modchooser_item($module, $context);
73 $resources = array_filter($modules, function($mod) {
74 return ($mod->archetype === MOD_ARCHETYPE_RESOURCE);
76 if (count($resources)) {
77 $sections[] = new chooser_section('resources', new lang_string('resources'),
78 array_map(function($module) use ($context) {
79 return new modchooser_item($module, $context);
84 $actionurl = new moodle_url('/course/jumpto.php');
85 $title = new lang_string('addresourceoractivity');
86 parent::__construct($actionurl, $title, $sections, 'jumplink');
88 $this->set_instructions(new lang_string('selectmoduletoviewhelp'));
89 $this->add_param('course', $course->id);
93 * Export for template.
95 * @param renderer_base The renderer.
98 public function export_for_template(renderer_base $output) {
99 $data = parent::export_for_template($output);
100 $data->courseid = $this->course->id;