. /** * Renderer for use with the course section and all the goodness that falls * within it. * * This renderer should contain methods useful to courses, and categories. * * @package moodlecore * @copyright 2010 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * The core course renderer * * Can be retrieved with the following: * $renderer = $PAGE->get_renderer('core','course'); */ class core_course_renderer extends plugin_renderer_base { const COURSECAT_SHOW_COURSES_NONE = 0; /* do not show courses at all */ const COURSECAT_SHOW_COURSES_COUNT = 5; /* do not show courses but show number of courses next to category name */ const COURSECAT_SHOW_COURSES_COLLAPSED = 10; const COURSECAT_SHOW_COURSES_AUTO = 15; /* will choose between collapsed and expanded automatically */ const COURSECAT_SHOW_COURSES_EXPANDED = 20; const COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT = 30; const COURSECAT_TYPE_CATEGORY = 0; const COURSECAT_TYPE_COURSE = 1; /** * A cache of strings * @var stdClass */ protected $strings; /** * Whether a category content is being initially rendered with children. This is mainly used by the * core_course_renderer::corsecat_tree() to render the appropriate action for the Expand/Collapse all link on * page load. * @var bool */ protected $categoryexpandedonload = false; /** * Override the constructor so that we can initialise the string cache * * @param moodle_page $page * @param string $target */ public function __construct(moodle_page $page, $target) { $this->strings = new stdClass; parent::__construct($page, $target); } /** * @deprecated since 3.2 */ protected function add_modchoosertoggle() { throw new coding_exception('core_course_renderer::add_modchoosertoggle() can not be used anymore.'); } /** * Renders course info box. * * @param stdClass $course * @return string */ public function course_info_box(stdClass $course) { $content = ''; $content .= $this->output->box_start('generalbox info'); $chelper = new coursecat_helper(); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); $content .= $this->coursecat_coursebox($chelper, $course); $content .= $this->output->box_end(); return $content; } /** * Renderers a structured array of courses and categories into a nice XHTML tree structure. * * @deprecated since 2.5 * * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 * * @param array $ignored argument ignored * @return string */ public final function course_category_tree(array $ignored) { debugging('Function core_course_renderer::course_category_tree() is deprecated, please use frontpage_combo_list()', DEBUG_DEVELOPER); return $this->frontpage_combo_list(); } /** * Renderers a category for use with course_category_tree * * @deprecated since 2.5 * * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 * * @param array $category * @param int $depth * @return string */ protected final function course_category_tree_category(stdClass $category, $depth=1) { debugging('Function core_course_renderer::course_category_tree_category() is deprecated', DEBUG_DEVELOPER); return ''; } /** * Render a modchooser. * * @param renderable $modchooser The chooser. * @return string */ public function render_modchooser(renderable $modchooser) { return $this->render_from_template('core_course/modchooser', $modchooser->export_for_template($this)); } /** * Build the HTML for the module chooser javascript popup * * @param array $modules A set of modules as returned form @see * get_module_metadata * @param object $course The course that will be displayed * @return string The composed HTML for the module */ public function course_modchooser($modules, $course) { debugging('course_modchooser() is deprecated. Please use course_activitychooser() instead.', DEBUG_DEVELOPER); return $this->course_activitychooser($course->id); } /** * Build the HTML for the module chooser javascript popup. * * @param int $courseid The course id to fetch modules for. * @return string */ public function course_activitychooser($courseid) { if (!$this->page->requires->should_create_one_time_item_now('core_course_modchooser')) { return ''; } // Build an object of config settings that we can then hook into in the Activity Chooser. $chooserconfig = (object) [ 'tabmode' => get_config('core', 'activitychoosertabmode'), ]; $this->page->requires->js_call_amd('core_course/activitychooser', 'init', [$courseid, $chooserconfig]); return ''; } /** * Build the HTML for a specified set of modules * * @param array $modules A set of modules as used by the * course_modchooser_module function * @return string The composed HTML for the module */ protected function course_modchooser_module_types($modules) { debugging('Method core_course_renderer::course_modchooser_module_types() is deprecated, ' . 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER); return ''; } /** * Return the HTML for the specified module adding any required classes * * @param object $module An object containing the title, and link. An * icon, and help text may optionally be specified. If the module * contains subtypes in the types option, then these will also be * displayed. * @param array $classes Additional classes to add to the encompassing * div element * @return string The composed HTML for the module */ protected function course_modchooser_module($module, $classes = array('option')) { debugging('Method core_course_renderer::course_modchooser_module() is deprecated, ' . 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER); return ''; } protected function course_modchooser_title($title, $identifier = null) { debugging('Method core_course_renderer::course_modchooser_title() is deprecated, ' . 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER); return ''; } /** * Renders HTML for displaying the sequence of course module editing buttons * * @see course_get_cm_edit_actions() * * @param action_link[] $actions Array of action_link objects * @param cm_info $mod The module we are displaying actions for. * @param array $displayoptions additional display options: * ownerselector => A JS/CSS selector that can be used to find an cm node. * If specified the owning node will be given the class 'action-menu-shown' when the action * menu is being displayed. * constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain * the action menu to when it is being displayed. * donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS. * @return string */ public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) { global $CFG; if (empty($actions)) { return ''; } if (isset($displayoptions['ownerselector'])) { $ownerselector = $displayoptions['ownerselector']; } else if ($mod) { $ownerselector = '#module-'.$mod->id; } else { debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER); $ownerselector = 'li.activity'; } if (isset($displayoptions['constraintselector'])) { $constraint = $displayoptions['constraintselector']; } else { $constraint = '.course-content'; } $menu = new action_menu(); $menu->set_owner_selector($ownerselector); $menu->set_constraint($constraint); $menu->set_alignment(action_menu::TR, action_menu::BR); $menu->set_menu_trigger(get_string('edit')); foreach ($actions as $action) { if ($action instanceof action_menu_link) { $action->add_class('cm-edit-action'); } $menu->add($action); } $menu->attributes['class'] .= ' section-cm-edit-actions commands'; // Prioritise the menu ahead of all other actions. $menu->prioritise = true; return $this->render($menu); } /** * Renders HTML for the menus to add activities and resources to the current course * * @param stdClass $course * @param int $section relative section number (field course_sections.section) * @param int $sectionreturn The section to link back to * @param array $displayoptions additional display options, for example blocks add * option 'inblock' => true, suggesting to display controls vertically * @return string */ function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) { global $CFG, $USER; // The returned control HTML can be one of the following: // - Only the non-ajax control (select menus of activities and resources) with a noscript fallback for non js clients. // - Only the ajax control (the link which when clicked produces the activity chooser modal). No noscript fallback. // - [Behat only]: The non-ajax control and optionally the ajax control (depending on site settings). If included, the link // takes priority and the non-ajax control is wrapped in a