MDL-73233 navigation: Breadcrumbs removed from user preferences
[moodle.git] / course / renderer.php
blob9fac8ebf42d5b8ec8856bdcd82544f2c52deabe1
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Renderer for use with the course section and all the goodness that falls
20 * within it.
22 * This renderer should contain methods useful to courses, and categories.
24 * @package moodlecore
25 * @copyright 2010 Sam Hemelryk
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 /**
30 * The core course renderer
32 * Can be retrieved with the following:
33 * $renderer = $PAGE->get_renderer('core','course');
35 class core_course_renderer extends plugin_renderer_base {
36 const COURSECAT_SHOW_COURSES_NONE = 0; /* do not show courses at all */
37 const COURSECAT_SHOW_COURSES_COUNT = 5; /* do not show courses but show number of courses next to category name */
38 const COURSECAT_SHOW_COURSES_COLLAPSED = 10;
39 const COURSECAT_SHOW_COURSES_AUTO = 15; /* will choose between collapsed and expanded automatically */
40 const COURSECAT_SHOW_COURSES_EXPANDED = 20;
41 const COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT = 30;
43 const COURSECAT_TYPE_CATEGORY = 0;
44 const COURSECAT_TYPE_COURSE = 1;
46 /**
47 * A cache of strings
48 * @var stdClass
50 protected $strings;
52 /**
53 * Whether a category content is being initially rendered with children. This is mainly used by the
54 * core_course_renderer::corsecat_tree() to render the appropriate action for the Expand/Collapse all link on
55 * page load.
56 * @var bool
58 protected $categoryexpandedonload = false;
60 /**
61 * Override the constructor so that we can initialise the string cache
63 * @param moodle_page $page
64 * @param string $target
66 public function __construct(moodle_page $page, $target) {
67 $this->strings = new stdClass;
68 $courseid = $page->course->id;
69 parent::__construct($page, $target);
72 /**
73 * @deprecated since 3.2
75 protected function add_modchoosertoggle() {
76 throw new coding_exception('core_course_renderer::add_modchoosertoggle() can not be used anymore.');
79 /**
80 * Renders course info box.
82 * @param stdClass $course
83 * @return string
85 public function course_info_box(stdClass $course) {
86 $content = '';
87 $content .= $this->output->box_start('generalbox info');
88 $chelper = new coursecat_helper();
89 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
90 $content .= $this->coursecat_coursebox($chelper, $course);
91 $content .= $this->output->box_end();
92 return $content;
95 /**
96 * Renderers a structured array of courses and categories into a nice XHTML tree structure.
98 * @deprecated since 2.5
100 * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
102 * @param array $ignored argument ignored
103 * @return string
105 public final function course_category_tree(array $ignored) {
106 debugging('Function core_course_renderer::course_category_tree() is deprecated, please use frontpage_combo_list()', DEBUG_DEVELOPER);
107 return $this->frontpage_combo_list();
111 * Renderers a category for use with course_category_tree
113 * @deprecated since 2.5
115 * Please see http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
117 * @param array $category
118 * @param int $depth
119 * @return string
121 protected final function course_category_tree_category(stdClass $category, $depth=1) {
122 debugging('Function core_course_renderer::course_category_tree_category() is deprecated', DEBUG_DEVELOPER);
123 return '';
127 * Render a modchooser.
129 * @param renderable $modchooser The chooser.
130 * @return string
132 public function render_modchooser(renderable $modchooser) {
133 return $this->render_from_template('core_course/modchooser', $modchooser->export_for_template($this));
137 * Build the HTML for the module chooser javascript popup
139 * @param array $modules A set of modules as returned form @see
140 * get_module_metadata
141 * @param object $course The course that will be displayed
142 * @return string The composed HTML for the module
144 public function course_modchooser($modules, $course) {
145 debugging('course_modchooser() is deprecated. Please use course_activitychooser() instead.', DEBUG_DEVELOPER);
147 return $this->course_activitychooser($course->id);
151 * Build the HTML for the module chooser javascript popup.
153 * @param int $courseid The course id to fetch modules for.
154 * @return string
156 public function course_activitychooser($courseid) {
158 if (!$this->page->requires->should_create_one_time_item_now('core_course_modchooser')) {
159 return '';
162 // Build an object of config settings that we can then hook into in the Activity Chooser.
163 $chooserconfig = (object) [
164 'tabmode' => get_config('core', 'activitychoosertabmode'),
166 $this->page->requires->js_call_amd('core_course/activitychooser', 'init', [$courseid, $chooserconfig]);
168 return '';
172 * Build the HTML for a specified set of modules
174 * @param array $modules A set of modules as used by the
175 * course_modchooser_module function
176 * @return string The composed HTML for the module
178 protected function course_modchooser_module_types($modules) {
179 debugging('Method core_course_renderer::course_modchooser_module_types() is deprecated, ' .
180 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER);
181 return '';
185 * Return the HTML for the specified module adding any required classes
187 * @param object $module An object containing the title, and link. An
188 * icon, and help text may optionally be specified. If the module
189 * contains subtypes in the types option, then these will also be
190 * displayed.
191 * @param array $classes Additional classes to add to the encompassing
192 * div element
193 * @return string The composed HTML for the module
195 protected function course_modchooser_module($module, $classes = array('option')) {
196 debugging('Method core_course_renderer::course_modchooser_module() is deprecated, ' .
197 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER);
198 return '';
201 protected function course_modchooser_title($title, $identifier = null) {
202 debugging('Method core_course_renderer::course_modchooser_title() is deprecated, ' .
203 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER);
204 return '';
208 * Renders HTML for displaying the sequence of course module editing buttons
210 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
212 * @see course_get_cm_edit_actions()
214 * @param action_link[] $actions Array of action_link objects
215 * @param cm_info $mod The module we are displaying actions for.
216 * @param array $displayoptions additional display options:
217 * ownerselector => A JS/CSS selector that can be used to find an cm node.
218 * If specified the owning node will be given the class 'action-menu-shown' when the action
219 * menu is being displayed.
220 * constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain
221 * the action menu to when it is being displayed.
222 * donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS.
223 * @return string
225 public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) {
226 global $CFG;
228 debugging(
229 'course_section_cm_edit_actions is deprecated. Use core_courseformat\\output\\local\\content\\cm\\controlmenu instead.',
230 DEBUG_DEVELOPER
233 if (empty($actions)) {
234 return '';
237 if (isset($displayoptions['ownerselector'])) {
238 $ownerselector = $displayoptions['ownerselector'];
239 } else if ($mod) {
240 $ownerselector = '#module-'.$mod->id;
241 } else {
242 debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER);
243 $ownerselector = 'li.activity';
246 if (isset($displayoptions['constraintselector'])) {
247 $constraint = $displayoptions['constraintselector'];
248 } else {
249 $constraint = '.course-content';
252 $menu = new action_menu();
253 $menu->set_owner_selector($ownerselector);
254 $menu->set_constraint($constraint);
255 $menu->set_menu_trigger(get_string('edit'));
257 foreach ($actions as $action) {
258 if ($action instanceof action_menu_link) {
259 $action->add_class('cm-edit-action');
261 $menu->add($action);
263 $menu->attributes['class'] .= ' section-cm-edit-actions commands';
265 // Prioritise the menu ahead of all other actions.
266 $menu->prioritise = true;
268 return $this->render($menu);
272 * Renders HTML for the menus to add activities and resources to the current course
274 * Renders the ajax control (the link which when clicked produces the activity chooser modal). No noscript fallback.
276 * @param stdClass $course
277 * @param int $section relative section number (field course_sections.section)
278 * @param int $sectionreturn The section to link back to
279 * @param array $displayoptions additional display options, for example blocks add
280 * option 'inblock' => true, suggesting to display controls vertically
281 * @return string
283 function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) {
284 // Check to see if user can add menus.
285 if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
286 || !$this->page->user_is_editing()) {
287 return '';
290 $data = [
291 'sectionid' => $section,
292 'sectionreturn' => $sectionreturn
294 $ajaxcontrol = $this->render_from_template('course/activitychooserbutton', $data);
296 // Load the JS for the modal.
297 $this->course_activitychooser($course->id);
299 return $ajaxcontrol;
303 * Render the deprecated nonajax activity chooser.
305 * @deprecated since Moodle 3.11
307 * @todo MDL-71331 deprecate this function
308 * @param stdClass $course the course object
309 * @param int $section relative section number (field course_sections.section)
310 * @param int $sectionreturn The section to link back to
311 * @param array $displayoptions additional display options, for example blocks add
312 * option 'inblock' => true, suggesting to display controls vertically
313 * @return string
315 private function course_section_add_cm_control_nonajax($course, $section, $sectionreturn = null,
316 $displayoptions = array()): string {
317 global $USER;
319 $vertical = !empty($displayoptions['inblock']);
321 // Check to see if user can add menus.
322 if (
323 !has_capability('moodle/course:manageactivities', context_course::instance($course->id))
324 || !$this->page->user_is_editing()
326 return '';
329 debugging('non-js dropdowns are deprecated.', DEBUG_DEVELOPER);
330 // Retrieve all modules with associated metadata.
331 $contentitemservice = \core_course\local\factory\content_item_service_factory::get_content_item_service();
332 $urlparams = ['section' => $section];
333 if (!is_null($sectionreturn)) {
334 $urlparams['sr'] = $sectionreturn;
336 $modules = $contentitemservice->get_content_items_for_user_in_course($USER, $course, $urlparams);
338 // Return if there are no content items to add.
339 if (empty($modules)) {
340 return '';
343 // We'll sort resources and activities into two lists.
344 $activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array());
346 foreach ($modules as $module) {
347 $activityclass = MOD_CLASS_ACTIVITY;
348 if ($module->archetype == MOD_ARCHETYPE_RESOURCE) {
349 $activityclass = MOD_CLASS_RESOURCE;
350 } else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
351 // System modules cannot be added by user, do not add to dropdown.
352 continue;
354 $link = $module->link;
355 $activities[$activityclass][$link] = $module->title;
358 $straddactivity = get_string('addactivity');
359 $straddresource = get_string('addresource');
360 $sectionname = get_section_name($course, $section);
361 $strresourcelabel = get_string('addresourcetosection', null, $sectionname);
362 $stractivitylabel = get_string('addactivitytosection', null, $sectionname);
364 $nonajaxcontrol = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-'
365 . $section));
367 if (!$vertical) {
368 $nonajaxcontrol .= html_writer::start_tag('div', array('class' => 'horizontal'));
371 if (!empty($activities[MOD_CLASS_RESOURCE])) {
372 $select = new url_select($activities[MOD_CLASS_RESOURCE], '', array('' => $straddresource), "ressection$section");
373 $select->set_help_icon('resources');
374 $select->set_label($strresourcelabel, array('class' => 'accesshide'));
375 $nonajaxcontrol .= $this->output->render($select);
378 if (!empty($activities[MOD_CLASS_ACTIVITY])) {
379 $select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array('' => $straddactivity), "section$section");
380 $select->set_help_icon('activities');
381 $select->set_label($stractivitylabel, array('class' => 'accesshide'));
382 $nonajaxcontrol .= $this->output->render($select);
385 if (!$vertical) {
386 $nonajaxcontrol .= html_writer::end_tag('div');
389 $nonajaxcontrol .= html_writer::end_tag('div');
391 return $nonajaxcontrol;
395 * Renders html to display a course search form
397 * @param string $value default value to populate the search field
398 * @return string
400 public function course_search_form($value = '') {
402 $data = [
403 'action' => \core_search\manager::get_course_search_url(),
404 'btnclass' => 'btn-primary',
405 'inputname' => 'q',
406 'searchstring' => get_string('searchcourses'),
407 'hiddenfields' => (object) ['name' => 'areaids', 'value' => 'core_course-course'],
408 'query' => $value
410 return $this->render_from_template('core/search_input', $data);
414 * Renders html for completion box on course page
416 * If completion is disabled, returns empty string
417 * If completion is automatic, returns an icon of the current completion state
418 * If completion is manual, returns a form (with an icon inside) that allows user to
419 * toggle completion
421 * @deprecated since Moodle 3.11
422 * @todo MDL-71183 Final deprecation in Moodle 4.3.
423 * @see \core_renderer::activity_information
425 * @param stdClass $course course object
426 * @param completion_info $completioninfo completion info for the course, it is recommended
427 * to fetch once for all modules in course/section for performance
428 * @param cm_info $mod module to show completion for
429 * @param array $displayoptions display options, not used in core
430 * @return string
432 public function course_section_cm_completion($course, &$completioninfo, cm_info $mod, $displayoptions = array()) {
433 global $CFG, $DB, $USER;
435 debugging(__FUNCTION__ . ' is deprecated and is being replaced by the activity_information output component.',
436 DEBUG_DEVELOPER);
438 $output = '';
440 $istrackeduser = $completioninfo->is_tracked_user($USER->id);
441 $isediting = $this->page->user_is_editing();
443 if (!empty($displayoptions['hidecompletion']) || !isloggedin() || isguestuser() || !$mod->uservisible) {
444 return $output;
446 if ($completioninfo === null) {
447 $completioninfo = new completion_info($course);
449 $completion = $completioninfo->is_enabled($mod);
451 if ($completion == COMPLETION_TRACKING_NONE) {
452 if ($isediting) {
453 $output .= html_writer::span('&nbsp;', 'filler');
455 return $output;
458 $completionicon = '';
460 if ($isediting || !$istrackeduser) {
461 switch ($completion) {
462 case COMPLETION_TRACKING_MANUAL :
463 $completionicon = 'manual-enabled'; break;
464 case COMPLETION_TRACKING_AUTOMATIC :
465 $completionicon = 'auto-enabled'; break;
467 } else {
468 $completiondata = $completioninfo->get_data($mod, true);
469 if ($completion == COMPLETION_TRACKING_MANUAL) {
470 switch($completiondata->completionstate) {
471 case COMPLETION_INCOMPLETE:
472 $completionicon = 'manual-n' . ($completiondata->overrideby ? '-override' : '');
473 break;
474 case COMPLETION_COMPLETE:
475 $completionicon = 'manual-y' . ($completiondata->overrideby ? '-override' : '');
476 break;
478 } else { // Automatic
479 switch($completiondata->completionstate) {
480 case COMPLETION_INCOMPLETE:
481 $completionicon = 'auto-n' . ($completiondata->overrideby ? '-override' : '');
482 break;
483 case COMPLETION_COMPLETE:
484 $completionicon = 'auto-y' . ($completiondata->overrideby ? '-override' : '');
485 break;
486 case COMPLETION_COMPLETE_PASS:
487 $completionicon = 'auto-pass'; break;
488 case COMPLETION_COMPLETE_FAIL:
489 $completionicon = 'auto-fail'; break;
493 if ($completionicon) {
494 $formattedname = html_entity_decode($mod->get_formatted_name(), ENT_QUOTES, 'UTF-8');
495 if (!$isediting && $istrackeduser && $completiondata->overrideby) {
496 $args = new stdClass();
497 $args->modname = $formattedname;
498 $overridebyuser = \core_user::get_user($completiondata->overrideby, '*', MUST_EXIST);
499 $args->overrideuser = fullname($overridebyuser);
500 $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $args);
501 } else {
502 $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
505 if ($isediting || !$istrackeduser || !has_capability('moodle/course:togglecompletion', $mod->context)) {
506 // When editing, the icon is just an image.
507 $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
508 array('title' => $imgalt, 'class' => 'iconsmall'));
509 $output .= html_writer::tag('span', $this->output->render($completionpixicon),
510 array('class' => 'autocompletion'));
511 } else if ($completion == COMPLETION_TRACKING_MANUAL) {
512 $newstate =
513 $completiondata->completionstate == COMPLETION_COMPLETE
514 ? COMPLETION_INCOMPLETE
515 : COMPLETION_COMPLETE;
516 // In manual mode the icon is a toggle form...
518 // If this completion state is used by the
519 // conditional activities system, we need to turn
520 // off the JS.
521 $extraclass = '';
522 if (!empty($CFG->enableavailability) &&
523 core_availability\info::completion_value_used($course, $mod->id)) {
524 $extraclass = ' preventjs';
526 $output .= html_writer::start_tag('form', array('method' => 'post',
527 'action' => new moodle_url('/course/togglecompletion.php'),
528 'class' => 'togglecompletion'. $extraclass));
529 $output .= html_writer::start_tag('div');
530 $output .= html_writer::empty_tag('input', array(
531 'type' => 'hidden', 'name' => 'id', 'value' => $mod->id));
532 $output .= html_writer::empty_tag('input', array(
533 'type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
534 $output .= html_writer::empty_tag('input', array(
535 'type' => 'hidden', 'name' => 'modulename', 'value' => $formattedname));
536 $output .= html_writer::empty_tag('input', array(
537 'type' => 'hidden', 'name' => 'completionstate', 'value' => $newstate));
538 $output .= html_writer::tag('button',
539 $this->output->pix_icon('i/completion-' . $completionicon, $imgalt),
540 array('class' => 'btn btn-link', 'aria-live' => 'assertive'));
541 $output .= html_writer::end_tag('div');
542 $output .= html_writer::end_tag('form');
543 } else {
544 // In auto mode, the icon is just an image.
545 $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
546 array('title' => $imgalt));
547 $output .= html_writer::tag('span', $this->output->render($completionpixicon),
548 array('class' => 'autocompletion'));
551 return $output;
555 * Checks if course module has any conditions that may make it unavailable for
556 * all or some of the students
558 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
560 * @param cm_info $mod
561 * @return bool
563 public function is_cm_conditionally_hidden(cm_info $mod) {
564 global $CFG;
566 debugging(
567 'is_cm_conditionally_hidden is deprecated. Use \core_availability\info_module::is_available_for_all instead',
568 DEBUG_DEVELOPER
571 $conditionalhidden = false;
572 if (!empty($CFG->enableavailability)) {
573 $info = new \core_availability\info_module($mod);
574 $conditionalhidden = !$info->is_available_for_all();
576 return $conditionalhidden;
580 * Renders html to display a name with the link to the course module on a course page
582 * If module is unavailable for user but still needs to be displayed
583 * in the list, just the name is returned without a link
585 * Note, that for course modules that never have separate pages (i.e. labels)
586 * this function return an empty string
588 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
590 * @param cm_info $mod
591 * @param array $displayoptions
592 * @return string
594 public function course_section_cm_name(cm_info $mod, $displayoptions = array()) {
595 debugging(
596 'course_section_cm_name is deprecated. Use core_courseformat\\output\\local\\content\\cm\\cmname class instead.',
597 DEBUG_DEVELOPER
600 if (!$mod->is_visible_on_course_page() || !$mod->url) {
601 // Nothing to be displayed to the user.
602 return '';
605 list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod);
606 $groupinglabel = $mod->get_grouping_label($textclasses);
608 // Render element that allows to edit activity name inline.
609 $format = course_get_format($mod->course);
610 $cmnameclass = $format->get_output_classname('content\\cm\\cmname');
611 // Mod inplace name editable.
612 $cmname = new $cmnameclass(
613 $format,
614 $mod->get_section_info(),
615 $mod,
616 $this->page->user_is_editing(),
617 $displayoptions
620 $data = $cmname->export_for_template($this->output);
622 return $this->output->render_from_template('core/inplace_editable', $data) .
623 $groupinglabel;
627 * Returns the CSS classes for the activity name/content
629 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
631 * For items which are hidden, unavailable or stealth but should be displayed
632 * to current user ($mod->is_visible_on_course_page()), we show those as dimmed.
633 * Students will also see as dimmed activities names that are not yet available
634 * but should still be displayed (without link) with availability info.
636 * @param cm_info $mod
637 * @return array array of two elements ($linkclasses, $textclasses)
639 protected function course_section_cm_classes(cm_info $mod) {
641 debugging(
642 'course_section_cm_classes is deprecated. Now it is part of core_courseformat\\output\\local\\content\\cm ',
643 DEBUG_DEVELOPER
646 $format = course_get_format($mod->course);
648 $cmclass = $format->get_output_classname('content\\cm');
649 $cmoutput = new $cmclass(
650 $format,
651 $mod->get_section_info(),
652 $mod,
654 return [
655 $cmoutput->get_link_classes(),
656 $cmoutput->get_text_classes(),
661 * Renders html to display a name with the link to the course module on a course page
663 * If module is unavailable for user but still needs to be displayed
664 * in the list, just the name is returned without a link
666 * Note, that for course modules that never have separate pages (i.e. labels)
667 * this function return an empty string
669 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
671 * @param cm_info $mod
672 * @param array $displayoptions
673 * @return string
675 public function course_section_cm_name_title(cm_info $mod, $displayoptions = array()) {
677 debugging(
678 'course_section_cm_name_title is deprecated. Use core_courseformat\\output\\local\\cm\\title class instead.',
679 DEBUG_DEVELOPER
682 $output = '';
683 $url = $mod->url;
684 if (!$mod->is_visible_on_course_page() || !$url) {
685 // Nothing to be displayed to the user.
686 return $output;
689 //Accessibility: for files get description via icon, this is very ugly hack!
690 $instancename = $mod->get_formatted_name();
691 $altname = $mod->modfullname;
692 // Avoid unnecessary duplication: if e.g. a forum name already
693 // includes the word forum (or Forum, etc) then it is unhelpful
694 // to include that in the accessible description that is added.
695 if (false !== strpos(core_text::strtolower($instancename),
696 core_text::strtolower($altname))) {
697 $altname = '';
699 // File type after name, for alphabetic lists (screen reader).
700 if ($altname) {
701 $altname = get_accesshide(' '.$altname);
704 list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod);
706 // Get on-click attribute value if specified and decode the onclick - it
707 // has already been encoded for display (puke).
708 $onclick = htmlspecialchars_decode($mod->onclick, ENT_QUOTES);
710 // Display link itself.
711 $instancename = html_writer::tag('span', $instancename . $altname, ['class' => 'instancename ml-1']);
713 $imageicon = html_writer::empty_tag('img', ['src' => $mod->get_icon_url(),
714 'class' => 'activityicon', 'alt' => '', 'role' => 'presentation', 'aria-hidden' => 'true']);
715 $imageicon = html_writer::tag('span', $imageicon, ['class' => 'activityiconcontainer courseicon']);
716 $activitylink = $imageicon . $instancename;
718 if ($mod->uservisible) {
719 $output .= html_writer::link($url, $activitylink, array('class' => 'aalink' . $linkclasses, 'onclick' => $onclick));
720 } else {
721 // We may be displaying this just in order to show information
722 // about visibility, without the actual link ($mod->is_visible_on_course_page()).
723 $output .= html_writer::tag('div', $activitylink, array('class' => $textclasses));
725 return $output;
729 * Renders html to display the module content on the course page (i.e. text of the labels)
731 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
733 * @param cm_info $mod
734 * @param array $displayoptions
735 * @return string
737 public function course_section_cm_text(cm_info $mod, $displayoptions = array()) {
739 debugging(
740 'course_section_cm_text is deprecated. Now it is part of core_courseformat\\output\\local\\content\\cm ',
741 DEBUG_DEVELOPER
744 $output = '';
745 if (!$mod->is_visible_on_course_page()) {
746 // nothing to be displayed to the user
747 return $output;
749 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
750 list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod);
751 if ($mod->url && $mod->uservisible) {
752 if ($content) {
753 // If specified, display extra content after link.
754 $output = html_writer::tag('div', $content, array('class' =>
755 trim('contentafterlink ' . $textclasses)));
757 } else {
758 $groupinglabel = $mod->get_grouping_label($textclasses);
760 // No link, so display only content.
761 $output = html_writer::tag('div', $content . $groupinglabel,
762 array('class' => 'contentwithoutlink ' . $textclasses));
764 return $output;
768 * Displays availability info for a course section or course module
770 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
771 * @param string $text
772 * @param string $additionalclasses
773 * @return string
775 public function availability_info($text, $additionalclasses = '') {
777 debugging(
778 'availability_info is deprecated. Use core_courseformat\\output\\local\\content\\section\\availability instead',
779 DEBUG_DEVELOPER
782 $data = ['text' => $text, 'classes' => $additionalclasses];
783 $additionalclasses = array_filter(explode(' ', $additionalclasses));
785 if (in_array('ishidden', $additionalclasses)) {
786 $data['ishidden'] = 1;
788 } else if (in_array('isstealth', $additionalclasses)) {
789 $data['isstealth'] = 1;
791 } else if (in_array('isrestricted', $additionalclasses)) {
792 $data['isrestricted'] = 1;
794 if (in_array('isfullinfo', $additionalclasses)) {
795 $data['isfullinfo'] = 1;
799 return $this->render_from_template('core/availability_info', $data);
803 * Renders HTML to show course module availability information (for someone who isn't allowed
804 * to see the activity itself, or for staff)
806 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
807 * @param cm_info $mod
808 * @param array $displayoptions
809 * @return string
811 public function course_section_cm_availability(cm_info $mod, $displayoptions = array()) {
813 debugging(
814 'course_section_cm_availability is deprecated. Use core_courseformat\\output\\local\\content\\cm\\availability instead',
815 DEBUG_DEVELOPER
818 $format = course_get_format($mod->course);
820 $availabilityclass = $format->get_output_classname('content\\cm\\availability');
821 $availability = new $availabilityclass(
822 $format,
823 $mod->get_section_info(),
824 $mod,
827 $renderer = $format->get_renderer($this->page);
828 $data = $availability->export_for_template($renderer);
829 return $data->info ?? '';
833 * Renders HTML to display one course module for display within a section.
835 * @deprecated since 4.0 - use core_course output components or course_format::course_section_updated_cm_item instead.
837 * This function calls:
838 * {@link core_course_renderer::course_section_cm()}
840 * @param stdClass $course
841 * @param completion_info $completioninfo
842 * @param cm_info $mod
843 * @param int|null $sectionreturn
844 * @param array $displayoptions
845 * @return String
847 public function course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = []) {
849 debugging(
850 'course_section_cm_list_item is deprecated. Use renderer course_section_updated_cm_item instead',
851 DEBUG_DEVELOPER
854 $output = '';
855 if ($modulehtml = $this->course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) {
856 $modclasses = 'activity ' . $mod->modname . ' modtype_' . $mod->modname . ' ' . $mod->extraclasses;
857 $output .= html_writer::tag('li', $modulehtml, array('class' => $modclasses, 'id' => 'module-' . $mod->id));
859 return $output;
863 * Renders HTML to display one course module in a course section
865 * This includes link, content, availability, completion info and additional information
866 * that module type wants to display (i.e. number of unread forum posts)
868 * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
870 * @param stdClass $course
871 * @param completion_info $completioninfo
872 * @param cm_info $mod
873 * @param int|null $sectionreturn
874 * @param array $displayoptions
875 * @return string
877 public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = []) {
879 debugging(
880 'course_section_cm is deprecated. Use core_courseformat\\output\\content\\cm output class instead.',
881 DEBUG_DEVELOPER
884 if (!$mod->is_visible_on_course_page()) {
885 return '';
888 $format = course_get_format($course);
889 $modinfo = $format->get_modinfo();
890 // Output renderers works only with real section_info objects.
891 if ($sectionreturn) {
892 $format->set_section_number($sectionreturn);
894 $section = $modinfo->get_section_info($format->get_section_number());
896 $cmclass = $format->get_output_classname('content\\cm');
897 $cm = new $cmclass($format, $section, $mod, $displayoptions);
898 // The course outputs works with format renderers, not with course renderers.
899 $renderer = $format->get_renderer($this->page);
900 $data = $cm->export_for_template($renderer);
901 return $this->output->render_from_template('core_courseformat/local/content/cm', $data);
905 * Message displayed to the user when they try to access unavailable activity following URL
907 * This method is a very simplified version of {@link course_section_cm()} to be part of the error
908 * notification only. It also does not check if module is visible on course page or not.
910 * The message will be displayed inside notification!
912 * @param cm_info $cm
913 * @return string
915 public function course_section_cm_unavailable_error_message(cm_info $cm) {
916 if ($cm->uservisible) {
917 return null;
919 if (!$cm->availableinfo) {
920 return get_string('activityiscurrentlyhidden');
923 $altname = get_accesshide(' ' . $cm->modfullname);
924 $name = html_writer::empty_tag('img', array('src' => $cm->get_icon_url(),
925 'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) .
926 html_writer::tag('span', ' '.$cm->get_formatted_name() . $altname, array('class' => 'instancename'));
927 $formattedinfo = \core_availability\info::format_info($cm->availableinfo, $cm->get_course());
928 return html_writer::div($name, 'activityinstance-error') .
929 html_writer::div($formattedinfo, 'availabilityinfo-error');
933 * Renders HTML to display a list of course modules in a course section
934 * Also displays "move here" controls in Javascript-disabled mode.
936 * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
938 * This function calls {@link core_course_renderer::course_section_cm()}
940 * @param stdClass $course course object
941 * @param int|stdClass|section_info $section relative section number or section object
942 * @param int $sectionreturn section number to return to
943 * @param int $displayoptions
944 * @return void
946 public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = []) {
947 global $USER;
949 debugging('course_section_cm_list is deprecated. Use core_courseformat\\output\\local\\content\\section\\cmlist '.
950 'classes instead.', DEBUG_DEVELOPER);
952 $output = '';
954 $format = course_get_format($course);
955 $modinfo = $format->get_modinfo();
957 if (is_object($section)) {
958 $section = $modinfo->get_section_info($section->section);
959 } else {
960 $section = $modinfo->get_section_info($section);
962 $completioninfo = new completion_info($course);
964 // check if we are currently in the process of moving a module with JavaScript disabled
965 $ismoving = $format->show_editor() && ismoving($course->id);
967 if ($ismoving) {
968 $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
971 // Get the list of modules visible to user (excluding the module being moved if there is one)
972 $moduleshtml = [];
973 if (!empty($modinfo->sections[$section->section])) {
974 foreach ($modinfo->sections[$section->section] as $modnumber) {
975 $mod = $modinfo->cms[$modnumber];
977 if ($ismoving and $mod->id == $USER->activitycopy) {
978 // do not display moving mod
979 continue;
982 if ($modulehtml = $this->course_section_cm_list_item($course,
983 $completioninfo, $mod, $sectionreturn, $displayoptions)) {
984 $moduleshtml[$modnumber] = $modulehtml;
989 $sectionoutput = '';
990 if (!empty($moduleshtml) || $ismoving) {
991 foreach ($moduleshtml as $modnumber => $modulehtml) {
992 if ($ismoving) {
993 $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey()));
994 $sectionoutput .= html_writer::tag('li',
995 html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere')),
996 array('class' => 'movehere'));
999 $sectionoutput .= $modulehtml;
1002 if ($ismoving) {
1003 $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
1004 $sectionoutput .= html_writer::tag('li',
1005 html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere')),
1006 array('class' => 'movehere'));
1010 // Always output the section module list.
1011 $output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text'));
1013 return $output;
1017 * Displays a custom list of courses with paging bar if necessary
1019 * If $paginationurl is specified but $totalcount is not, the link 'View more'
1020 * appears under the list.
1022 * If both $paginationurl and $totalcount are specified, and $totalcount is
1023 * bigger than count($courses), a paging bar is displayed above and under the
1024 * courses list.
1026 * @param array $courses array of course records (or instances of core_course_list_element) to show on this page
1027 * @param bool $showcategoryname whether to add category name to the course description
1028 * @param string $additionalclasses additional CSS classes to add to the div.courses
1029 * @param moodle_url $paginationurl url to view more or url to form links to the other pages in paging bar
1030 * @param int $totalcount total number of courses on all pages, if omitted $paginationurl will be displayed as 'View more' link
1031 * @param int $page current page number (defaults to 0 referring to the first page)
1032 * @param int $perpage number of records per page (defaults to $CFG->coursesperpage)
1033 * @return string
1035 public function courses_list($courses, $showcategoryname = false, $additionalclasses = null, $paginationurl = null, $totalcount = null, $page = 0, $perpage = null) {
1036 global $CFG;
1037 // create instance of coursecat_helper to pass display options to function rendering courses list
1038 $chelper = new coursecat_helper();
1039 if ($showcategoryname) {
1040 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT);
1041 } else {
1042 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
1044 if ($totalcount !== null && $paginationurl !== null) {
1045 // add options to display pagination
1046 if ($perpage === null) {
1047 $perpage = $CFG->coursesperpage;
1049 $chelper->set_courses_display_options(array(
1050 'limit' => $perpage,
1051 'offset' => ((int)$page) * $perpage,
1052 'paginationurl' => $paginationurl,
1054 } else if ($paginationurl !== null) {
1055 // add options to display 'View more' link
1056 $chelper->set_courses_display_options(array('viewmoreurl' => $paginationurl));
1057 $totalcount = count($courses) + 1; // has to be bigger than count($courses) otherwise link will not be displayed
1059 $chelper->set_attributes(array('class' => $additionalclasses));
1060 $content = $this->coursecat_courses($chelper, $courses, $totalcount);
1061 return $content;
1065 * Returns HTML to display course name.
1067 * @param coursecat_helper $chelper
1068 * @param core_course_list_element $course
1069 * @return string
1071 protected function course_name(coursecat_helper $chelper, core_course_list_element $course): string {
1072 $content = '';
1073 if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) {
1074 $nametag = 'h3';
1075 } else {
1076 $nametag = 'div';
1078 $coursename = $chelper->get_course_formatted_name($course);
1079 $coursenamelink = html_writer::link(new moodle_url('/course/view.php', ['id' => $course->id]),
1080 $coursename, ['class' => $course->visible ? 'aalink' : 'aalink dimmed']);
1081 $content .= html_writer::tag($nametag, $coursenamelink, ['class' => 'coursename']);
1082 // If we display course in collapsed form but the course has summary or course contacts, display the link to the info page.
1083 $content .= html_writer::start_tag('div', ['class' => 'moreinfo']);
1084 if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
1085 if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles()
1086 || $course->has_custom_fields()) {
1087 $url = new moodle_url('/course/info.php', ['id' => $course->id]);
1088 $image = $this->output->pix_icon('i/info', $this->strings->summary);
1089 $content .= html_writer::link($url, $image, ['title' => $this->strings->summary]);
1090 // Make sure JS file to expand course content is included.
1091 $this->coursecat_include_js();
1094 $content .= html_writer::end_tag('div');
1095 return $content;
1099 * Returns HTML to display course enrolment icons.
1101 * @param core_course_list_element $course
1102 * @return string
1104 protected function course_enrolment_icons(core_course_list_element $course): string {
1105 $content = '';
1106 if ($icons = enrol_get_course_info_icons($course)) {
1107 $content .= html_writer::start_tag('div', ['class' => 'enrolmenticons']);
1108 foreach ($icons as $icon) {
1109 $content .= $this->render($icon);
1111 $content .= html_writer::end_tag('div');
1113 return $content;
1117 * Displays one course in the list of courses.
1119 * This is an internal function, to display an information about just one course
1120 * please use {@link core_course_renderer::course_info_box()}
1122 * @param coursecat_helper $chelper various display options
1123 * @param core_course_list_element|stdClass $course
1124 * @param string $additionalclasses additional classes to add to the main <div> tag (usually
1125 * depend on the course position in list - first/last/even/odd)
1126 * @return string
1128 protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
1129 if (!isset($this->strings->summary)) {
1130 $this->strings->summary = get_string('summary');
1132 if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) {
1133 return '';
1135 if ($course instanceof stdClass) {
1136 $course = new core_course_list_element($course);
1138 $content = '';
1139 $classes = trim('coursebox clearfix '. $additionalclasses);
1140 if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
1141 $classes .= ' collapsed';
1144 // .coursebox
1145 $content .= html_writer::start_tag('div', array(
1146 'class' => $classes,
1147 'data-courseid' => $course->id,
1148 'data-type' => self::COURSECAT_TYPE_COURSE,
1151 $content .= html_writer::start_tag('div', array('class' => 'info'));
1152 $content .= $this->course_name($chelper, $course);
1153 $content .= $this->course_enrolment_icons($course);
1154 $content .= html_writer::end_tag('div');
1156 $content .= html_writer::start_tag('div', array('class' => 'content'));
1157 $content .= $this->coursecat_coursebox_content($chelper, $course);
1158 $content .= html_writer::end_tag('div');
1160 $content .= html_writer::end_tag('div'); // .coursebox
1161 return $content;
1165 * Returns HTML to display course summary.
1167 * @param coursecat_helper $chelper
1168 * @param core_course_list_element $course
1169 * @return string
1171 protected function course_summary(coursecat_helper $chelper, core_course_list_element $course): string {
1172 $content = '';
1173 if ($course->has_summary()) {
1174 $content .= html_writer::start_tag('div', ['class' => 'summary']);
1175 $content .= $chelper->get_course_formatted_summary($course,
1176 array('overflowdiv' => true, 'noclean' => true, 'para' => false));
1177 $content .= html_writer::end_tag('div');
1179 return $content;
1183 * Returns HTML to display course contacts.
1185 * @param core_course_list_element $course
1186 * @return string
1188 protected function course_contacts(core_course_list_element $course) {
1189 $content = '';
1190 if ($course->has_course_contacts()) {
1191 $content .= html_writer::start_tag('ul', ['class' => 'teachers']);
1192 foreach ($course->get_course_contacts() as $coursecontact) {
1193 $rolenames = array_map(function ($role) {
1194 return $role->displayname;
1195 }, $coursecontact['roles']);
1196 $name = html_writer::tag('span', implode(", ", $rolenames).': ', ['class' => 'font-weight-bold']);
1197 $name .= html_writer::link(new moodle_url('/user/view.php',
1198 ['id' => $coursecontact['user']->id, 'course' => SITEID]),
1199 $coursecontact['username']);
1200 $content .= html_writer::tag('li', $name);
1202 $content .= html_writer::end_tag('ul');
1204 return $content;
1208 * Returns HTML to display course overview files.
1210 * @param core_course_list_element $course
1211 * @return string
1213 protected function course_overview_files(core_course_list_element $course): string {
1214 global $CFG;
1216 $contentimages = $contentfiles = '';
1217 foreach ($course->get_course_overviewfiles() as $file) {
1218 $isimage = $file->is_valid_image();
1219 $url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
1220 '/' . $file->get_contextid() . '/' . $file->get_component() . '/' .
1221 $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
1222 if ($isimage) {
1223 $contentimages .= html_writer::tag('div',
1224 html_writer::empty_tag('img', ['src' => $url]),
1225 ['class' => 'courseimage']);
1226 } else {
1227 $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
1228 $filename = html_writer::tag('span', $image, ['class' => 'fp-icon']).
1229 html_writer::tag('span', $file->get_filename(), ['class' => 'fp-filename']);
1230 $contentfiles .= html_writer::tag('span',
1231 html_writer::link($url, $filename),
1232 ['class' => 'coursefile fp-filename-icon']);
1235 return $contentimages . $contentfiles;
1239 * Returns HTML to display course category name.
1241 * @param coursecat_helper $chelper
1242 * @param core_course_list_element $course
1243 * @return string
1245 protected function course_category_name(coursecat_helper $chelper, core_course_list_element $course): string {
1246 $content = '';
1247 // Display course category if necessary (for example in search results).
1248 if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
1249 if ($cat = core_course_category::get($course->category, IGNORE_MISSING)) {
1250 $content .= html_writer::start_tag('div', ['class' => 'coursecat']);
1251 $content .= html_writer::tag('span', get_string('category').': ', ['class' => 'font-weight-bold']);
1252 $content .= html_writer::link(new moodle_url('/course/index.php', ['categoryid' => $cat->id]),
1253 $cat->get_formatted_name(), ['class' => $cat->visible ? '' : 'dimmed']);
1254 $content .= html_writer::end_tag('div');
1257 return $content;
1261 * Returns HTML to display course custom fields.
1263 * @param core_course_list_element $course
1264 * @return string
1266 protected function course_custom_fields(core_course_list_element $course): string {
1267 $content = '';
1268 if ($course->has_custom_fields()) {
1269 $handler = core_course\customfield\course_handler::create();
1270 $customfields = $handler->display_custom_fields_data($course->get_custom_fields());
1271 $content .= \html_writer::tag('div', $customfields, ['class' => 'customfields-container']);
1273 return $content;
1277 * Returns HTML to display course content (summary, course contacts and optionally category name)
1279 * This method is called from coursecat_coursebox() and may be re-used in AJAX
1281 * @param coursecat_helper $chelper various display options
1282 * @param stdClass|core_course_list_element $course
1283 * @return string
1285 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) {
1286 if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
1287 return '';
1289 if ($course instanceof stdClass) {
1290 $course = new core_course_list_element($course);
1292 $content = \html_writer::start_tag('div', ['class' => 'd-flex']);
1293 $content .= $this->course_overview_files($course);
1294 $content .= \html_writer::start_tag('div', ['class' => 'flex-grow-1']);
1295 $content .= $this->course_summary($chelper, $course);
1296 $content .= $this->course_contacts($course);
1297 $content .= $this->course_category_name($chelper, $course);
1298 $content .= $this->course_custom_fields($course);
1299 $content .= \html_writer::end_tag('div');
1300 $content .= \html_writer::end_tag('div');
1301 return $content;
1305 * Renders the list of courses
1307 * This is internal function, please use {@link core_course_renderer::courses_list()} or another public
1308 * method from outside of the class
1310 * If list of courses is specified in $courses; the argument $chelper is only used
1311 * to retrieve display options and attributes, only methods get_show_courses(),
1312 * get_courses_display_option() and get_and_erase_attributes() are called.
1314 * @param coursecat_helper $chelper various display options
1315 * @param array $courses the list of courses to display
1316 * @param int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable),
1317 * defaulted to count($courses)
1318 * @return string
1320 protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) {
1321 global $CFG;
1322 if ($totalcount === null) {
1323 $totalcount = count($courses);
1325 if (!$totalcount) {
1326 // Courses count is cached during courses retrieval.
1327 return '';
1330 if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) {
1331 // In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit
1332 if ($totalcount <= $CFG->courseswithsummarieslimit) {
1333 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
1334 } else {
1335 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
1339 // prepare content of paging bar if it is needed
1340 $paginationurl = $chelper->get_courses_display_option('paginationurl');
1341 $paginationallowall = $chelper->get_courses_display_option('paginationallowall');
1342 if ($totalcount > count($courses)) {
1343 // there are more results that can fit on one page
1344 if ($paginationurl) {
1345 // the option paginationurl was specified, display pagingbar
1346 $perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage);
1347 $page = $chelper->get_courses_display_option('offset') / $perpage;
1348 $pagingbar = $this->paging_bar($totalcount, $page, $perpage,
1349 $paginationurl->out(false, array('perpage' => $perpage)));
1350 if ($paginationallowall) {
1351 $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')),
1352 get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
1354 } else if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) {
1355 // the option for 'View more' link was specified, display more link
1356 $viewmoretext = $chelper->get_courses_display_option('viewmoretext', new lang_string('viewmore'));
1357 $morelink = html_writer::tag(
1358 'div',
1359 html_writer::link($viewmoreurl, $viewmoretext, ['class' => 'btn btn-secondary']),
1360 ['class' => 'paging paging-morelink']
1363 } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
1364 // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
1365 $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
1366 get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
1369 // display list of courses
1370 $attributes = $chelper->get_and_erase_attributes('courses');
1371 $content = html_writer::start_tag('div', $attributes);
1373 if (!empty($pagingbar)) {
1374 $content .= $pagingbar;
1377 $coursecount = 0;
1378 foreach ($courses as $course) {
1379 $coursecount ++;
1380 $classes = ($coursecount%2) ? 'odd' : 'even';
1381 if ($coursecount == 1) {
1382 $classes .= ' first';
1384 if ($coursecount >= count($courses)) {
1385 $classes .= ' last';
1387 $content .= $this->coursecat_coursebox($chelper, $course, $classes);
1390 if (!empty($pagingbar)) {
1391 $content .= $pagingbar;
1393 if (!empty($morelink)) {
1394 $content .= $morelink;
1397 $content .= html_writer::end_tag('div'); // .courses
1398 return $content;
1402 * Renders the list of subcategories in a category
1404 * @param coursecat_helper $chelper various display options
1405 * @param core_course_category $coursecat
1406 * @param int $depth depth of the category in the current tree
1407 * @return string
1409 protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth) {
1410 global $CFG;
1411 $subcategories = array();
1412 if (!$chelper->get_categories_display_option('nodisplay')) {
1413 $subcategories = $coursecat->get_children($chelper->get_categories_display_options());
1415 $totalcount = $coursecat->get_children_count();
1416 if (!$totalcount) {
1417 // Note that we call core_course_category::get_children_count() AFTER core_course_category::get_children()
1418 // to avoid extra DB requests.
1419 // Categories count is cached during children categories retrieval.
1420 return '';
1423 // prepare content of paging bar or more link if it is needed
1424 $paginationurl = $chelper->get_categories_display_option('paginationurl');
1425 $paginationallowall = $chelper->get_categories_display_option('paginationallowall');
1426 if ($totalcount > count($subcategories)) {
1427 if ($paginationurl) {
1428 // the option 'paginationurl was specified, display pagingbar
1429 $perpage = $chelper->get_categories_display_option('limit', $CFG->coursesperpage);
1430 $page = $chelper->get_categories_display_option('offset') / $perpage;
1431 $pagingbar = $this->paging_bar($totalcount, $page, $perpage,
1432 $paginationurl->out(false, array('perpage' => $perpage)));
1433 if ($paginationallowall) {
1434 $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')),
1435 get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
1437 } else if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) {
1438 // the option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id)
1439 if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
1440 $viewmoreurl->param('categoryid', $coursecat->id);
1442 $viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore'));
1443 $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext),
1444 array('class' => 'paging paging-morelink'));
1446 } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
1447 // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
1448 $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
1449 get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
1452 // display list of subcategories
1453 $content = html_writer::start_tag('div', array('class' => 'subcategories'));
1455 if (!empty($pagingbar)) {
1456 $content .= $pagingbar;
1459 foreach ($subcategories as $subcategory) {
1460 $content .= $this->coursecat_category($chelper, $subcategory, $depth + 1);
1463 if (!empty($pagingbar)) {
1464 $content .= $pagingbar;
1466 if (!empty($morelink)) {
1467 $content .= $morelink;
1470 $content .= html_writer::end_tag('div');
1471 return $content;
1475 * Make sure that javascript file for AJAX expanding of courses and categories content is included
1477 protected function coursecat_include_js() {
1478 if (!$this->page->requires->should_create_one_time_item_now('core_course_categoryexpanderjsinit')) {
1479 return;
1482 // We must only load this module once.
1483 $this->page->requires->yui_module('moodle-course-categoryexpander',
1484 'Y.Moodle.course.categoryexpander.init');
1488 * Returns HTML to display the subcategories and courses in the given category
1490 * This method is re-used by AJAX to expand content of not loaded category
1492 * @param coursecat_helper $chelper various display options
1493 * @param core_course_category $coursecat
1494 * @param int $depth depth of the category in the current tree
1495 * @return string
1497 protected function coursecat_category_content(coursecat_helper $chelper, $coursecat, $depth) {
1498 $content = '';
1499 // Subcategories
1500 $content .= $this->coursecat_subcategories($chelper, $coursecat, $depth);
1502 // AUTO show courses: Courses will be shown expanded if this is not nested category,
1503 // and number of courses no bigger than $CFG->courseswithsummarieslimit.
1504 $showcoursesauto = $chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO;
1505 if ($showcoursesauto && $depth) {
1506 // this is definitely collapsed mode
1507 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
1510 // Courses
1511 if ($chelper->get_show_courses() > core_course_renderer::COURSECAT_SHOW_COURSES_COUNT) {
1512 $courses = array();
1513 if (!$chelper->get_courses_display_option('nodisplay')) {
1514 $courses = $coursecat->get_courses($chelper->get_courses_display_options());
1516 if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) {
1517 // the option for 'View more' link was specified, display more link (if it is link to category view page, add category id)
1518 if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
1519 $chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('categoryid' => $coursecat->id)));
1522 $content .= $this->coursecat_courses($chelper, $courses, $coursecat->get_courses_count());
1525 if ($showcoursesauto) {
1526 // restore the show_courses back to AUTO
1527 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO);
1530 return $content;
1534 * Returns HTML to display a course category as a part of a tree
1536 * This is an internal function, to display a particular category and all its contents
1537 * use {@link core_course_renderer::course_category()}
1539 * @param coursecat_helper $chelper various display options
1540 * @param core_course_category $coursecat
1541 * @param int $depth depth of this category in the current tree
1542 * @return string
1544 protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) {
1545 // open category tag
1546 $classes = array('category');
1547 if (empty($coursecat->visible)) {
1548 $classes[] = 'dimmed_category';
1550 if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {
1551 // do not load content
1552 $categorycontent = '';
1553 $classes[] = 'notloaded';
1554 if ($coursecat->get_children_count() ||
1555 ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_COLLAPSED && $coursecat->get_courses_count())) {
1556 $classes[] = 'with_children';
1557 $classes[] = 'collapsed';
1559 } else {
1560 // load category content
1561 $categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth);
1562 $classes[] = 'loaded';
1563 if (!empty($categorycontent)) {
1564 $classes[] = 'with_children';
1565 // Category content loaded with children.
1566 $this->categoryexpandedonload = true;
1570 // Make sure JS file to expand category content is included.
1571 $this->coursecat_include_js();
1573 $content = html_writer::start_tag('div', array(
1574 'class' => join(' ', $classes),
1575 'data-categoryid' => $coursecat->id,
1576 'data-depth' => $depth,
1577 'data-showcourses' => $chelper->get_show_courses(),
1578 'data-type' => self::COURSECAT_TYPE_CATEGORY,
1581 // category name
1582 $categoryname = $coursecat->get_formatted_name();
1583 $categoryname = html_writer::link(new moodle_url('/course/index.php',
1584 array('categoryid' => $coursecat->id)),
1585 $categoryname);
1586 if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT
1587 && ($coursescount = $coursecat->get_courses_count())) {
1588 $categoryname .= html_writer::tag('span', ' ('. $coursescount.')',
1589 array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse'));
1591 $content .= html_writer::start_tag('div', array('class' => 'info'));
1593 $content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname aabtn'));
1594 $content .= html_writer::end_tag('div'); // .info
1596 // add category content to the output
1597 $content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
1599 $content .= html_writer::end_tag('div'); // .category
1601 // Return the course category tree HTML
1602 return $content;
1606 * Returns HTML to display a tree of subcategories and courses in the given category
1608 * @param coursecat_helper $chelper various display options
1609 * @param core_course_category $coursecat top category (this category's name and description will NOT be added to the tree)
1610 * @return string
1612 protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
1613 // Reset the category expanded flag for this course category tree first.
1614 $this->categoryexpandedonload = false;
1615 $categorycontent = $this->coursecat_category_content($chelper, $coursecat, 0);
1616 if (empty($categorycontent)) {
1617 return '';
1620 // Start content generation
1621 $content = '';
1622 $attributes = $chelper->get_and_erase_attributes('course_category_tree clearfix');
1623 $content .= html_writer::start_tag('div', $attributes);
1625 if ($coursecat->get_children_count()) {
1626 $classes = array(
1627 'collapseexpand', 'aabtn'
1630 // Check if the category content contains subcategories with children's content loaded.
1631 if ($this->categoryexpandedonload) {
1632 $classes[] = 'collapse-all';
1633 $linkname = get_string('collapseall');
1634 } else {
1635 $linkname = get_string('expandall');
1638 // Only show the collapse/expand if there are children to expand.
1639 $content .= html_writer::start_tag('div', array('class' => 'collapsible-actions'));
1640 $content .= html_writer::link('#', $linkname, array('class' => implode(' ', $classes)));
1641 $content .= html_writer::end_tag('div');
1642 $this->page->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle');
1645 $content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
1647 $content .= html_writer::end_tag('div'); // .course_category_tree
1649 return $content;
1653 * Renders HTML to display particular course category - list of it's subcategories and courses
1655 * Invoked from /course/index.php
1657 * @param int|stdClass|core_course_category $category
1659 public function course_category($category) {
1660 global $CFG;
1661 $usertop = core_course_category::user_top();
1662 if (empty($category)) {
1663 $coursecat = $usertop;
1664 } else if (is_object($category) && $category instanceof core_course_category) {
1665 $coursecat = $category;
1666 } else {
1667 $coursecat = core_course_category::get(is_object($category) ? $category->id : $category);
1669 $site = get_site();
1670 $actionbar = new \core_course\output\category_action_bar($this->page, $coursecat);
1671 $output = $this->render_from_template('core_course/category_actionbar', $actionbar->export_for_template($this));
1673 if (core_course_category::is_simple_site()) {
1674 // There is only one category in the system, do not display link to it.
1675 $strfulllistofcourses = get_string('fulllistofcourses');
1676 $this->page->set_title("$site->shortname: $strfulllistofcourses");
1677 } else if (!$coursecat->id || !$coursecat->is_uservisible()) {
1678 $strcategories = get_string('categories');
1679 $this->page->set_title("$site->shortname: $strcategories");
1680 } else {
1681 $strfulllistofcourses = get_string('fulllistofcourses');
1682 $this->page->set_title("$site->shortname: $strfulllistofcourses");
1685 // Print current category description
1686 $chelper = new coursecat_helper();
1687 if ($description = $chelper->get_category_formatted_description($coursecat)) {
1688 $output .= $this->box($description, array('class' => 'generalbox info'));
1691 // Prepare parameters for courses and categories lists in the tree
1692 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO)
1693 ->set_attributes(array('class' => 'category-browse category-browse-'.$coursecat->id));
1695 $coursedisplayoptions = array();
1696 $catdisplayoptions = array();
1697 $browse = optional_param('browse', null, PARAM_ALPHA);
1698 $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT);
1699 $page = optional_param('page', 0, PARAM_INT);
1700 $baseurl = new moodle_url('/course/index.php');
1701 if ($coursecat->id) {
1702 $baseurl->param('categoryid', $coursecat->id);
1704 if ($perpage != $CFG->coursesperpage) {
1705 $baseurl->param('perpage', $perpage);
1707 $coursedisplayoptions['limit'] = $perpage;
1708 $catdisplayoptions['limit'] = $perpage;
1709 if ($browse === 'courses' || !$coursecat->get_children_count()) {
1710 $coursedisplayoptions['offset'] = $page * $perpage;
1711 $coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses'));
1712 $catdisplayoptions['nodisplay'] = true;
1713 $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories'));
1714 $catdisplayoptions['viewmoretext'] = new lang_string('viewallsubcategories');
1715 } else if ($browse === 'categories' || !$coursecat->get_courses_count()) {
1716 $coursedisplayoptions['nodisplay'] = true;
1717 $catdisplayoptions['offset'] = $page * $perpage;
1718 $catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories'));
1719 $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses'));
1720 $coursedisplayoptions['viewmoretext'] = new lang_string('viewallcourses');
1721 } else {
1722 // we have a category that has both subcategories and courses, display pagination separately
1723 $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1));
1724 $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1));
1726 $chelper->set_courses_display_options($coursedisplayoptions)->set_categories_display_options($catdisplayoptions);
1728 // Display course category tree.
1729 $output .= $this->coursecat_tree($chelper, $coursecat);
1731 return $output;
1735 * Serves requests to /course/category.ajax.php
1737 * In this renderer implementation it may expand the category content or
1738 * course content.
1740 * @return string
1741 * @throws coding_exception
1743 public function coursecat_ajax() {
1744 global $DB, $CFG;
1746 $type = required_param('type', PARAM_INT);
1748 if ($type === self::COURSECAT_TYPE_CATEGORY) {
1749 // This is a request for a category list of some kind.
1750 $categoryid = required_param('categoryid', PARAM_INT);
1751 $showcourses = required_param('showcourses', PARAM_INT);
1752 $depth = required_param('depth', PARAM_INT);
1754 $category = core_course_category::get($categoryid);
1756 $chelper = new coursecat_helper();
1757 $baseurl = new moodle_url('/course/index.php', array('categoryid' => $categoryid));
1758 $coursedisplayoptions = array(
1759 'limit' => $CFG->coursesperpage,
1760 'viewmoreurl' => new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1))
1762 $catdisplayoptions = array(
1763 'limit' => $CFG->coursesperpage,
1764 'viewmoreurl' => new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1))
1766 $chelper->set_show_courses($showcourses)->
1767 set_courses_display_options($coursedisplayoptions)->
1768 set_categories_display_options($catdisplayoptions);
1770 return $this->coursecat_category_content($chelper, $category, $depth);
1771 } else if ($type === self::COURSECAT_TYPE_COURSE) {
1772 // This is a request for the course information.
1773 $courseid = required_param('courseid', PARAM_INT);
1775 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
1777 $chelper = new coursecat_helper();
1778 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
1779 return $this->coursecat_coursebox_content($chelper, $course);
1780 } else {
1781 throw new coding_exception('Invalid request type');
1786 * Renders html to display search result page
1788 * @param array $searchcriteria may contain elements: search, blocklist, modulelist, tagid
1789 * @return string
1791 public function search_courses($searchcriteria) {
1792 global $CFG;
1793 $content = '';
1795 $search = '';
1796 if (!empty($searchcriteria['search'])) {
1797 $search = $searchcriteria['search'];
1799 $content .= $this->course_search_form($search);
1801 if (!empty($searchcriteria)) {
1802 // print search results
1804 $displayoptions = array('sort' => array('displayname' => 1));
1805 // take the current page and number of results per page from query
1806 $perpage = optional_param('perpage', 0, PARAM_RAW);
1807 if ($perpage !== 'all') {
1808 $displayoptions['limit'] = ((int)$perpage <= 0) ? $CFG->coursesperpage : (int)$perpage;
1809 $page = optional_param('page', 0, PARAM_INT);
1810 $displayoptions['offset'] = $displayoptions['limit'] * $page;
1812 // options 'paginationurl' and 'paginationallowall' are only used in method coursecat_courses()
1813 $displayoptions['paginationurl'] = new moodle_url('/course/search.php', $searchcriteria);
1814 $displayoptions['paginationallowall'] = true; // allow adding link 'View all'
1816 $class = 'course-search-result';
1817 foreach ($searchcriteria as $key => $value) {
1818 if (!empty($value)) {
1819 $class .= ' course-search-result-'. $key;
1822 $chelper = new coursecat_helper();
1823 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT)->
1824 set_courses_display_options($displayoptions)->
1825 set_search_criteria($searchcriteria)->
1826 set_attributes(array('class' => $class));
1828 $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
1829 $totalcount = core_course_category::search_courses_count($searchcriteria);
1830 $courseslist = $this->coursecat_courses($chelper, $courses, $totalcount);
1832 if (!$totalcount) {
1833 if (!empty($searchcriteria['search'])) {
1834 $content .= $this->heading(get_string('nocoursesfound', '', $searchcriteria['search']));
1835 } else {
1836 $content .= $this->heading(get_string('novalidcourses'));
1838 } else {
1839 $content .= $this->heading(get_string('searchresults'). ": $totalcount");
1840 $content .= $courseslist;
1843 return $content;
1847 * Renders html to print list of courses tagged with particular tag
1849 * @param int $tagid id of the tag
1850 * @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
1851 * are displayed on the page and the per-page limit may be bigger
1852 * @param int $fromctx context id where the link was displayed, may be used by callbacks
1853 * to display items in the same context first
1854 * @param int $ctx context id where to search for records
1855 * @param bool $rec search in subcontexts as well
1856 * @param array $displayoptions
1857 * @return string empty string if no courses are marked with this tag or rendered list of courses
1859 public function tagged_courses($tagid, $exclusivemode = true, $ctx = 0, $rec = true, $displayoptions = null) {
1860 global $CFG;
1861 if (empty($displayoptions)) {
1862 $displayoptions = array();
1864 $showcategories = !core_course_category::is_simple_site();
1865 $displayoptions += array('limit' => $CFG->coursesperpage, 'offset' => 0);
1866 $chelper = new coursecat_helper();
1867 $searchcriteria = array('tagid' => $tagid, 'ctx' => $ctx, 'rec' => $rec);
1868 $chelper->set_show_courses($showcategories ? self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT :
1869 self::COURSECAT_SHOW_COURSES_EXPANDED)->
1870 set_search_criteria($searchcriteria)->
1871 set_courses_display_options($displayoptions)->
1872 set_attributes(array('class' => 'course-search-result course-search-result-tagid'));
1873 // (we set the same css class as in search results by tagid)
1874 if ($totalcount = core_course_category::search_courses_count($searchcriteria)) {
1875 $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
1876 if ($exclusivemode) {
1877 return $this->coursecat_courses($chelper, $courses, $totalcount);
1878 } else {
1879 $tagfeed = new core_tag\output\tagfeed();
1880 $img = $this->output->pix_icon('i/course', '');
1881 foreach ($courses as $course) {
1882 $url = course_get_url($course);
1883 $imgwithlink = html_writer::link($url, $img);
1884 $coursename = html_writer::link($url, $course->get_formatted_name());
1885 $details = '';
1886 if ($showcategories && ($cat = core_course_category::get($course->category, IGNORE_MISSING))) {
1887 $details = get_string('category').': '.
1888 html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
1889 $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
1891 $tagfeed->add($imgwithlink, $coursename, $details);
1893 return $this->output->render_from_template('core_tag/tagfeed', $tagfeed->export_for_template($this->output));
1896 return '';
1900 * Returns HTML to display one remote course
1902 * @param stdClass $course remote course information, contains properties:
1903 id, remoteid, shortname, fullname, hostid, summary, summaryformat, cat_name, hostname
1904 * @return string
1906 protected function frontpage_remote_course(stdClass $course) {
1907 $url = new moodle_url('/auth/mnet/jump.php', array(
1908 'hostid' => $course->hostid,
1909 'wantsurl' => '/course/view.php?id='. $course->remoteid
1912 $output = '';
1913 $output .= html_writer::start_tag('div', array('class' => 'coursebox remotecoursebox clearfix'));
1914 $output .= html_writer::start_tag('div', array('class' => 'info'));
1915 $output .= html_writer::start_tag('h3', array('class' => 'coursename'));
1916 $output .= html_writer::link($url, format_string($course->fullname), array('title' => get_string('entercourse')));
1917 $output .= html_writer::end_tag('h3'); // .name
1918 $output .= html_writer::tag('div', '', array('class' => 'moreinfo'));
1919 $output .= html_writer::end_tag('div'); // .info
1920 $output .= html_writer::start_tag('div', array('class' => 'content'));
1921 $output .= html_writer::start_tag('div', array('class' => 'summary'));
1922 $options = new stdClass();
1923 $options->noclean = true;
1924 $options->para = false;
1925 $options->overflowdiv = true;
1926 $output .= format_text($course->summary, $course->summaryformat, $options);
1927 $output .= html_writer::end_tag('div'); // .summary
1928 $addinfo = format_string($course->hostname) . ' : '
1929 . format_string($course->cat_name) . ' : '
1930 . format_string($course->shortname);
1931 $output .= html_writer::tag('div', $addinfo, array('class' => 'remotecourseinfo'));
1932 $output .= html_writer::end_tag('div'); // .content
1933 $output .= html_writer::end_tag('div'); // .coursebox
1934 return $output;
1938 * Returns HTML to display one remote host
1940 * @param array $host host information, contains properties: name, url, count
1941 * @return string
1943 protected function frontpage_remote_host($host) {
1944 $output = '';
1945 $output .= html_writer::start_tag('div', array('class' => 'coursebox remotehost clearfix'));
1946 $output .= html_writer::start_tag('div', array('class' => 'info'));
1947 $output .= html_writer::start_tag('h3', array('class' => 'name'));
1948 $output .= html_writer::link($host['url'], s($host['name']), array('title' => s($host['name'])));
1949 $output .= html_writer::end_tag('h3'); // .name
1950 $output .= html_writer::tag('div', '', array('class' => 'moreinfo'));
1951 $output .= html_writer::end_tag('div'); // .info
1952 $output .= html_writer::start_tag('div', array('class' => 'content'));
1953 $output .= html_writer::start_tag('div', array('class' => 'summary'));
1954 $output .= $host['count'] . ' ' . get_string('courses');
1955 $output .= html_writer::end_tag('div'); // .content
1956 $output .= html_writer::end_tag('div'); // .coursebox
1957 return $output;
1961 * Returns HTML to print list of courses user is enrolled to for the frontpage
1963 * Also lists remote courses or remote hosts if MNET authorisation is used
1965 * @return string
1967 public function frontpage_my_courses() {
1968 global $USER, $CFG, $DB;
1970 if (!isloggedin() or isguestuser()) {
1971 return '';
1974 $output = '';
1975 $courses = enrol_get_my_courses('summary, summaryformat');
1976 $rhosts = array();
1977 $rcourses = array();
1978 if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') {
1979 $rcourses = get_my_remotecourses($USER->id);
1980 $rhosts = get_my_remotehosts();
1983 if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) {
1985 $chelper = new coursecat_helper();
1986 $totalcount = count($courses);
1987 if (count($courses) > $CFG->frontpagecourselimit) {
1988 // There are more enrolled courses than we can display, display link to 'My courses'.
1989 $courses = array_slice($courses, 0, $CFG->frontpagecourselimit, true);
1990 $chelper->set_courses_display_options(array(
1991 'viewmoreurl' => new moodle_url('/my/courses.php'),
1992 'viewmoretext' => new lang_string('mycourses')
1994 } else if (core_course_category::top()->is_uservisible()) {
1995 // All enrolled courses are displayed, display link to 'All courses' if there are more courses in system.
1996 $chelper->set_courses_display_options(array(
1997 'viewmoreurl' => new moodle_url('/course/index.php'),
1998 'viewmoretext' => new lang_string('fulllistofcourses')
2000 $totalcount = $DB->count_records('course') - 1;
2002 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->
2003 set_attributes(array('class' => 'frontpage-course-list-enrolled'));
2004 $output .= $this->coursecat_courses($chelper, $courses, $totalcount);
2006 // MNET
2007 if (!empty($rcourses)) {
2008 // at the IDP, we know of all the remote courses
2009 $output .= html_writer::start_tag('div', array('class' => 'courses'));
2010 foreach ($rcourses as $course) {
2011 $output .= $this->frontpage_remote_course($course);
2013 $output .= html_writer::end_tag('div'); // .courses
2014 } elseif (!empty($rhosts)) {
2015 // non-IDP, we know of all the remote servers, but not courses
2016 $output .= html_writer::start_tag('div', array('class' => 'courses'));
2017 foreach ($rhosts as $host) {
2018 $output .= $this->frontpage_remote_host($host);
2020 $output .= html_writer::end_tag('div'); // .courses
2023 return $output;
2027 * Returns HTML to print list of available courses for the frontpage
2029 * @return string
2031 public function frontpage_available_courses() {
2032 global $CFG;
2034 $chelper = new coursecat_helper();
2035 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->
2036 set_courses_display_options(array(
2037 'recursive' => true,
2038 'limit' => $CFG->frontpagecourselimit,
2039 'viewmoreurl' => new moodle_url('/course/index.php'),
2040 'viewmoretext' => new lang_string('fulllistofcourses')));
2042 $chelper->set_attributes(array('class' => 'frontpage-course-list-all'));
2043 $courses = core_course_category::top()->get_courses($chelper->get_courses_display_options());
2044 $totalcount = core_course_category::top()->get_courses_count($chelper->get_courses_display_options());
2045 if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) {
2046 // Print link to create a new course, for the 1st available category.
2047 return $this->add_new_course_button();
2049 return $this->coursecat_courses($chelper, $courses, $totalcount);
2053 * Returns HTML to the "add new course" button for the page
2055 * @return string
2057 public function add_new_course_button() {
2058 global $CFG;
2059 // Print link to create a new course, for the 1st available category.
2060 $output = $this->container_start('buttons');
2061 $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat'));
2062 $output .= $this->single_button($url, get_string('addnewcourse'), 'get');
2063 $output .= $this->container_end('buttons');
2064 return $output;
2068 * Returns HTML to print tree with course categories and courses for the frontpage
2070 * @return string
2072 public function frontpage_combo_list() {
2073 global $CFG;
2074 // TODO MDL-10965 improve.
2075 $tree = core_course_category::top();
2076 if (!$tree->get_children_count()) {
2077 return '';
2079 $chelper = new coursecat_helper();
2080 $chelper->set_subcat_depth($CFG->maxcategorydepth)->
2081 set_categories_display_options(array(
2082 'limit' => $CFG->coursesperpage,
2083 'viewmoreurl' => new moodle_url('/course/index.php',
2084 array('browse' => 'categories', 'page' => 1))
2085 ))->
2086 set_courses_display_options(array(
2087 'limit' => $CFG->coursesperpage,
2088 'viewmoreurl' => new moodle_url('/course/index.php',
2089 array('browse' => 'courses', 'page' => 1))
2090 ))->
2091 set_attributes(array('class' => 'frontpage-category-combo'));
2092 return $this->coursecat_tree($chelper, $tree);
2096 * Returns HTML to print tree of course categories (with number of courses) for the frontpage
2098 * @return string
2100 public function frontpage_categories_list() {
2101 global $CFG;
2102 // TODO MDL-10965 improve.
2103 $tree = core_course_category::top();
2104 if (!$tree->get_children_count()) {
2105 return '';
2107 $chelper = new coursecat_helper();
2108 $chelper->set_subcat_depth($CFG->maxcategorydepth)->
2109 set_show_courses(self::COURSECAT_SHOW_COURSES_COUNT)->
2110 set_categories_display_options(array(
2111 'limit' => $CFG->coursesperpage,
2112 'viewmoreurl' => new moodle_url('/course/index.php',
2113 array('browse' => 'categories', 'page' => 1))
2114 ))->
2115 set_attributes(array('class' => 'frontpage-category-names'));
2116 return $this->coursecat_tree($chelper, $tree);
2120 * Renders the activity information.
2122 * Defer to template.
2124 * @param \core_course\output\activity_information $page
2125 * @return string html for the page
2127 public function render_activity_information(\core_course\output\activity_information $page) {
2128 $data = $page->export_for_template($this->output);
2129 return $this->output->render_from_template('core_course/activity_info', $data);
2133 * Renders the activity navigation.
2135 * Defer to template.
2137 * @param \core_course\output\activity_navigation $page
2138 * @return string html for the page
2140 public function render_activity_navigation(\core_course\output\activity_navigation $page) {
2141 $data = $page->export_for_template($this->output);
2142 return $this->output->render_from_template('core_course/activity_navigation', $data);
2146 * Display waiting information about backup size during uploading backup process
2147 * @param object $backupfile the backup stored_file
2148 * @return $html string
2150 public function sendingbackupinfo($backupfile) {
2151 $sizeinfo = new stdClass();
2152 $sizeinfo->total = number_format($backupfile->get_filesize() / 1000000, 2);
2153 $html = html_writer::tag('div', get_string('sendingsize', 'hub', $sizeinfo),
2154 array('class' => 'courseuploadtextinfo'));
2155 return $html;
2159 * Hub information (logo - name - description - link)
2160 * @param object $hubinfo
2161 * @return string html code
2163 public function hubinfo($hubinfo) {
2164 $screenshothtml = html_writer::empty_tag('img',
2165 array('src' => $hubinfo['imgurl'], 'alt' => $hubinfo['name']));
2166 $hubdescription = html_writer::tag('div', $screenshothtml,
2167 array('class' => 'hubscreenshot'));
2169 $hubdescription .= html_writer::tag('a', $hubinfo['name'],
2170 array('class' => 'hublink', 'href' => $hubinfo['url'],
2171 'onclick' => 'this.target="_blank"'));
2173 $hubdescription .= html_writer::tag('div', format_text($hubinfo['description'], FORMAT_PLAIN),
2174 array('class' => 'hubdescription'));
2175 $hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo clearfix'));
2177 return $hubdescription;
2181 * Output frontpage summary text and frontpage modules (stored as section 1 in site course)
2183 * This may be disabled in settings
2185 * @return string
2187 public function frontpage_section1() {
2188 global $SITE, $USER;
2190 $output = '';
2191 $editing = $this->page->user_is_editing();
2193 if ($editing) {
2194 // Make sure section with number 1 exists.
2195 course_create_sections_if_missing($SITE, 1);
2198 $modinfo = get_fast_modinfo($SITE);
2199 $section = $modinfo->get_section_info(1);
2202 if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
2204 $format = course_get_format($SITE);
2205 $frontpageclass = $format->get_output_classname('content\\frontpagesection');
2206 $frontpagesection = new $frontpageclass($format, $section);
2208 // The course outputs works with format renderers, not with course renderers.
2209 $renderer = $format->get_renderer($this->page);
2210 $output .= $renderer->render($frontpagesection);
2213 return $output;
2217 * Output news for the frontpage (extract from site-wide news forum)
2219 * @param stdClass $forum record from db table 'forum' that represents the site news forum
2220 * @return string
2222 protected function frontpage_news($forum) {
2223 global $CFG, $SITE, $SESSION, $USER;
2224 require_once($CFG->dirroot .'/mod/forum/lib.php');
2226 $output = '';
2228 if (isloggedin()) {
2229 $SESSION->fromdiscussion = $CFG->wwwroot;
2230 $subtext = '';
2231 if (\mod_forum\subscriptions::is_subscribed($USER->id, $forum)) {
2232 if (!\mod_forum\subscriptions::is_forcesubscribed($forum)) {
2233 $subtext = get_string('unsubscribe', 'forum');
2235 } else {
2236 $subtext = get_string('subscribe', 'forum');
2238 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $forum->id, 'sesskey' => sesskey()));
2239 $output .= html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
2242 $coursemodule = get_coursemodule_from_instance('forum', $forum->id);
2243 $context = context_module::instance($coursemodule->id);
2245 $entityfactory = mod_forum\local\container::get_entity_factory();
2246 $forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $SITE);
2248 $rendererfactory = mod_forum\local\container::get_renderer_factory();
2249 $discussionsrenderer = $rendererfactory->get_frontpage_news_discussion_list_renderer($forumentity);
2250 $cm = \cm_info::create($coursemodule);
2251 return $output . $discussionsrenderer->render($USER, $cm, null, null, 0, $SITE->newsitems);
2255 * Renders part of frontpage with a skip link (i.e. "My courses", "Site news", etc.)
2257 * @param string $skipdivid
2258 * @param string $contentsdivid
2259 * @param string $header Header of the part
2260 * @param string $contents Contents of the part
2261 * @return string
2263 protected function frontpage_part($skipdivid, $contentsdivid, $header, $contents) {
2264 if (strval($contents) === '') {
2265 return '';
2267 $output = html_writer::link('#' . $skipdivid,
2268 get_string('skipa', 'access', core_text::strtolower(strip_tags($header))),
2269 array('class' => 'skip-block skip aabtn'));
2271 // Wrap frontpage part in div container.
2272 $output .= html_writer::start_tag('div', array('id' => $contentsdivid));
2273 $output .= $this->heading($header);
2275 $output .= $contents;
2277 // End frontpage part div container.
2278 $output .= html_writer::end_tag('div');
2280 $output .= html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => $skipdivid));
2281 return $output;
2285 * Outputs contents for frontpage as configured in $CFG->frontpage or $CFG->frontpageloggedin
2287 * @return string
2289 public function frontpage() {
2290 global $CFG, $SITE;
2292 $output = '';
2294 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
2295 $frontpagelayout = $CFG->frontpageloggedin;
2296 } else {
2297 $frontpagelayout = $CFG->frontpage;
2300 foreach (explode(',', $frontpagelayout) as $v) {
2301 switch ($v) {
2302 // Display the main part of the front page.
2303 case FRONTPAGENEWS:
2304 if ($SITE->newsitems) {
2305 // Print forums only when needed.
2306 require_once($CFG->dirroot .'/mod/forum/lib.php');
2307 if (($newsforum = forum_get_course_forum($SITE->id, 'news')) &&
2308 ($forumcontents = $this->frontpage_news($newsforum))) {
2309 $newsforumcm = get_fast_modinfo($SITE)->instances['forum'][$newsforum->id];
2310 $output .= $this->frontpage_part('skipsitenews', 'site-news-forum',
2311 $newsforumcm->get_formatted_name(), $forumcontents);
2314 break;
2316 case FRONTPAGEENROLLEDCOURSELIST:
2317 $mycourseshtml = $this->frontpage_my_courses();
2318 if (!empty($mycourseshtml)) {
2319 $output .= $this->frontpage_part('skipmycourses', 'frontpage-course-list',
2320 get_string('mycourses'), $mycourseshtml);
2322 break;
2324 case FRONTPAGEALLCOURSELIST:
2325 $availablecourseshtml = $this->frontpage_available_courses();
2326 $output .= $this->frontpage_part('skipavailablecourses', 'frontpage-available-course-list',
2327 get_string('availablecourses'), $availablecourseshtml);
2328 break;
2330 case FRONTPAGECATEGORYNAMES:
2331 $output .= $this->frontpage_part('skipcategories', 'frontpage-category-names',
2332 get_string('categories'), $this->frontpage_categories_list());
2333 break;
2335 case FRONTPAGECATEGORYCOMBO:
2336 $output .= $this->frontpage_part('skipcourses', 'frontpage-category-combo',
2337 get_string('courses'), $this->frontpage_combo_list());
2338 break;
2340 case FRONTPAGECOURSESEARCH:
2341 $output .= $this->box($this->course_search_form(''), 'd-flex justify-content-center');
2342 break;
2345 $output .= '<br />';
2348 return $output;
2353 * Class storing display options and functions to help display course category and/or courses lists
2355 * This is a wrapper for core_course_category objects that also stores display options
2356 * and functions to retrieve sorted and paginated lists of categories/courses.
2358 * If theme overrides methods in core_course_renderers that access this class
2359 * it may as well not use this class at all or extend it.
2361 * @package core
2362 * @copyright 2013 Marina Glancy
2363 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2365 class coursecat_helper {
2366 /** @var string [none, collapsed, expanded] how (if) display courses list */
2367 protected $showcourses = 10; /* core_course_renderer::COURSECAT_SHOW_COURSES_COLLAPSED */
2368 /** @var int depth to expand subcategories in the tree (deeper subcategories will be loaded by AJAX or proceed to category page by clicking on category name) */
2369 protected $subcatdepth = 1;
2370 /** @var array options to display courses list */
2371 protected $coursesdisplayoptions = array();
2372 /** @var array options to display subcategories list */
2373 protected $categoriesdisplayoptions = array();
2374 /** @var array additional HTML attributes */
2375 protected $attributes = array();
2376 /** @var array search criteria if the list is a search result */
2377 protected $searchcriteria = null;
2380 * Sets how (if) to show the courses - none, collapsed, expanded, etc.
2382 * @param int $showcourses SHOW_COURSES_NONE, SHOW_COURSES_COLLAPSED, SHOW_COURSES_EXPANDED, etc.
2383 * @return coursecat_helper
2385 public function set_show_courses($showcourses) {
2386 $this->showcourses = $showcourses;
2387 // Automatically set the options to preload summary and coursecontacts for core_course_category::get_courses()
2388 // and core_course_category::search_courses().
2389 $this->coursesdisplayoptions['summary'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_AUTO;
2390 $this->coursesdisplayoptions['coursecontacts'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_EXPANDED;
2391 $this->coursesdisplayoptions['customfields'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_COLLAPSED;
2392 return $this;
2396 * Returns how (if) to show the courses - none, collapsed, expanded, etc.
2398 * @return int - COURSECAT_SHOW_COURSES_NONE, COURSECAT_SHOW_COURSES_COLLAPSED, COURSECAT_SHOW_COURSES_EXPANDED, etc.
2400 public function get_show_courses() {
2401 return $this->showcourses;
2405 * Sets the maximum depth to expand subcategories in the tree
2407 * deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name
2409 * @param int $subcatdepth
2410 * @return coursecat_helper
2412 public function set_subcat_depth($subcatdepth) {
2413 $this->subcatdepth = $subcatdepth;
2414 return $this;
2418 * Returns the maximum depth to expand subcategories in the tree
2420 * deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name
2422 * @return int
2424 public function get_subcat_depth() {
2425 return $this->subcatdepth;
2429 * Sets options to display list of courses
2431 * Options are later submitted as argument to core_course_category::get_courses() and/or core_course_category::search_courses()
2433 * Options that core_course_category::get_courses() accept:
2434 * - recursive - return courses from subcategories as well. Use with care,
2435 * this may be a huge list!
2436 * - summary - preloads fields 'summary' and 'summaryformat'
2437 * - coursecontacts - preloads course contacts
2438 * - customfields - preloads custom fields data
2439 * - isenrolled - preloads indication whether this user is enrolled in the course
2440 * - sort - list of fields to sort. Example
2441 * array('idnumber' => 1, 'shortname' => 1, 'id' => -1)
2442 * will sort by idnumber asc, shortname asc and id desc.
2443 * Default: array('sortorder' => 1)
2444 * Only cached fields may be used for sorting!
2445 * - offset
2446 * - limit - maximum number of children to return, 0 or null for no limit
2448 * Options summary and coursecontacts are filled automatically in the set_show_courses()
2450 * Also renderer can set here any additional options it wants to pass between renderer functions.
2452 * @param array $options
2453 * @return coursecat_helper
2455 public function set_courses_display_options($options) {
2456 $this->coursesdisplayoptions = $options;
2457 $this->set_show_courses($this->showcourses); // this will calculate special display options
2458 return $this;
2462 * Sets one option to display list of courses
2464 * @see coursecat_helper::set_courses_display_options()
2466 * @param string $key
2467 * @param mixed $value
2468 * @return coursecat_helper
2470 public function set_courses_display_option($key, $value) {
2471 $this->coursesdisplayoptions[$key] = $value;
2472 return $this;
2476 * Return the specified option to display list of courses
2478 * @param string $optionname option name
2479 * @param mixed $defaultvalue default value for option if it is not specified
2480 * @return mixed
2482 public function get_courses_display_option($optionname, $defaultvalue = null) {
2483 if (array_key_exists($optionname, $this->coursesdisplayoptions)) {
2484 return $this->coursesdisplayoptions[$optionname];
2485 } else {
2486 return $defaultvalue;
2491 * Returns all options to display the courses
2493 * This array is usually passed to {@link core_course_category::get_courses()} or
2494 * {@link core_course_category::search_courses()}
2496 * @return array
2498 public function get_courses_display_options() {
2499 return $this->coursesdisplayoptions;
2503 * Sets options to display list of subcategories
2505 * Options 'sort', 'offset' and 'limit' are passed to core_course_category::get_children().
2506 * Any other options may be used by renderer functions
2508 * @param array $options
2509 * @return coursecat_helper
2511 public function set_categories_display_options($options) {
2512 $this->categoriesdisplayoptions = $options;
2513 return $this;
2517 * Return the specified option to display list of subcategories
2519 * @param string $optionname option name
2520 * @param mixed $defaultvalue default value for option if it is not specified
2521 * @return mixed
2523 public function get_categories_display_option($optionname, $defaultvalue = null) {
2524 if (array_key_exists($optionname, $this->categoriesdisplayoptions)) {
2525 return $this->categoriesdisplayoptions[$optionname];
2526 } else {
2527 return $defaultvalue;
2532 * Returns all options to display list of subcategories
2534 * This array is usually passed to {@link core_course_category::get_children()}
2536 * @return array
2538 public function get_categories_display_options() {
2539 return $this->categoriesdisplayoptions;
2543 * Sets additional general options to pass between renderer functions, usually HTML attributes
2545 * @param array $attributes
2546 * @return coursecat_helper
2548 public function set_attributes($attributes) {
2549 $this->attributes = $attributes;
2550 return $this;
2554 * Return all attributes and erases them so they are not applied again
2556 * @param string $classname adds additional class name to the beginning of $attributes['class']
2557 * @return array
2559 public function get_and_erase_attributes($classname) {
2560 $attributes = $this->attributes;
2561 $this->attributes = array();
2562 if (empty($attributes['class'])) {
2563 $attributes['class'] = '';
2565 $attributes['class'] = $classname . ' '. $attributes['class'];
2566 return $attributes;
2570 * Sets the search criteria if the course is a search result
2572 * Search string will be used to highlight terms in course name and description
2574 * @param array $searchcriteria
2575 * @return coursecat_helper
2577 public function set_search_criteria($searchcriteria) {
2578 $this->searchcriteria = $searchcriteria;
2579 return $this;
2583 * Returns formatted and filtered description of the given category
2585 * @param core_course_category $coursecat category
2586 * @param stdClass|array $options format options, by default [noclean,overflowdiv],
2587 * if context is not specified it will be added automatically
2588 * @return string|null
2590 public function get_category_formatted_description($coursecat, $options = null) {
2591 if ($coursecat->id && $coursecat->is_uservisible() && !empty($coursecat->description)) {
2592 if (!isset($coursecat->descriptionformat)) {
2593 $descriptionformat = FORMAT_MOODLE;
2594 } else {
2595 $descriptionformat = $coursecat->descriptionformat;
2597 if ($options === null) {
2598 $options = array('noclean' => true, 'overflowdiv' => true);
2599 } else {
2600 $options = (array)$options;
2602 $context = context_coursecat::instance($coursecat->id);
2603 if (!isset($options['context'])) {
2604 $options['context'] = $context;
2606 $text = file_rewrite_pluginfile_urls($coursecat->description,
2607 'pluginfile.php', $context->id, 'coursecat', 'description', null);
2608 return format_text($text, $descriptionformat, $options);
2610 return null;
2614 * Returns given course's summary with proper embedded files urls and formatted
2616 * @param core_course_list_element $course
2617 * @param array|stdClass $options additional formatting options
2618 * @return string
2620 public function get_course_formatted_summary($course, $options = array()) {
2621 global $CFG;
2622 require_once($CFG->libdir. '/filelib.php');
2623 if (!$course->has_summary()) {
2624 return '';
2626 $options = (array)$options;
2627 $context = context_course::instance($course->id);
2628 if (!isset($options['context'])) {
2629 // TODO see MDL-38521
2630 // option 1 (current), page context - no code required
2631 // option 2, system context
2632 // $options['context'] = context_system::instance();
2633 // option 3, course context:
2634 // $options['context'] = $context;
2635 // option 4, course category context:
2636 // $options['context'] = $context->get_parent_context();
2638 $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null);
2639 $summary = format_text($summary, $course->summaryformat, $options, $course->id);
2640 if (!empty($this->searchcriteria['search'])) {
2641 $summary = highlight($this->searchcriteria['search'], $summary);
2643 return $summary;
2647 * Returns course name as it is configured to appear in courses lists formatted to course context
2649 * @param core_course_list_element $course
2650 * @param array|stdClass $options additional formatting options
2651 * @return string
2653 public function get_course_formatted_name($course, $options = array()) {
2654 $options = (array)$options;
2655 if (!isset($options['context'])) {
2656 $options['context'] = context_course::instance($course->id);
2658 $name = format_string(get_course_display_name_for_list($course), true, $options);
2659 if (!empty($this->searchcriteria['search'])) {
2660 $name = highlight($this->searchcriteria['search'], $name);
2662 return $name;