. /** * The modchooser renderable. * * @package core_course * @copyright 2016 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_course\output; defined('MOODLE_INTERNAL') || die(); use core\output\chooser; use core\output\chooser_section; use context_course; use lang_string; use moodle_url; use pix_icon; use renderer_base; use stdClass; /** * The modchooser renderable class. * * @package core_course * @copyright 2016 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class modchooser extends chooser { /** @var stdClass The course. */ public $course; /** * Constructor. * * @param stdClass $course The course. * @param stdClass[] $modules The modules. */ public function __construct(stdClass $course, array $modules) { $this->course = $course; $sections = []; $context = context_course::instance($course->id); // Activities. $activities = array_filter($modules, function($mod) { return ($mod->archetype !== MOD_ARCHETYPE_RESOURCE && $mod->archetype !== MOD_ARCHETYPE_SYSTEM); }); if (count($activities)) { $sections[] = new chooser_section('activities', new lang_string('activities'), array_map(function($module) use ($context) { return new modchooser_item($module, $context); }, $activities) ); } $resources = array_filter($modules, function($mod) { return ($mod->archetype === MOD_ARCHETYPE_RESOURCE); }); if (count($resources)) { $sections[] = new chooser_section('resources', new lang_string('resources'), array_map(function($module) use ($context) { return new modchooser_item($module, $context); }, $resources) ); } $actionurl = new moodle_url('/course/jumpto.php'); $title = new lang_string('addresourceoractivity'); parent::__construct($actionurl, $title, $sections, 'jumplink'); $this->set_instructions(new lang_string('selectmoduletoviewhelp')); $this->add_param('course', $course->id); } /** * Export for template. * * @param renderer_base The renderer. * @return stdClass */ public function export_for_template(renderer_base $output) { $data = parent::export_for_template($output); $data->courseid = $this->course->id; return $data; } }