Merge branch 'MDL-74656-fix' of https://github.com/paulholden/moodle
[moodle.git] / course / renderer.php
blobbbd2f69be6583b466f997183151c6c17b222176c
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 * @deprecated since 3.9
139 public function course_modchooser() {
140 throw new coding_exception('course_modchooser() can not be used anymore, please use course_activitychooser() instead.');
144 * Build the HTML for the module chooser javascript popup.
146 * @param int $courseid The course id to fetch modules for.
147 * @return string
149 public function course_activitychooser($courseid) {
151 if (!$this->page->requires->should_create_one_time_item_now('core_course_modchooser')) {
152 return '';
155 // Build an object of config settings that we can then hook into in the Activity Chooser.
156 $chooserconfig = (object) [
157 'tabmode' => get_config('core', 'activitychoosertabmode'),
159 $this->page->requires->js_call_amd('core_course/activitychooser', 'init', [$courseid, $chooserconfig]);
161 return '';
165 * Build the HTML for a specified set of modules
167 * @param array $modules A set of modules as used by the
168 * course_modchooser_module function
169 * @return string The composed HTML for the module
171 protected function course_modchooser_module_types($modules) {
172 debugging('Method core_course_renderer::course_modchooser_module_types() is deprecated, ' .
173 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER);
174 return '';
178 * Return the HTML for the specified module adding any required classes
180 * @param object $module An object containing the title, and link. An
181 * icon, and help text may optionally be specified. If the module
182 * contains subtypes in the types option, then these will also be
183 * displayed.
184 * @param array $classes Additional classes to add to the encompassing
185 * div element
186 * @return string The composed HTML for the module
188 protected function course_modchooser_module($module, $classes = array('option')) {
189 debugging('Method core_course_renderer::course_modchooser_module() is deprecated, ' .
190 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER);
191 return '';
194 protected function course_modchooser_title($title, $identifier = null) {
195 debugging('Method core_course_renderer::course_modchooser_title() is deprecated, ' .
196 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER);
197 return '';
201 * Renders HTML for displaying the sequence of course module editing buttons
203 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
205 * @see course_get_cm_edit_actions()
207 * @param action_link[] $actions Array of action_link objects
208 * @param cm_info $mod The module we are displaying actions for.
209 * @param array $displayoptions additional display options:
210 * ownerselector => A JS/CSS selector that can be used to find an cm node.
211 * If specified the owning node will be given the class 'action-menu-shown' when the action
212 * menu is being displayed.
213 * constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain
214 * the action menu to when it is being displayed.
215 * donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS.
216 * @return string
218 public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) {
219 global $CFG;
221 debugging(
222 'course_section_cm_edit_actions is deprecated. Use core_courseformat\\output\\local\\content\\cm\\controlmenu instead.',
223 DEBUG_DEVELOPER
226 if (empty($actions)) {
227 return '';
230 if (isset($displayoptions['ownerselector'])) {
231 $ownerselector = $displayoptions['ownerselector'];
232 } else if ($mod) {
233 $ownerselector = '#module-'.$mod->id;
234 } else {
235 debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER);
236 $ownerselector = 'li.activity';
239 if (isset($displayoptions['constraintselector'])) {
240 $constraint = $displayoptions['constraintselector'];
241 } else {
242 $constraint = '.course-content';
245 $menu = new action_menu();
246 $menu->set_owner_selector($ownerselector);
247 $menu->set_constraint($constraint);
248 $menu->set_menu_trigger(get_string('edit'));
250 foreach ($actions as $action) {
251 if ($action instanceof action_menu_link) {
252 $action->add_class('cm-edit-action');
254 $menu->add($action);
256 $menu->attributes['class'] .= ' section-cm-edit-actions commands';
258 // Prioritise the menu ahead of all other actions.
259 $menu->prioritise = true;
261 return $this->render($menu);
265 * Renders HTML for the menus to add activities and resources to the current course
267 * Renders the ajax control (the link which when clicked produces the activity chooser modal). No noscript fallback.
269 * @param stdClass $course
270 * @param int $section relative section number (field course_sections.section)
271 * @param int $sectionreturn The section to link back to
272 * @param array $displayoptions additional display options, for example blocks add
273 * option 'inblock' => true, suggesting to display controls vertically
274 * @return string
276 function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) {
277 // Check to see if user can add menus.
278 if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
279 || !$this->page->user_is_editing()) {
280 return '';
283 $data = [
284 'sectionid' => $section,
285 'sectionreturn' => $sectionreturn
287 $ajaxcontrol = $this->render_from_template('course/activitychooserbutton', $data);
289 // Load the JS for the modal.
290 $this->course_activitychooser($course->id);
292 return $ajaxcontrol;
296 * Render the deprecated nonajax activity chooser.
298 * @deprecated since Moodle 3.11
300 * @todo MDL-71331 deprecate this function
301 * @param stdClass $course the course object
302 * @param int $section relative section number (field course_sections.section)
303 * @param int $sectionreturn The section to link back to
304 * @param array $displayoptions additional display options, for example blocks add
305 * option 'inblock' => true, suggesting to display controls vertically
306 * @return string
308 private function course_section_add_cm_control_nonajax($course, $section, $sectionreturn = null,
309 $displayoptions = array()): string {
310 global $USER;
312 $vertical = !empty($displayoptions['inblock']);
314 // Check to see if user can add menus.
315 if (
316 !has_capability('moodle/course:manageactivities', context_course::instance($course->id))
317 || !$this->page->user_is_editing()
319 return '';
322 debugging('non-js dropdowns are deprecated.', DEBUG_DEVELOPER);
323 // Retrieve all modules with associated metadata.
324 $contentitemservice = \core_course\local\factory\content_item_service_factory::get_content_item_service();
325 $urlparams = ['section' => $section];
326 if (!is_null($sectionreturn)) {
327 $urlparams['sr'] = $sectionreturn;
329 $modules = $contentitemservice->get_content_items_for_user_in_course($USER, $course, $urlparams);
331 // Return if there are no content items to add.
332 if (empty($modules)) {
333 return '';
336 // We'll sort resources and activities into two lists.
337 $activities = array(MOD_CLASS_ACTIVITY => array(), MOD_CLASS_RESOURCE => array());
339 foreach ($modules as $module) {
340 $activityclass = MOD_CLASS_ACTIVITY;
341 if ($module->archetype == MOD_ARCHETYPE_RESOURCE) {
342 $activityclass = MOD_CLASS_RESOURCE;
343 } else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
344 // System modules cannot be added by user, do not add to dropdown.
345 continue;
347 $link = $module->link;
348 $activities[$activityclass][$link] = $module->title;
351 $straddactivity = get_string('addactivity');
352 $straddresource = get_string('addresource');
353 $sectionname = get_section_name($course, $section);
354 $strresourcelabel = get_string('addresourcetosection', null, $sectionname);
355 $stractivitylabel = get_string('addactivitytosection', null, $sectionname);
357 $nonajaxcontrol = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-'
358 . $section));
360 if (!$vertical) {
361 $nonajaxcontrol .= html_writer::start_tag('div', array('class' => 'horizontal'));
364 if (!empty($activities[MOD_CLASS_RESOURCE])) {
365 $select = new url_select($activities[MOD_CLASS_RESOURCE], '', array('' => $straddresource), "ressection$section");
366 $select->set_help_icon('resources');
367 $select->set_label($strresourcelabel, array('class' => 'accesshide'));
368 $nonajaxcontrol .= $this->output->render($select);
371 if (!empty($activities[MOD_CLASS_ACTIVITY])) {
372 $select = new url_select($activities[MOD_CLASS_ACTIVITY], '', array('' => $straddactivity), "section$section");
373 $select->set_help_icon('activities');
374 $select->set_label($stractivitylabel, array('class' => 'accesshide'));
375 $nonajaxcontrol .= $this->output->render($select);
378 if (!$vertical) {
379 $nonajaxcontrol .= html_writer::end_tag('div');
382 $nonajaxcontrol .= html_writer::end_tag('div');
384 return $nonajaxcontrol;
388 * Renders html to display a course search form
390 * @param string $value default value to populate the search field
391 * @return string
393 public function course_search_form($value = '') {
395 $data = [
396 'action' => \core_search\manager::get_course_search_url(),
397 'btnclass' => 'btn-primary',
398 'inputname' => 'q',
399 'searchstring' => get_string('searchcourses'),
400 'hiddenfields' => (object) ['name' => 'areaids', 'value' => 'core_course-course'],
401 'query' => $value
403 return $this->render_from_template('core/search_input', $data);
407 * Renders html for completion box on course page
409 * If completion is disabled, returns empty string
410 * If completion is automatic, returns an icon of the current completion state
411 * If completion is manual, returns a form (with an icon inside) that allows user to
412 * toggle completion
414 * @deprecated since Moodle 3.11
415 * @todo MDL-71183 Final deprecation in Moodle 4.3.
416 * @see \core_renderer::activity_information
418 * @param stdClass $course course object
419 * @param completion_info $completioninfo completion info for the course, it is recommended
420 * to fetch once for all modules in course/section for performance
421 * @param cm_info $mod module to show completion for
422 * @param array $displayoptions display options, not used in core
423 * @return string
425 public function course_section_cm_completion($course, &$completioninfo, cm_info $mod, $displayoptions = array()) {
426 global $CFG, $DB, $USER;
428 debugging(__FUNCTION__ . ' is deprecated and is being replaced by the activity_information output component.',
429 DEBUG_DEVELOPER);
431 $output = '';
433 $istrackeduser = $completioninfo->is_tracked_user($USER->id);
434 $isediting = $this->page->user_is_editing();
436 if (!empty($displayoptions['hidecompletion']) || !isloggedin() || isguestuser() || !$mod->uservisible) {
437 return $output;
439 if ($completioninfo === null) {
440 $completioninfo = new completion_info($course);
442 $completion = $completioninfo->is_enabled($mod);
444 if ($completion == COMPLETION_TRACKING_NONE) {
445 if ($isediting) {
446 $output .= html_writer::span('&nbsp;', 'filler');
448 return $output;
451 $completionicon = '';
453 if ($isediting || !$istrackeduser) {
454 switch ($completion) {
455 case COMPLETION_TRACKING_MANUAL :
456 $completionicon = 'manual-enabled'; break;
457 case COMPLETION_TRACKING_AUTOMATIC :
458 $completionicon = 'auto-enabled'; break;
460 } else {
461 $completiondata = $completioninfo->get_data($mod, true);
462 if ($completion == COMPLETION_TRACKING_MANUAL) {
463 switch($completiondata->completionstate) {
464 case COMPLETION_INCOMPLETE:
465 $completionicon = 'manual-n' . ($completiondata->overrideby ? '-override' : '');
466 break;
467 case COMPLETION_COMPLETE:
468 $completionicon = 'manual-y' . ($completiondata->overrideby ? '-override' : '');
469 break;
471 } else { // Automatic
472 switch($completiondata->completionstate) {
473 case COMPLETION_INCOMPLETE:
474 $completionicon = 'auto-n' . ($completiondata->overrideby ? '-override' : '');
475 break;
476 case COMPLETION_COMPLETE:
477 $completionicon = 'auto-y' . ($completiondata->overrideby ? '-override' : '');
478 break;
479 case COMPLETION_COMPLETE_PASS:
480 $completionicon = 'auto-pass'; break;
481 case COMPLETION_COMPLETE_FAIL:
482 $completionicon = 'auto-fail'; break;
486 if ($completionicon) {
487 $formattedname = html_entity_decode($mod->get_formatted_name(), ENT_QUOTES, 'UTF-8');
488 if (!$isediting && $istrackeduser && $completiondata->overrideby) {
489 $args = new stdClass();
490 $args->modname = $formattedname;
491 $overridebyuser = \core_user::get_user($completiondata->overrideby, '*', MUST_EXIST);
492 $args->overrideuser = fullname($overridebyuser);
493 $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $args);
494 } else {
495 $imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
498 if ($isediting || !$istrackeduser || !has_capability('moodle/course:togglecompletion', $mod->context)) {
499 // When editing, the icon is just an image.
500 $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
501 array('title' => $imgalt, 'class' => 'iconsmall'));
502 $output .= html_writer::tag('span', $this->output->render($completionpixicon),
503 array('class' => 'autocompletion'));
504 } else if ($completion == COMPLETION_TRACKING_MANUAL) {
505 $newstate =
506 $completiondata->completionstate == COMPLETION_COMPLETE
507 ? COMPLETION_INCOMPLETE
508 : COMPLETION_COMPLETE;
509 // In manual mode the icon is a toggle form...
511 // If this completion state is used by the
512 // conditional activities system, we need to turn
513 // off the JS.
514 $extraclass = '';
515 if (!empty($CFG->enableavailability) &&
516 core_availability\info::completion_value_used($course, $mod->id)) {
517 $extraclass = ' preventjs';
519 $output .= html_writer::start_tag('form', array('method' => 'post',
520 'action' => new moodle_url('/course/togglecompletion.php'),
521 'class' => 'togglecompletion'. $extraclass));
522 $output .= html_writer::start_tag('div');
523 $output .= html_writer::empty_tag('input', array(
524 'type' => 'hidden', 'name' => 'id', 'value' => $mod->id));
525 $output .= html_writer::empty_tag('input', array(
526 'type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
527 $output .= html_writer::empty_tag('input', array(
528 'type' => 'hidden', 'name' => 'modulename', 'value' => $formattedname));
529 $output .= html_writer::empty_tag('input', array(
530 'type' => 'hidden', 'name' => 'completionstate', 'value' => $newstate));
531 $output .= html_writer::tag('button',
532 $this->output->pix_icon('i/completion-' . $completionicon, $imgalt),
533 array('class' => 'btn btn-link', 'aria-live' => 'assertive'));
534 $output .= html_writer::end_tag('div');
535 $output .= html_writer::end_tag('form');
536 } else {
537 // In auto mode, the icon is just an image.
538 $completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
539 array('title' => $imgalt));
540 $output .= html_writer::tag('span', $this->output->render($completionpixicon),
541 array('class' => 'autocompletion'));
544 return $output;
548 * Checks if course module has any conditions that may make it unavailable for
549 * all or some of the students
551 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
553 * @param cm_info $mod
554 * @return bool
556 public function is_cm_conditionally_hidden(cm_info $mod) {
557 global $CFG;
559 debugging(
560 'is_cm_conditionally_hidden is deprecated. Use \core_availability\info_module::is_available_for_all instead',
561 DEBUG_DEVELOPER
564 $conditionalhidden = false;
565 if (!empty($CFG->enableavailability)) {
566 $info = new \core_availability\info_module($mod);
567 $conditionalhidden = !$info->is_available_for_all();
569 return $conditionalhidden;
573 * Renders html to display a name with the link to the course module on a course page
575 * If module is unavailable for user but still needs to be displayed
576 * in the list, just the name is returned without a link
578 * Note, that for course modules that never have separate pages (i.e. labels)
579 * this function return an empty string
581 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
583 * @param cm_info $mod
584 * @param array $displayoptions
585 * @return string
587 public function course_section_cm_name(cm_info $mod, $displayoptions = array()) {
588 debugging(
589 'course_section_cm_name is deprecated. Use core_courseformat\\output\\local\\content\\cm\\cmname class instead.',
590 DEBUG_DEVELOPER
593 if (!$mod->is_visible_on_course_page() || !$mod->url) {
594 // Nothing to be displayed to the user.
595 return '';
598 list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod);
599 $groupinglabel = $mod->get_grouping_label($textclasses);
601 // Render element that allows to edit activity name inline.
602 $format = course_get_format($mod->course);
603 $cmnameclass = $format->get_output_classname('content\\cm\\cmname');
604 // Mod inplace name editable.
605 $cmname = new $cmnameclass(
606 $format,
607 $mod->get_section_info(),
608 $mod,
609 $this->page->user_is_editing(),
610 $displayoptions
613 $data = $cmname->export_for_template($this->output);
615 return $this->output->render_from_template('core/inplace_editable', $data) .
616 $groupinglabel;
620 * Returns the CSS classes for the activity name/content
622 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
624 * For items which are hidden, unavailable or stealth but should be displayed
625 * to current user ($mod->is_visible_on_course_page()), we show those as dimmed.
626 * Students will also see as dimmed activities names that are not yet available
627 * but should still be displayed (without link) with availability info.
629 * @param cm_info $mod
630 * @return array array of two elements ($linkclasses, $textclasses)
632 protected function course_section_cm_classes(cm_info $mod) {
634 debugging(
635 'course_section_cm_classes is deprecated. Now it is part of core_courseformat\\output\\local\\content\\cm ',
636 DEBUG_DEVELOPER
639 $format = course_get_format($mod->course);
641 $cmclass = $format->get_output_classname('content\\cm');
642 $cmoutput = new $cmclass(
643 $format,
644 $mod->get_section_info(),
645 $mod,
647 return [
648 $cmoutput->get_link_classes(),
649 $cmoutput->get_text_classes(),
654 * Renders html to display a name with the link to the course module on a course page
656 * If module is unavailable for user but still needs to be displayed
657 * in the list, just the name is returned without a link
659 * Note, that for course modules that never have separate pages (i.e. labels)
660 * this function return an empty string
662 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
664 * @param cm_info $mod
665 * @param array $displayoptions
666 * @return string
668 public function course_section_cm_name_title(cm_info $mod, $displayoptions = array()) {
670 debugging(
671 'course_section_cm_name_title is deprecated. Use core_courseformat\\output\\local\\cm\\title class instead.',
672 DEBUG_DEVELOPER
675 $output = '';
676 $url = $mod->url;
677 if (!$mod->is_visible_on_course_page() || !$url) {
678 // Nothing to be displayed to the user.
679 return $output;
682 //Accessibility: for files get description via icon, this is very ugly hack!
683 $instancename = $mod->get_formatted_name();
684 $altname = $mod->modfullname;
685 // Avoid unnecessary duplication: if e.g. a forum name already
686 // includes the word forum (or Forum, etc) then it is unhelpful
687 // to include that in the accessible description that is added.
688 if (false !== strpos(core_text::strtolower($instancename),
689 core_text::strtolower($altname))) {
690 $altname = '';
692 // File type after name, for alphabetic lists (screen reader).
693 if ($altname) {
694 $altname = get_accesshide(' '.$altname);
697 list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod);
699 // Get on-click attribute value if specified and decode the onclick - it
700 // has already been encoded for display (puke).
701 $onclick = htmlspecialchars_decode($mod->onclick, ENT_QUOTES);
703 // Display link itself.
704 $instancename = html_writer::tag('span', $instancename . $altname, ['class' => 'instancename ml-1']);
706 $imageicon = html_writer::empty_tag('img', ['src' => $mod->get_icon_url(),
707 'class' => 'activityicon', 'alt' => '', 'role' => 'presentation', 'aria-hidden' => 'true']);
708 $imageicon = html_writer::tag('span', $imageicon, ['class' => 'activityiconcontainer courseicon']);
709 $activitylink = $imageicon . $instancename;
711 if ($mod->uservisible) {
712 $output .= html_writer::link($url, $activitylink, array('class' => 'aalink' . $linkclasses, 'onclick' => $onclick));
713 } else {
714 // We may be displaying this just in order to show information
715 // about visibility, without the actual link ($mod->is_visible_on_course_page()).
716 $output .= html_writer::tag('div', $activitylink, array('class' => $textclasses));
718 return $output;
722 * Renders html to display the module content on the course page (i.e. text of the labels)
724 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
726 * @param cm_info $mod
727 * @param array $displayoptions
728 * @return string
730 public function course_section_cm_text(cm_info $mod, $displayoptions = array()) {
732 debugging(
733 'course_section_cm_text is deprecated. Now it is part of core_courseformat\\output\\local\\content\\cm ',
734 DEBUG_DEVELOPER
737 $output = '';
738 if (!$mod->is_visible_on_course_page()) {
739 // nothing to be displayed to the user
740 return $output;
742 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
743 list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod);
744 if ($mod->url && $mod->uservisible) {
745 if ($content) {
746 // If specified, display extra content after link.
747 $output = html_writer::tag('div', $content, array('class' =>
748 trim('contentafterlink ' . $textclasses)));
750 } else {
751 $groupinglabel = $mod->get_grouping_label($textclasses);
753 // No link, so display only content.
754 $output = html_writer::tag('div', $content . $groupinglabel,
755 array('class' => 'contentwithoutlink ' . $textclasses));
757 return $output;
761 * Displays availability info for a course section or course module
763 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
764 * @param string $text
765 * @param string $additionalclasses
766 * @return string
768 public function availability_info($text, $additionalclasses = '') {
770 debugging(
771 'availability_info is deprecated. Use core_courseformat\\output\\local\\content\\section\\availability instead',
772 DEBUG_DEVELOPER
775 $data = ['text' => $text, 'classes' => $additionalclasses];
776 $additionalclasses = array_filter(explode(' ', $additionalclasses));
778 if (in_array('ishidden', $additionalclasses)) {
779 $data['ishidden'] = 1;
781 } else if (in_array('isstealth', $additionalclasses)) {
782 $data['isstealth'] = 1;
784 } else if (in_array('isrestricted', $additionalclasses)) {
785 $data['isrestricted'] = 1;
787 if (in_array('isfullinfo', $additionalclasses)) {
788 $data['isfullinfo'] = 1;
792 return $this->render_from_template('core/availability_info', $data);
796 * Renders HTML to show course module availability information (for someone who isn't allowed
797 * to see the activity itself, or for staff)
799 * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more.
800 * @param cm_info $mod
801 * @param array $displayoptions
802 * @return string
804 public function course_section_cm_availability(cm_info $mod, $displayoptions = array()) {
806 debugging(
807 'course_section_cm_availability is deprecated. Use core_courseformat\\output\\local\\content\\cm\\availability instead',
808 DEBUG_DEVELOPER
811 $format = course_get_format($mod->course);
813 $availabilityclass = $format->get_output_classname('content\\cm\\availability');
814 $availability = new $availabilityclass(
815 $format,
816 $mod->get_section_info(),
817 $mod,
819 $renderer = $format->get_renderer($this->page);
820 return $renderer->render($availability);
824 * Renders HTML to display one course module for display within a section.
826 * @deprecated since 4.0 - use core_course output components or course_format::course_section_updated_cm_item instead.
828 * This function calls:
829 * {@link core_course_renderer::course_section_cm()}
831 * @param stdClass $course
832 * @param completion_info $completioninfo
833 * @param cm_info $mod
834 * @param int|null $sectionreturn
835 * @param array $displayoptions
836 * @return String
838 public function course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = []) {
840 debugging(
841 'course_section_cm_list_item is deprecated. Use renderer course_section_updated_cm_item instead',
842 DEBUG_DEVELOPER
845 $output = '';
846 if ($modulehtml = $this->course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) {
847 $modclasses = 'activity ' . $mod->modname . ' modtype_' . $mod->modname . ' ' . $mod->extraclasses;
848 $output .= html_writer::tag('li', $modulehtml, array('class' => $modclasses, 'id' => 'module-' . $mod->id));
850 return $output;
854 * Renders HTML to display one course module in a course section
856 * This includes link, content, availability, completion info and additional information
857 * that module type wants to display (i.e. number of unread forum posts)
859 * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
861 * @param stdClass $course
862 * @param completion_info $completioninfo
863 * @param cm_info $mod
864 * @param int|null $sectionreturn
865 * @param array $displayoptions
866 * @return string
868 public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = []) {
870 debugging(
871 'course_section_cm is deprecated. Use core_courseformat\\output\\content\\cm output class instead.',
872 DEBUG_DEVELOPER
875 if (!$mod->is_visible_on_course_page()) {
876 return '';
879 $format = course_get_format($course);
880 $modinfo = $format->get_modinfo();
881 // Output renderers works only with real section_info objects.
882 if ($sectionreturn) {
883 $format->set_section_number($sectionreturn);
885 $section = $modinfo->get_section_info($format->get_section_number());
887 $cmclass = $format->get_output_classname('content\\cm');
888 $cm = new $cmclass($format, $section, $mod, $displayoptions);
889 // The course outputs works with format renderers, not with course renderers.
890 $renderer = $format->get_renderer($this->page);
891 $data = $cm->export_for_template($renderer);
892 return $this->output->render_from_template('core_courseformat/local/content/cm', $data);
896 * Message displayed to the user when they try to access unavailable activity following URL
898 * This method is a very simplified version of {@link course_section_cm()} to be part of the error
899 * notification only. It also does not check if module is visible on course page or not.
901 * The message will be displayed inside notification!
903 * @param cm_info $cm
904 * @return string
906 public function course_section_cm_unavailable_error_message(cm_info $cm) {
907 if ($cm->uservisible) {
908 return null;
910 if (!$cm->availableinfo) {
911 return get_string('activityiscurrentlyhidden');
914 $altname = get_accesshide(' ' . $cm->modfullname);
915 $name = html_writer::empty_tag('img', array('src' => $cm->get_icon_url(),
916 'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) .
917 html_writer::tag('span', ' '.$cm->get_formatted_name() . $altname, array('class' => 'instancename'));
918 $formattedinfo = \core_availability\info::format_info($cm->availableinfo, $cm->get_course());
919 return html_writer::div($name, 'activityinstance-error') .
920 html_writer::div($formattedinfo, 'availabilityinfo-error');
924 * Renders HTML to display a list of course modules in a course section
925 * Also displays "move here" controls in Javascript-disabled mode.
927 * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
929 * This function calls {@link core_course_renderer::course_section_cm()}
931 * @param stdClass $course course object
932 * @param int|stdClass|section_info $section relative section number or section object
933 * @param int $sectionreturn section number to return to
934 * @param int $displayoptions
935 * @return void
937 public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = []) {
938 global $USER;
940 debugging('course_section_cm_list is deprecated. Use core_courseformat\\output\\local\\content\\section\\cmlist '.
941 'classes instead.', DEBUG_DEVELOPER);
943 $output = '';
945 $format = course_get_format($course);
946 $modinfo = $format->get_modinfo();
948 if (is_object($section)) {
949 $section = $modinfo->get_section_info($section->section);
950 } else {
951 $section = $modinfo->get_section_info($section);
953 $completioninfo = new completion_info($course);
955 // check if we are currently in the process of moving a module with JavaScript disabled
956 $ismoving = $format->show_editor() && ismoving($course->id);
958 if ($ismoving) {
959 $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
962 // Get the list of modules visible to user (excluding the module being moved if there is one)
963 $moduleshtml = [];
964 if (!empty($modinfo->sections[$section->section])) {
965 foreach ($modinfo->sections[$section->section] as $modnumber) {
966 $mod = $modinfo->cms[$modnumber];
968 if ($ismoving and $mod->id == $USER->activitycopy) {
969 // do not display moving mod
970 continue;
973 if ($modulehtml = $this->course_section_cm_list_item($course,
974 $completioninfo, $mod, $sectionreturn, $displayoptions)) {
975 $moduleshtml[$modnumber] = $modulehtml;
980 $sectionoutput = '';
981 if (!empty($moduleshtml) || $ismoving) {
982 foreach ($moduleshtml as $modnumber => $modulehtml) {
983 if ($ismoving) {
984 $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey()));
985 $sectionoutput .= html_writer::tag('li',
986 html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere')),
987 array('class' => 'movehere'));
990 $sectionoutput .= $modulehtml;
993 if ($ismoving) {
994 $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
995 $sectionoutput .= html_writer::tag('li',
996 html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere')),
997 array('class' => 'movehere'));
1001 // Always output the section module list.
1002 $output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text'));
1004 return $output;
1008 * Displays a custom list of courses with paging bar if necessary
1010 * If $paginationurl is specified but $totalcount is not, the link 'View more'
1011 * appears under the list.
1013 * If both $paginationurl and $totalcount are specified, and $totalcount is
1014 * bigger than count($courses), a paging bar is displayed above and under the
1015 * courses list.
1017 * @param array $courses array of course records (or instances of core_course_list_element) to show on this page
1018 * @param bool $showcategoryname whether to add category name to the course description
1019 * @param string $additionalclasses additional CSS classes to add to the div.courses
1020 * @param moodle_url $paginationurl url to view more or url to form links to the other pages in paging bar
1021 * @param int $totalcount total number of courses on all pages, if omitted $paginationurl will be displayed as 'View more' link
1022 * @param int $page current page number (defaults to 0 referring to the first page)
1023 * @param int $perpage number of records per page (defaults to $CFG->coursesperpage)
1024 * @return string
1026 public function courses_list($courses, $showcategoryname = false, $additionalclasses = null, $paginationurl = null, $totalcount = null, $page = 0, $perpage = null) {
1027 global $CFG;
1028 // create instance of coursecat_helper to pass display options to function rendering courses list
1029 $chelper = new coursecat_helper();
1030 if ($showcategoryname) {
1031 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT);
1032 } else {
1033 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
1035 if ($totalcount !== null && $paginationurl !== null) {
1036 // add options to display pagination
1037 if ($perpage === null) {
1038 $perpage = $CFG->coursesperpage;
1040 $chelper->set_courses_display_options(array(
1041 'limit' => $perpage,
1042 'offset' => ((int)$page) * $perpage,
1043 'paginationurl' => $paginationurl,
1045 } else if ($paginationurl !== null) {
1046 // add options to display 'View more' link
1047 $chelper->set_courses_display_options(array('viewmoreurl' => $paginationurl));
1048 $totalcount = count($courses) + 1; // has to be bigger than count($courses) otherwise link will not be displayed
1050 $chelper->set_attributes(array('class' => $additionalclasses));
1051 $content = $this->coursecat_courses($chelper, $courses, $totalcount);
1052 return $content;
1056 * Returns HTML to display course name.
1058 * @param coursecat_helper $chelper
1059 * @param core_course_list_element $course
1060 * @return string
1062 protected function course_name(coursecat_helper $chelper, core_course_list_element $course): string {
1063 $content = '';
1064 if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) {
1065 $nametag = 'h3';
1066 } else {
1067 $nametag = 'div';
1069 $coursename = $chelper->get_course_formatted_name($course);
1070 $coursenamelink = html_writer::link(new moodle_url('/course/view.php', ['id' => $course->id]),
1071 $coursename, ['class' => $course->visible ? 'aalink' : 'aalink dimmed']);
1072 $content .= html_writer::tag($nametag, $coursenamelink, ['class' => 'coursename']);
1073 // If we display course in collapsed form but the course has summary or course contacts, display the link to the info page.
1074 $content .= html_writer::start_tag('div', ['class' => 'moreinfo']);
1075 if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
1076 if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles()
1077 || $course->has_custom_fields()) {
1078 $url = new moodle_url('/course/info.php', ['id' => $course->id]);
1079 $image = $this->output->pix_icon('i/info', $this->strings->summary);
1080 $content .= html_writer::link($url, $image, ['title' => $this->strings->summary]);
1081 // Make sure JS file to expand course content is included.
1082 $this->coursecat_include_js();
1085 $content .= html_writer::end_tag('div');
1086 return $content;
1090 * Returns HTML to display course enrolment icons.
1092 * @param core_course_list_element $course
1093 * @return string
1095 protected function course_enrolment_icons(core_course_list_element $course): string {
1096 $content = '';
1097 if ($icons = enrol_get_course_info_icons($course)) {
1098 $content .= html_writer::start_tag('div', ['class' => 'enrolmenticons']);
1099 foreach ($icons as $icon) {
1100 $content .= $this->render($icon);
1102 $content .= html_writer::end_tag('div');
1104 return $content;
1108 * Displays one course in the list of courses.
1110 * This is an internal function, to display an information about just one course
1111 * please use {@link core_course_renderer::course_info_box()}
1113 * @param coursecat_helper $chelper various display options
1114 * @param core_course_list_element|stdClass $course
1115 * @param string $additionalclasses additional classes to add to the main <div> tag (usually
1116 * depend on the course position in list - first/last/even/odd)
1117 * @return string
1119 protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
1120 if (!isset($this->strings->summary)) {
1121 $this->strings->summary = get_string('summary');
1123 if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) {
1124 return '';
1126 if ($course instanceof stdClass) {
1127 $course = new core_course_list_element($course);
1129 $content = '';
1130 $classes = trim('coursebox clearfix '. $additionalclasses);
1131 if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
1132 $classes .= ' collapsed';
1135 // .coursebox
1136 $content .= html_writer::start_tag('div', array(
1137 'class' => $classes,
1138 'data-courseid' => $course->id,
1139 'data-type' => self::COURSECAT_TYPE_COURSE,
1142 $content .= html_writer::start_tag('div', array('class' => 'info'));
1143 $content .= $this->course_name($chelper, $course);
1144 $content .= $this->course_enrolment_icons($course);
1145 $content .= html_writer::end_tag('div');
1147 $content .= html_writer::start_tag('div', array('class' => 'content'));
1148 $content .= $this->coursecat_coursebox_content($chelper, $course);
1149 $content .= html_writer::end_tag('div');
1151 $content .= html_writer::end_tag('div'); // .coursebox
1152 return $content;
1156 * Returns HTML to display course summary.
1158 * @param coursecat_helper $chelper
1159 * @param core_course_list_element $course
1160 * @return string
1162 protected function course_summary(coursecat_helper $chelper, core_course_list_element $course): string {
1163 $content = '';
1164 if ($course->has_summary()) {
1165 $content .= html_writer::start_tag('div', ['class' => 'summary']);
1166 $content .= $chelper->get_course_formatted_summary($course,
1167 array('overflowdiv' => true, 'noclean' => true, 'para' => false));
1168 $content .= html_writer::end_tag('div');
1170 return $content;
1174 * Returns HTML to display course contacts.
1176 * @param core_course_list_element $course
1177 * @return string
1179 protected function course_contacts(core_course_list_element $course) {
1180 $content = '';
1181 if ($course->has_course_contacts()) {
1182 $content .= html_writer::start_tag('ul', ['class' => 'teachers']);
1183 foreach ($course->get_course_contacts() as $coursecontact) {
1184 $rolenames = array_map(function ($role) {
1185 return $role->displayname;
1186 }, $coursecontact['roles']);
1187 $name = html_writer::tag('span', implode(", ", $rolenames).': ', ['class' => 'font-weight-bold']);
1188 $name .= html_writer::link(new moodle_url('/user/view.php',
1189 ['id' => $coursecontact['user']->id, 'course' => SITEID]),
1190 $coursecontact['username']);
1191 $content .= html_writer::tag('li', $name);
1193 $content .= html_writer::end_tag('ul');
1195 return $content;
1199 * Returns HTML to display course overview files.
1201 * @param core_course_list_element $course
1202 * @return string
1204 protected function course_overview_files(core_course_list_element $course): string {
1205 global $CFG;
1207 $contentimages = $contentfiles = '';
1208 foreach ($course->get_course_overviewfiles() as $file) {
1209 $isimage = $file->is_valid_image();
1210 $url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
1211 '/' . $file->get_contextid() . '/' . $file->get_component() . '/' .
1212 $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
1213 if ($isimage) {
1214 $contentimages .= html_writer::tag('div',
1215 html_writer::empty_tag('img', ['src' => $url]),
1216 ['class' => 'courseimage']);
1217 } else {
1218 $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
1219 $filename = html_writer::tag('span', $image, ['class' => 'fp-icon']).
1220 html_writer::tag('span', $file->get_filename(), ['class' => 'fp-filename']);
1221 $contentfiles .= html_writer::tag('span',
1222 html_writer::link($url, $filename),
1223 ['class' => 'coursefile fp-filename-icon']);
1226 return $contentimages . $contentfiles;
1230 * Returns HTML to display course category name.
1232 * @param coursecat_helper $chelper
1233 * @param core_course_list_element $course
1234 * @return string
1236 protected function course_category_name(coursecat_helper $chelper, core_course_list_element $course): string {
1237 $content = '';
1238 // Display course category if necessary (for example in search results).
1239 if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
1240 if ($cat = core_course_category::get($course->category, IGNORE_MISSING)) {
1241 $content .= html_writer::start_tag('div', ['class' => 'coursecat']);
1242 $content .= html_writer::tag('span', get_string('category').': ', ['class' => 'font-weight-bold']);
1243 $content .= html_writer::link(new moodle_url('/course/index.php', ['categoryid' => $cat->id]),
1244 $cat->get_formatted_name(), ['class' => $cat->visible ? '' : 'dimmed']);
1245 $content .= html_writer::end_tag('div');
1248 return $content;
1252 * Returns HTML to display course custom fields.
1254 * @param core_course_list_element $course
1255 * @return string
1257 protected function course_custom_fields(core_course_list_element $course): string {
1258 $content = '';
1259 if ($course->has_custom_fields()) {
1260 $handler = core_course\customfield\course_handler::create();
1261 $customfields = $handler->display_custom_fields_data($course->get_custom_fields());
1262 $content .= \html_writer::tag('div', $customfields, ['class' => 'customfields-container']);
1264 return $content;
1268 * Returns HTML to display course content (summary, course contacts and optionally category name)
1270 * This method is called from coursecat_coursebox() and may be re-used in AJAX
1272 * @param coursecat_helper $chelper various display options
1273 * @param stdClass|core_course_list_element $course
1274 * @return string
1276 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) {
1277 if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
1278 return '';
1280 if ($course instanceof stdClass) {
1281 $course = new core_course_list_element($course);
1283 $content = \html_writer::start_tag('div', ['class' => 'd-flex']);
1284 $content .= $this->course_overview_files($course);
1285 $content .= \html_writer::start_tag('div', ['class' => 'flex-grow-1']);
1286 $content .= $this->course_summary($chelper, $course);
1287 $content .= $this->course_contacts($course);
1288 $content .= $this->course_category_name($chelper, $course);
1289 $content .= $this->course_custom_fields($course);
1290 $content .= \html_writer::end_tag('div');
1291 $content .= \html_writer::end_tag('div');
1292 return $content;
1296 * Renders the list of courses
1298 * This is internal function, please use {@link core_course_renderer::courses_list()} or another public
1299 * method from outside of the class
1301 * If list of courses is specified in $courses; the argument $chelper is only used
1302 * to retrieve display options and attributes, only methods get_show_courses(),
1303 * get_courses_display_option() and get_and_erase_attributes() are called.
1305 * @param coursecat_helper $chelper various display options
1306 * @param array $courses the list of courses to display
1307 * @param int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable),
1308 * defaulted to count($courses)
1309 * @return string
1311 protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) {
1312 global $CFG;
1313 if ($totalcount === null) {
1314 $totalcount = count($courses);
1316 if (!$totalcount) {
1317 // Courses count is cached during courses retrieval.
1318 return '';
1321 if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) {
1322 // In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit
1323 if ($totalcount <= $CFG->courseswithsummarieslimit) {
1324 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
1325 } else {
1326 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
1330 // prepare content of paging bar if it is needed
1331 $paginationurl = $chelper->get_courses_display_option('paginationurl');
1332 $paginationallowall = $chelper->get_courses_display_option('paginationallowall');
1333 if ($totalcount > count($courses)) {
1334 // there are more results that can fit on one page
1335 if ($paginationurl) {
1336 // the option paginationurl was specified, display pagingbar
1337 $perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage);
1338 $page = $chelper->get_courses_display_option('offset') / $perpage;
1339 $pagingbar = $this->paging_bar($totalcount, $page, $perpage,
1340 $paginationurl->out(false, array('perpage' => $perpage)));
1341 if ($paginationallowall) {
1342 $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')),
1343 get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
1345 } else if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) {
1346 // the option for 'View more' link was specified, display more link
1347 $viewmoretext = $chelper->get_courses_display_option('viewmoretext', new lang_string('viewmore'));
1348 $morelink = html_writer::tag(
1349 'div',
1350 html_writer::link($viewmoreurl, $viewmoretext, ['class' => 'btn btn-secondary']),
1351 ['class' => 'paging paging-morelink']
1354 } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
1355 // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
1356 $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
1357 get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
1360 // display list of courses
1361 $attributes = $chelper->get_and_erase_attributes('courses');
1362 $content = html_writer::start_tag('div', $attributes);
1364 if (!empty($pagingbar)) {
1365 $content .= $pagingbar;
1368 $coursecount = 0;
1369 foreach ($courses as $course) {
1370 $coursecount ++;
1371 $classes = ($coursecount%2) ? 'odd' : 'even';
1372 if ($coursecount == 1) {
1373 $classes .= ' first';
1375 if ($coursecount >= count($courses)) {
1376 $classes .= ' last';
1378 $content .= $this->coursecat_coursebox($chelper, $course, $classes);
1381 if (!empty($pagingbar)) {
1382 $content .= $pagingbar;
1384 if (!empty($morelink)) {
1385 $content .= $morelink;
1388 $content .= html_writer::end_tag('div'); // .courses
1389 return $content;
1393 * Renders the list of subcategories in a category
1395 * @param coursecat_helper $chelper various display options
1396 * @param core_course_category $coursecat
1397 * @param int $depth depth of the category in the current tree
1398 * @return string
1400 protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth) {
1401 global $CFG;
1402 $subcategories = array();
1403 if (!$chelper->get_categories_display_option('nodisplay')) {
1404 $subcategories = $coursecat->get_children($chelper->get_categories_display_options());
1406 $totalcount = $coursecat->get_children_count();
1407 if (!$totalcount) {
1408 // Note that we call core_course_category::get_children_count() AFTER core_course_category::get_children()
1409 // to avoid extra DB requests.
1410 // Categories count is cached during children categories retrieval.
1411 return '';
1414 // prepare content of paging bar or more link if it is needed
1415 $paginationurl = $chelper->get_categories_display_option('paginationurl');
1416 $paginationallowall = $chelper->get_categories_display_option('paginationallowall');
1417 if ($totalcount > count($subcategories)) {
1418 if ($paginationurl) {
1419 // the option 'paginationurl was specified, display pagingbar
1420 $perpage = $chelper->get_categories_display_option('limit', $CFG->coursesperpage);
1421 $page = $chelper->get_categories_display_option('offset') / $perpage;
1422 $pagingbar = $this->paging_bar($totalcount, $page, $perpage,
1423 $paginationurl->out(false, array('perpage' => $perpage)));
1424 if ($paginationallowall) {
1425 $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')),
1426 get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall'));
1428 } else if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) {
1429 // the option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id)
1430 if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
1431 $viewmoreurl->param('categoryid', $coursecat->id);
1433 $viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore'));
1434 $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext),
1435 array('class' => 'paging paging-morelink'));
1437 } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
1438 // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode
1439 $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
1440 get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage'));
1443 // display list of subcategories
1444 $content = html_writer::start_tag('div', array('class' => 'subcategories'));
1446 if (!empty($pagingbar)) {
1447 $content .= $pagingbar;
1450 foreach ($subcategories as $subcategory) {
1451 $content .= $this->coursecat_category($chelper, $subcategory, $depth + 1);
1454 if (!empty($pagingbar)) {
1455 $content .= $pagingbar;
1457 if (!empty($morelink)) {
1458 $content .= $morelink;
1461 $content .= html_writer::end_tag('div');
1462 return $content;
1466 * Make sure that javascript file for AJAX expanding of courses and categories content is included
1468 protected function coursecat_include_js() {
1469 if (!$this->page->requires->should_create_one_time_item_now('core_course_categoryexpanderjsinit')) {
1470 return;
1473 // We must only load this module once.
1474 $this->page->requires->yui_module('moodle-course-categoryexpander',
1475 'Y.Moodle.course.categoryexpander.init');
1479 * Returns HTML to display the subcategories and courses in the given category
1481 * This method is re-used by AJAX to expand content of not loaded category
1483 * @param coursecat_helper $chelper various display options
1484 * @param core_course_category $coursecat
1485 * @param int $depth depth of the category in the current tree
1486 * @return string
1488 protected function coursecat_category_content(coursecat_helper $chelper, $coursecat, $depth) {
1489 $content = '';
1490 // Subcategories
1491 $content .= $this->coursecat_subcategories($chelper, $coursecat, $depth);
1493 // AUTO show courses: Courses will be shown expanded if this is not nested category,
1494 // and number of courses no bigger than $CFG->courseswithsummarieslimit.
1495 $showcoursesauto = $chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO;
1496 if ($showcoursesauto && $depth) {
1497 // this is definitely collapsed mode
1498 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
1501 // Courses
1502 if ($chelper->get_show_courses() > core_course_renderer::COURSECAT_SHOW_COURSES_COUNT) {
1503 $courses = array();
1504 if (!$chelper->get_courses_display_option('nodisplay')) {
1505 $courses = $coursecat->get_courses($chelper->get_courses_display_options());
1507 if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) {
1508 // the option for 'View more' link was specified, display more link (if it is link to category view page, add category id)
1509 if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
1510 $chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('categoryid' => $coursecat->id)));
1513 $content .= $this->coursecat_courses($chelper, $courses, $coursecat->get_courses_count());
1516 if ($showcoursesauto) {
1517 // restore the show_courses back to AUTO
1518 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO);
1521 return $content;
1525 * Returns HTML to display a course category as a part of a tree
1527 * This is an internal function, to display a particular category and all its contents
1528 * use {@link core_course_renderer::course_category()}
1530 * @param coursecat_helper $chelper various display options
1531 * @param core_course_category $coursecat
1532 * @param int $depth depth of this category in the current tree
1533 * @return string
1535 protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) {
1536 // open category tag
1537 $classes = array('category');
1538 if (empty($coursecat->visible)) {
1539 $classes[] = 'dimmed_category';
1541 if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {
1542 // do not load content
1543 $categorycontent = '';
1544 $classes[] = 'notloaded';
1545 if ($coursecat->get_children_count() ||
1546 ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_COLLAPSED && $coursecat->get_courses_count())) {
1547 $classes[] = 'with_children';
1548 $classes[] = 'collapsed';
1550 } else {
1551 // load category content
1552 $categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth);
1553 $classes[] = 'loaded';
1554 if (!empty($categorycontent)) {
1555 $classes[] = 'with_children';
1556 // Category content loaded with children.
1557 $this->categoryexpandedonload = true;
1561 // Make sure JS file to expand category content is included.
1562 $this->coursecat_include_js();
1564 $content = html_writer::start_tag('div', array(
1565 'class' => join(' ', $classes),
1566 'data-categoryid' => $coursecat->id,
1567 'data-depth' => $depth,
1568 'data-showcourses' => $chelper->get_show_courses(),
1569 'data-type' => self::COURSECAT_TYPE_CATEGORY,
1572 // category name
1573 $categoryname = $coursecat->get_formatted_name();
1574 $categoryname = html_writer::link(new moodle_url('/course/index.php',
1575 array('categoryid' => $coursecat->id)),
1576 $categoryname);
1577 if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT
1578 && ($coursescount = $coursecat->get_courses_count())) {
1579 $categoryname .= html_writer::tag('span', ' ('. $coursescount.')',
1580 array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse'));
1582 $content .= html_writer::start_tag('div', array('class' => 'info'));
1584 $content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname aabtn'));
1585 $content .= html_writer::end_tag('div'); // .info
1587 // add category content to the output
1588 $content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
1590 $content .= html_writer::end_tag('div'); // .category
1592 // Return the course category tree HTML
1593 return $content;
1597 * Returns HTML to display a tree of subcategories and courses in the given category
1599 * @param coursecat_helper $chelper various display options
1600 * @param core_course_category $coursecat top category (this category's name and description will NOT be added to the tree)
1601 * @return string
1603 protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
1604 // Reset the category expanded flag for this course category tree first.
1605 $this->categoryexpandedonload = false;
1606 $categorycontent = $this->coursecat_category_content($chelper, $coursecat, 0);
1607 if (empty($categorycontent)) {
1608 return '';
1611 // Start content generation
1612 $content = '';
1613 $attributes = $chelper->get_and_erase_attributes('course_category_tree clearfix');
1614 $content .= html_writer::start_tag('div', $attributes);
1616 if ($coursecat->get_children_count()) {
1617 $classes = array(
1618 'collapseexpand', 'aabtn'
1621 // Check if the category content contains subcategories with children's content loaded.
1622 if ($this->categoryexpandedonload) {
1623 $classes[] = 'collapse-all';
1624 $linkname = get_string('collapseall');
1625 } else {
1626 $linkname = get_string('expandall');
1629 // Only show the collapse/expand if there are children to expand.
1630 $content .= html_writer::start_tag('div', array('class' => 'collapsible-actions'));
1631 $content .= html_writer::link('#', $linkname, array('class' => implode(' ', $classes)));
1632 $content .= html_writer::end_tag('div');
1633 $this->page->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle');
1636 $content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
1638 $content .= html_writer::end_tag('div'); // .course_category_tree
1640 return $content;
1644 * Renders HTML to display particular course category - list of it's subcategories and courses
1646 * Invoked from /course/index.php
1648 * @param int|stdClass|core_course_category $category
1650 public function course_category($category) {
1651 global $CFG;
1652 $usertop = core_course_category::user_top();
1653 if (empty($category)) {
1654 $coursecat = $usertop;
1655 } else if (is_object($category) && $category instanceof core_course_category) {
1656 $coursecat = $category;
1657 } else {
1658 $coursecat = core_course_category::get(is_object($category) ? $category->id : $category);
1660 $site = get_site();
1661 $actionbar = new \core_course\output\category_action_bar($this->page, $coursecat);
1662 $output = $this->render_from_template('core_course/category_actionbar', $actionbar->export_for_template($this));
1664 if (core_course_category::is_simple_site()) {
1665 // There is only one category in the system, do not display link to it.
1666 $strfulllistofcourses = get_string('fulllistofcourses');
1667 $this->page->set_title("$site->shortname: $strfulllistofcourses");
1668 } else if (!$coursecat->id || !$coursecat->is_uservisible()) {
1669 $strcategories = get_string('categories');
1670 $this->page->set_title("$site->shortname: $strcategories");
1671 } else {
1672 $strfulllistofcourses = get_string('fulllistofcourses');
1673 $this->page->set_title("$site->shortname: $strfulllistofcourses");
1676 // Print current category description
1677 $chelper = new coursecat_helper();
1678 if ($description = $chelper->get_category_formatted_description($coursecat)) {
1679 $output .= $this->box($description, array('class' => 'generalbox info'));
1682 // Prepare parameters for courses and categories lists in the tree
1683 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO)
1684 ->set_attributes(array('class' => 'category-browse category-browse-'.$coursecat->id));
1686 $coursedisplayoptions = array();
1687 $catdisplayoptions = array();
1688 $browse = optional_param('browse', null, PARAM_ALPHA);
1689 $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT);
1690 $page = optional_param('page', 0, PARAM_INT);
1691 $baseurl = new moodle_url('/course/index.php');
1692 if ($coursecat->id) {
1693 $baseurl->param('categoryid', $coursecat->id);
1695 if ($perpage != $CFG->coursesperpage) {
1696 $baseurl->param('perpage', $perpage);
1698 $coursedisplayoptions['limit'] = $perpage;
1699 $catdisplayoptions['limit'] = $perpage;
1700 if ($browse === 'courses' || !$coursecat->get_children_count()) {
1701 $coursedisplayoptions['offset'] = $page * $perpage;
1702 $coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses'));
1703 $catdisplayoptions['nodisplay'] = true;
1704 $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories'));
1705 $catdisplayoptions['viewmoretext'] = new lang_string('viewallsubcategories');
1706 } else if ($browse === 'categories' || !$coursecat->get_courses_count()) {
1707 $coursedisplayoptions['nodisplay'] = true;
1708 $catdisplayoptions['offset'] = $page * $perpage;
1709 $catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories'));
1710 $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses'));
1711 $coursedisplayoptions['viewmoretext'] = new lang_string('viewallcourses');
1712 } else {
1713 // we have a category that has both subcategories and courses, display pagination separately
1714 $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1));
1715 $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1));
1717 $chelper->set_courses_display_options($coursedisplayoptions)->set_categories_display_options($catdisplayoptions);
1719 // Display course category tree.
1720 $output .= $this->coursecat_tree($chelper, $coursecat);
1722 return $output;
1726 * Serves requests to /course/category.ajax.php
1728 * In this renderer implementation it may expand the category content or
1729 * course content.
1731 * @return string
1732 * @throws coding_exception
1734 public function coursecat_ajax() {
1735 global $DB, $CFG;
1737 $type = required_param('type', PARAM_INT);
1739 if ($type === self::COURSECAT_TYPE_CATEGORY) {
1740 // This is a request for a category list of some kind.
1741 $categoryid = required_param('categoryid', PARAM_INT);
1742 $showcourses = required_param('showcourses', PARAM_INT);
1743 $depth = required_param('depth', PARAM_INT);
1745 $category = core_course_category::get($categoryid);
1747 $chelper = new coursecat_helper();
1748 $baseurl = new moodle_url('/course/index.php', array('categoryid' => $categoryid));
1749 $coursedisplayoptions = array(
1750 'limit' => $CFG->coursesperpage,
1751 'viewmoreurl' => new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1))
1753 $catdisplayoptions = array(
1754 'limit' => $CFG->coursesperpage,
1755 'viewmoreurl' => new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1))
1757 $chelper->set_show_courses($showcourses)->
1758 set_courses_display_options($coursedisplayoptions)->
1759 set_categories_display_options($catdisplayoptions);
1761 return $this->coursecat_category_content($chelper, $category, $depth);
1762 } else if ($type === self::COURSECAT_TYPE_COURSE) {
1763 // This is a request for the course information.
1764 $courseid = required_param('courseid', PARAM_INT);
1766 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
1768 $chelper = new coursecat_helper();
1769 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
1770 return $this->coursecat_coursebox_content($chelper, $course);
1771 } else {
1772 throw new coding_exception('Invalid request type');
1777 * Renders html to display search result page
1779 * @param array $searchcriteria may contain elements: search, blocklist, modulelist, tagid
1780 * @return string
1782 public function search_courses($searchcriteria) {
1783 global $CFG;
1784 $content = '';
1786 $search = '';
1787 if (!empty($searchcriteria['search'])) {
1788 $search = $searchcriteria['search'];
1790 $content .= $this->course_search_form($search);
1792 if (!empty($searchcriteria)) {
1793 // print search results
1795 $displayoptions = array('sort' => array('displayname' => 1));
1796 // take the current page and number of results per page from query
1797 $perpage = optional_param('perpage', 0, PARAM_RAW);
1798 if ($perpage !== 'all') {
1799 $displayoptions['limit'] = ((int)$perpage <= 0) ? $CFG->coursesperpage : (int)$perpage;
1800 $page = optional_param('page', 0, PARAM_INT);
1801 $displayoptions['offset'] = $displayoptions['limit'] * $page;
1803 // options 'paginationurl' and 'paginationallowall' are only used in method coursecat_courses()
1804 $displayoptions['paginationurl'] = new moodle_url('/course/search.php', $searchcriteria);
1805 $displayoptions['paginationallowall'] = true; // allow adding link 'View all'
1807 $class = 'course-search-result';
1808 foreach ($searchcriteria as $key => $value) {
1809 if (!empty($value)) {
1810 $class .= ' course-search-result-'. $key;
1813 $chelper = new coursecat_helper();
1814 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT)->
1815 set_courses_display_options($displayoptions)->
1816 set_search_criteria($searchcriteria)->
1817 set_attributes(array('class' => $class));
1819 $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
1820 $totalcount = core_course_category::search_courses_count($searchcriteria);
1821 $courseslist = $this->coursecat_courses($chelper, $courses, $totalcount);
1823 if (!$totalcount) {
1824 if (!empty($searchcriteria['search'])) {
1825 $content .= $this->heading(get_string('nocoursesfound', '', $searchcriteria['search']));
1826 } else {
1827 $content .= $this->heading(get_string('novalidcourses'));
1829 } else {
1830 $content .= $this->heading(get_string('searchresults'). ": $totalcount");
1831 $content .= $courseslist;
1834 return $content;
1838 * Renders html to print list of courses tagged with particular tag
1840 * @param int $tagid id of the tag
1841 * @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
1842 * are displayed on the page and the per-page limit may be bigger
1843 * @param int $fromctx context id where the link was displayed, may be used by callbacks
1844 * to display items in the same context first
1845 * @param int $ctx context id where to search for records
1846 * @param bool $rec search in subcontexts as well
1847 * @param array $displayoptions
1848 * @return string empty string if no courses are marked with this tag or rendered list of courses
1850 public function tagged_courses($tagid, $exclusivemode = true, $ctx = 0, $rec = true, $displayoptions = null) {
1851 global $CFG;
1852 if (empty($displayoptions)) {
1853 $displayoptions = array();
1855 $showcategories = !core_course_category::is_simple_site();
1856 $displayoptions += array('limit' => $CFG->coursesperpage, 'offset' => 0);
1857 $chelper = new coursecat_helper();
1858 $searchcriteria = array('tagid' => $tagid, 'ctx' => $ctx, 'rec' => $rec);
1859 $chelper->set_show_courses($showcategories ? self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT :
1860 self::COURSECAT_SHOW_COURSES_EXPANDED)->
1861 set_search_criteria($searchcriteria)->
1862 set_courses_display_options($displayoptions)->
1863 set_attributes(array('class' => 'course-search-result course-search-result-tagid'));
1864 // (we set the same css class as in search results by tagid)
1865 if ($totalcount = core_course_category::search_courses_count($searchcriteria)) {
1866 $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
1867 if ($exclusivemode) {
1868 return $this->coursecat_courses($chelper, $courses, $totalcount);
1869 } else {
1870 $tagfeed = new core_tag\output\tagfeed();
1871 $img = $this->output->pix_icon('i/course', '');
1872 foreach ($courses as $course) {
1873 $url = course_get_url($course);
1874 $imgwithlink = html_writer::link($url, $img);
1875 $coursename = html_writer::link($url, $course->get_formatted_name());
1876 $details = '';
1877 if ($showcategories && ($cat = core_course_category::get($course->category, IGNORE_MISSING))) {
1878 $details = get_string('category').': '.
1879 html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
1880 $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
1882 $tagfeed->add($imgwithlink, $coursename, $details);
1884 return $this->output->render_from_template('core_tag/tagfeed', $tagfeed->export_for_template($this->output));
1887 return '';
1891 * Returns HTML to display one remote course
1893 * @param stdClass $course remote course information, contains properties:
1894 id, remoteid, shortname, fullname, hostid, summary, summaryformat, cat_name, hostname
1895 * @return string
1897 protected function frontpage_remote_course(stdClass $course) {
1898 $url = new moodle_url('/auth/mnet/jump.php', array(
1899 'hostid' => $course->hostid,
1900 'wantsurl' => '/course/view.php?id='. $course->remoteid
1903 $output = '';
1904 $output .= html_writer::start_tag('div', array('class' => 'coursebox remotecoursebox clearfix'));
1905 $output .= html_writer::start_tag('div', array('class' => 'info'));
1906 $output .= html_writer::start_tag('h3', array('class' => 'coursename'));
1907 $output .= html_writer::link($url, format_string($course->fullname), array('title' => get_string('entercourse')));
1908 $output .= html_writer::end_tag('h3'); // .name
1909 $output .= html_writer::tag('div', '', array('class' => 'moreinfo'));
1910 $output .= html_writer::end_tag('div'); // .info
1911 $output .= html_writer::start_tag('div', array('class' => 'content'));
1912 $output .= html_writer::start_tag('div', array('class' => 'summary'));
1913 $options = new stdClass();
1914 $options->noclean = true;
1915 $options->para = false;
1916 $options->overflowdiv = true;
1917 $output .= format_text($course->summary, $course->summaryformat, $options);
1918 $output .= html_writer::end_tag('div'); // .summary
1919 $addinfo = format_string($course->hostname) . ' : '
1920 . format_string($course->cat_name) . ' : '
1921 . format_string($course->shortname);
1922 $output .= html_writer::tag('div', $addinfo, array('class' => 'remotecourseinfo'));
1923 $output .= html_writer::end_tag('div'); // .content
1924 $output .= html_writer::end_tag('div'); // .coursebox
1925 return $output;
1929 * Returns HTML to display one remote host
1931 * @param array $host host information, contains properties: name, url, count
1932 * @return string
1934 protected function frontpage_remote_host($host) {
1935 $output = '';
1936 $output .= html_writer::start_tag('div', array('class' => 'coursebox remotehost clearfix'));
1937 $output .= html_writer::start_tag('div', array('class' => 'info'));
1938 $output .= html_writer::start_tag('h3', array('class' => 'name'));
1939 $output .= html_writer::link($host['url'], s($host['name']), array('title' => s($host['name'])));
1940 $output .= html_writer::end_tag('h3'); // .name
1941 $output .= html_writer::tag('div', '', array('class' => 'moreinfo'));
1942 $output .= html_writer::end_tag('div'); // .info
1943 $output .= html_writer::start_tag('div', array('class' => 'content'));
1944 $output .= html_writer::start_tag('div', array('class' => 'summary'));
1945 $output .= $host['count'] . ' ' . get_string('courses');
1946 $output .= html_writer::end_tag('div'); // .content
1947 $output .= html_writer::end_tag('div'); // .coursebox
1948 return $output;
1952 * Returns HTML to print list of courses user is enrolled to for the frontpage
1954 * Also lists remote courses or remote hosts if MNET authorisation is used
1956 * @return string
1958 public function frontpage_my_courses() {
1959 global $USER, $CFG, $DB;
1961 if (!isloggedin() or isguestuser()) {
1962 return '';
1965 $output = '';
1966 $courses = enrol_get_my_courses('summary, summaryformat');
1967 $rhosts = array();
1968 $rcourses = array();
1969 if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') {
1970 $rcourses = get_my_remotecourses($USER->id);
1971 $rhosts = get_my_remotehosts();
1974 if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) {
1976 $chelper = new coursecat_helper();
1977 $totalcount = count($courses);
1978 if (count($courses) > $CFG->frontpagecourselimit) {
1979 // There are more enrolled courses than we can display, display link to 'My courses'.
1980 $courses = array_slice($courses, 0, $CFG->frontpagecourselimit, true);
1981 $chelper->set_courses_display_options(array(
1982 'viewmoreurl' => new moodle_url('/my/courses.php'),
1983 'viewmoretext' => new lang_string('mycourses')
1985 } else if (core_course_category::top()->is_uservisible()) {
1986 // All enrolled courses are displayed, display link to 'All courses' if there are more courses in system.
1987 $chelper->set_courses_display_options(array(
1988 'viewmoreurl' => new moodle_url('/course/index.php'),
1989 'viewmoretext' => new lang_string('fulllistofcourses')
1991 $totalcount = $DB->count_records('course') - 1;
1993 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->
1994 set_attributes(array('class' => 'frontpage-course-list-enrolled'));
1995 $output .= $this->coursecat_courses($chelper, $courses, $totalcount);
1997 // MNET
1998 if (!empty($rcourses)) {
1999 // at the IDP, we know of all the remote courses
2000 $output .= html_writer::start_tag('div', array('class' => 'courses'));
2001 foreach ($rcourses as $course) {
2002 $output .= $this->frontpage_remote_course($course);
2004 $output .= html_writer::end_tag('div'); // .courses
2005 } elseif (!empty($rhosts)) {
2006 // non-IDP, we know of all the remote servers, but not courses
2007 $output .= html_writer::start_tag('div', array('class' => 'courses'));
2008 foreach ($rhosts as $host) {
2009 $output .= $this->frontpage_remote_host($host);
2011 $output .= html_writer::end_tag('div'); // .courses
2014 return $output;
2018 * Returns HTML to print list of available courses for the frontpage
2020 * @return string
2022 public function frontpage_available_courses() {
2023 global $CFG;
2025 $chelper = new coursecat_helper();
2026 $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->
2027 set_courses_display_options(array(
2028 'recursive' => true,
2029 'limit' => $CFG->frontpagecourselimit,
2030 'viewmoreurl' => new moodle_url('/course/index.php'),
2031 'viewmoretext' => new lang_string('fulllistofcourses')));
2033 $chelper->set_attributes(array('class' => 'frontpage-course-list-all'));
2034 $courses = core_course_category::top()->get_courses($chelper->get_courses_display_options());
2035 $totalcount = core_course_category::top()->get_courses_count($chelper->get_courses_display_options());
2036 if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) {
2037 // Print link to create a new course, for the 1st available category.
2038 return $this->add_new_course_button();
2040 return $this->coursecat_courses($chelper, $courses, $totalcount);
2044 * Returns HTML to the "add new course" button for the page
2046 * @return string
2048 public function add_new_course_button() {
2049 global $CFG;
2050 // Print link to create a new course, for the 1st available category.
2051 $output = $this->container_start('buttons');
2052 $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat'));
2053 $output .= $this->single_button($url, get_string('addnewcourse'), 'get');
2054 $output .= $this->container_end('buttons');
2055 return $output;
2059 * Returns HTML to print tree with course categories and courses for the frontpage
2061 * @return string
2063 public function frontpage_combo_list() {
2064 global $CFG;
2065 // TODO MDL-10965 improve.
2066 $tree = core_course_category::top();
2067 if (!$tree->get_children_count()) {
2068 return '';
2070 $chelper = new coursecat_helper();
2071 $chelper->set_subcat_depth($CFG->maxcategorydepth)->
2072 set_categories_display_options(array(
2073 'limit' => $CFG->coursesperpage,
2074 'viewmoreurl' => new moodle_url('/course/index.php',
2075 array('browse' => 'categories', 'page' => 1))
2076 ))->
2077 set_courses_display_options(array(
2078 'limit' => $CFG->coursesperpage,
2079 'viewmoreurl' => new moodle_url('/course/index.php',
2080 array('browse' => 'courses', 'page' => 1))
2081 ))->
2082 set_attributes(array('class' => 'frontpage-category-combo'));
2083 return $this->coursecat_tree($chelper, $tree);
2087 * Returns HTML to print tree of course categories (with number of courses) for the frontpage
2089 * @return string
2091 public function frontpage_categories_list() {
2092 global $CFG;
2093 // TODO MDL-10965 improve.
2094 $tree = core_course_category::top();
2095 if (!$tree->get_children_count()) {
2096 return '';
2098 $chelper = new coursecat_helper();
2099 $chelper->set_subcat_depth($CFG->maxcategorydepth)->
2100 set_show_courses(self::COURSECAT_SHOW_COURSES_COUNT)->
2101 set_categories_display_options(array(
2102 'limit' => $CFG->coursesperpage,
2103 'viewmoreurl' => new moodle_url('/course/index.php',
2104 array('browse' => 'categories', 'page' => 1))
2105 ))->
2106 set_attributes(array('class' => 'frontpage-category-names'));
2107 return $this->coursecat_tree($chelper, $tree);
2111 * Renders the activity information.
2113 * Defer to template.
2115 * @param \core_course\output\activity_information $page
2116 * @return string html for the page
2118 public function render_activity_information(\core_course\output\activity_information $page) {
2119 $data = $page->export_for_template($this->output);
2120 return $this->output->render_from_template('core_course/activity_info', $data);
2124 * Renders the activity navigation.
2126 * Defer to template.
2128 * @param \core_course\output\activity_navigation $page
2129 * @return string html for the page
2131 public function render_activity_navigation(\core_course\output\activity_navigation $page) {
2132 $data = $page->export_for_template($this->output);
2133 return $this->output->render_from_template('core_course/activity_navigation', $data);
2137 * Display waiting information about backup size during uploading backup process
2138 * @param object $backupfile the backup stored_file
2139 * @return $html string
2141 public function sendingbackupinfo($backupfile) {
2142 $sizeinfo = new stdClass();
2143 $sizeinfo->total = number_format($backupfile->get_filesize() / 1000000, 2);
2144 $html = html_writer::tag('div', get_string('sendingsize', 'hub', $sizeinfo),
2145 array('class' => 'courseuploadtextinfo'));
2146 return $html;
2150 * Hub information (logo - name - description - link)
2151 * @param object $hubinfo
2152 * @return string html code
2154 public function hubinfo($hubinfo) {
2155 $screenshothtml = html_writer::empty_tag('img',
2156 array('src' => $hubinfo['imgurl'], 'alt' => $hubinfo['name']));
2157 $hubdescription = html_writer::tag('div', $screenshothtml,
2158 array('class' => 'hubscreenshot'));
2160 $hubdescription .= html_writer::tag('a', $hubinfo['name'],
2161 array('class' => 'hublink', 'href' => $hubinfo['url'],
2162 'onclick' => 'this.target="_blank"'));
2164 $hubdescription .= html_writer::tag('div', format_text($hubinfo['description'], FORMAT_PLAIN),
2165 array('class' => 'hubdescription'));
2166 $hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo clearfix'));
2168 return $hubdescription;
2172 * Output frontpage summary text and frontpage modules (stored as section 1 in site course)
2174 * This may be disabled in settings
2176 * @return string
2178 public function frontpage_section1() {
2179 global $SITE, $USER;
2181 $output = '';
2182 $editing = $this->page->user_is_editing();
2184 if ($editing) {
2185 // Make sure section with number 1 exists.
2186 course_create_sections_if_missing($SITE, 1);
2189 $modinfo = get_fast_modinfo($SITE);
2190 $section = $modinfo->get_section_info(1);
2193 if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
2195 $format = course_get_format($SITE);
2196 $frontpageclass = $format->get_output_classname('content\\frontpagesection');
2197 $frontpagesection = new $frontpageclass($format, $section);
2199 // The course outputs works with format renderers, not with course renderers.
2200 $renderer = $format->get_renderer($this->page);
2201 $output .= $renderer->render($frontpagesection);
2204 return $output;
2208 * Output news for the frontpage (extract from site-wide news forum)
2210 * @param stdClass $forum record from db table 'forum' that represents the site news forum
2211 * @return string
2213 protected function frontpage_news($forum) {
2214 global $CFG, $SITE, $SESSION, $USER;
2215 require_once($CFG->dirroot .'/mod/forum/lib.php');
2217 $output = '';
2219 if (isloggedin()) {
2220 $SESSION->fromdiscussion = $CFG->wwwroot;
2221 $subtext = '';
2222 if (\mod_forum\subscriptions::is_subscribed($USER->id, $forum)) {
2223 if (!\mod_forum\subscriptions::is_forcesubscribed($forum)) {
2224 $subtext = get_string('unsubscribe', 'forum');
2226 } else {
2227 $subtext = get_string('subscribe', 'forum');
2229 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $forum->id, 'sesskey' => sesskey()));
2230 $output .= html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
2233 $coursemodule = get_coursemodule_from_instance('forum', $forum->id);
2234 $context = context_module::instance($coursemodule->id);
2236 $entityfactory = mod_forum\local\container::get_entity_factory();
2237 $forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $SITE);
2239 $rendererfactory = mod_forum\local\container::get_renderer_factory();
2240 $discussionsrenderer = $rendererfactory->get_frontpage_news_discussion_list_renderer($forumentity);
2241 $cm = \cm_info::create($coursemodule);
2242 return $output . $discussionsrenderer->render($USER, $cm, null, null, 0, $SITE->newsitems);
2246 * Renders part of frontpage with a skip link (i.e. "My courses", "Site news", etc.)
2248 * @param string $skipdivid
2249 * @param string $contentsdivid
2250 * @param string $header Header of the part
2251 * @param string $contents Contents of the part
2252 * @return string
2254 protected function frontpage_part($skipdivid, $contentsdivid, $header, $contents) {
2255 if (strval($contents) === '') {
2256 return '';
2258 $output = html_writer::link('#' . $skipdivid,
2259 get_string('skipa', 'access', core_text::strtolower(strip_tags($header))),
2260 array('class' => 'skip-block skip aabtn'));
2262 // Wrap frontpage part in div container.
2263 $output .= html_writer::start_tag('div', array('id' => $contentsdivid));
2264 $output .= $this->heading($header);
2266 $output .= $contents;
2268 // End frontpage part div container.
2269 $output .= html_writer::end_tag('div');
2271 $output .= html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => $skipdivid));
2272 return $output;
2276 * Outputs contents for frontpage as configured in $CFG->frontpage or $CFG->frontpageloggedin
2278 * @return string
2280 public function frontpage() {
2281 global $CFG, $SITE;
2283 $output = '';
2285 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
2286 $frontpagelayout = $CFG->frontpageloggedin;
2287 } else {
2288 $frontpagelayout = $CFG->frontpage;
2291 foreach (explode(',', $frontpagelayout) as $v) {
2292 switch ($v) {
2293 // Display the main part of the front page.
2294 case FRONTPAGENEWS:
2295 if ($SITE->newsitems) {
2296 // Print forums only when needed.
2297 require_once($CFG->dirroot .'/mod/forum/lib.php');
2298 if (($newsforum = forum_get_course_forum($SITE->id, 'news')) &&
2299 ($forumcontents = $this->frontpage_news($newsforum))) {
2300 $newsforumcm = get_fast_modinfo($SITE)->instances['forum'][$newsforum->id];
2301 $output .= $this->frontpage_part('skipsitenews', 'site-news-forum',
2302 $newsforumcm->get_formatted_name(), $forumcontents);
2305 break;
2307 case FRONTPAGEENROLLEDCOURSELIST:
2308 $mycourseshtml = $this->frontpage_my_courses();
2309 if (!empty($mycourseshtml)) {
2310 $output .= $this->frontpage_part('skipmycourses', 'frontpage-course-list',
2311 get_string('mycourses'), $mycourseshtml);
2313 break;
2315 case FRONTPAGEALLCOURSELIST:
2316 $availablecourseshtml = $this->frontpage_available_courses();
2317 $output .= $this->frontpage_part('skipavailablecourses', 'frontpage-available-course-list',
2318 get_string('availablecourses'), $availablecourseshtml);
2319 break;
2321 case FRONTPAGECATEGORYNAMES:
2322 $output .= $this->frontpage_part('skipcategories', 'frontpage-category-names',
2323 get_string('categories'), $this->frontpage_categories_list());
2324 break;
2326 case FRONTPAGECATEGORYCOMBO:
2327 $output .= $this->frontpage_part('skipcourses', 'frontpage-category-combo',
2328 get_string('courses'), $this->frontpage_combo_list());
2329 break;
2331 case FRONTPAGECOURSESEARCH:
2332 $output .= $this->box($this->course_search_form(''), 'd-flex justify-content-center');
2333 break;
2336 $output .= '<br />';
2339 return $output;
2344 * Class storing display options and functions to help display course category and/or courses lists
2346 * This is a wrapper for core_course_category objects that also stores display options
2347 * and functions to retrieve sorted and paginated lists of categories/courses.
2349 * If theme overrides methods in core_course_renderers that access this class
2350 * it may as well not use this class at all or extend it.
2352 * @package core
2353 * @copyright 2013 Marina Glancy
2354 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2356 class coursecat_helper {
2357 /** @var string [none, collapsed, expanded] how (if) display courses list */
2358 protected $showcourses = 10; /* core_course_renderer::COURSECAT_SHOW_COURSES_COLLAPSED */
2359 /** @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) */
2360 protected $subcatdepth = 1;
2361 /** @var array options to display courses list */
2362 protected $coursesdisplayoptions = array();
2363 /** @var array options to display subcategories list */
2364 protected $categoriesdisplayoptions = array();
2365 /** @var array additional HTML attributes */
2366 protected $attributes = array();
2367 /** @var array search criteria if the list is a search result */
2368 protected $searchcriteria = null;
2371 * Sets how (if) to show the courses - none, collapsed, expanded, etc.
2373 * @param int $showcourses SHOW_COURSES_NONE, SHOW_COURSES_COLLAPSED, SHOW_COURSES_EXPANDED, etc.
2374 * @return coursecat_helper
2376 public function set_show_courses($showcourses) {
2377 $this->showcourses = $showcourses;
2378 // Automatically set the options to preload summary and coursecontacts for core_course_category::get_courses()
2379 // and core_course_category::search_courses().
2380 $this->coursesdisplayoptions['summary'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_AUTO;
2381 $this->coursesdisplayoptions['coursecontacts'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_EXPANDED;
2382 $this->coursesdisplayoptions['customfields'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_COLLAPSED;
2383 return $this;
2387 * Returns how (if) to show the courses - none, collapsed, expanded, etc.
2389 * @return int - COURSECAT_SHOW_COURSES_NONE, COURSECAT_SHOW_COURSES_COLLAPSED, COURSECAT_SHOW_COURSES_EXPANDED, etc.
2391 public function get_show_courses() {
2392 return $this->showcourses;
2396 * Sets the maximum depth to expand subcategories in the tree
2398 * deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name
2400 * @param int $subcatdepth
2401 * @return coursecat_helper
2403 public function set_subcat_depth($subcatdepth) {
2404 $this->subcatdepth = $subcatdepth;
2405 return $this;
2409 * Returns the maximum depth to expand subcategories in the tree
2411 * deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name
2413 * @return int
2415 public function get_subcat_depth() {
2416 return $this->subcatdepth;
2420 * Sets options to display list of courses
2422 * Options are later submitted as argument to core_course_category::get_courses() and/or core_course_category::search_courses()
2424 * Options that core_course_category::get_courses() accept:
2425 * - recursive - return courses from subcategories as well. Use with care,
2426 * this may be a huge list!
2427 * - summary - preloads fields 'summary' and 'summaryformat'
2428 * - coursecontacts - preloads course contacts
2429 * - customfields - preloads custom fields data
2430 * - isenrolled - preloads indication whether this user is enrolled in the course
2431 * - sort - list of fields to sort. Example
2432 * array('idnumber' => 1, 'shortname' => 1, 'id' => -1)
2433 * will sort by idnumber asc, shortname asc and id desc.
2434 * Default: array('sortorder' => 1)
2435 * Only cached fields may be used for sorting!
2436 * - offset
2437 * - limit - maximum number of children to return, 0 or null for no limit
2439 * Options summary and coursecontacts are filled automatically in the set_show_courses()
2441 * Also renderer can set here any additional options it wants to pass between renderer functions.
2443 * @param array $options
2444 * @return coursecat_helper
2446 public function set_courses_display_options($options) {
2447 $this->coursesdisplayoptions = $options;
2448 $this->set_show_courses($this->showcourses); // this will calculate special display options
2449 return $this;
2453 * Sets one option to display list of courses
2455 * @see coursecat_helper::set_courses_display_options()
2457 * @param string $key
2458 * @param mixed $value
2459 * @return coursecat_helper
2461 public function set_courses_display_option($key, $value) {
2462 $this->coursesdisplayoptions[$key] = $value;
2463 return $this;
2467 * Return the specified option to display list of courses
2469 * @param string $optionname option name
2470 * @param mixed $defaultvalue default value for option if it is not specified
2471 * @return mixed
2473 public function get_courses_display_option($optionname, $defaultvalue = null) {
2474 if (array_key_exists($optionname, $this->coursesdisplayoptions)) {
2475 return $this->coursesdisplayoptions[$optionname];
2476 } else {
2477 return $defaultvalue;
2482 * Returns all options to display the courses
2484 * This array is usually passed to {@link core_course_category::get_courses()} or
2485 * {@link core_course_category::search_courses()}
2487 * @return array
2489 public function get_courses_display_options() {
2490 return $this->coursesdisplayoptions;
2494 * Sets options to display list of subcategories
2496 * Options 'sort', 'offset' and 'limit' are passed to core_course_category::get_children().
2497 * Any other options may be used by renderer functions
2499 * @param array $options
2500 * @return coursecat_helper
2502 public function set_categories_display_options($options) {
2503 $this->categoriesdisplayoptions = $options;
2504 return $this;
2508 * Return the specified option to display list of subcategories
2510 * @param string $optionname option name
2511 * @param mixed $defaultvalue default value for option if it is not specified
2512 * @return mixed
2514 public function get_categories_display_option($optionname, $defaultvalue = null) {
2515 if (array_key_exists($optionname, $this->categoriesdisplayoptions)) {
2516 return $this->categoriesdisplayoptions[$optionname];
2517 } else {
2518 return $defaultvalue;
2523 * Returns all options to display list of subcategories
2525 * This array is usually passed to {@link core_course_category::get_children()}
2527 * @return array
2529 public function get_categories_display_options() {
2530 return $this->categoriesdisplayoptions;
2534 * Sets additional general options to pass between renderer functions, usually HTML attributes
2536 * @param array $attributes
2537 * @return coursecat_helper
2539 public function set_attributes($attributes) {
2540 $this->attributes = $attributes;
2541 return $this;
2545 * Return all attributes and erases them so they are not applied again
2547 * @param string $classname adds additional class name to the beginning of $attributes['class']
2548 * @return array
2550 public function get_and_erase_attributes($classname) {
2551 $attributes = $this->attributes;
2552 $this->attributes = array();
2553 if (empty($attributes['class'])) {
2554 $attributes['class'] = '';
2556 $attributes['class'] = $classname . ' '. $attributes['class'];
2557 return $attributes;
2561 * Sets the search criteria if the course is a search result
2563 * Search string will be used to highlight terms in course name and description
2565 * @param array $searchcriteria
2566 * @return coursecat_helper
2568 public function set_search_criteria($searchcriteria) {
2569 $this->searchcriteria = $searchcriteria;
2570 return $this;
2574 * Returns formatted and filtered description of the given category
2576 * @param core_course_category $coursecat category
2577 * @param stdClass|array $options format options, by default [noclean,overflowdiv],
2578 * if context is not specified it will be added automatically
2579 * @return string|null
2581 public function get_category_formatted_description($coursecat, $options = null) {
2582 if ($coursecat->id && $coursecat->is_uservisible() && !empty($coursecat->description)) {
2583 if (!isset($coursecat->descriptionformat)) {
2584 $descriptionformat = FORMAT_MOODLE;
2585 } else {
2586 $descriptionformat = $coursecat->descriptionformat;
2588 if ($options === null) {
2589 $options = array('noclean' => true, 'overflowdiv' => true);
2590 } else {
2591 $options = (array)$options;
2593 $context = context_coursecat::instance($coursecat->id);
2594 if (!isset($options['context'])) {
2595 $options['context'] = $context;
2597 $text = file_rewrite_pluginfile_urls($coursecat->description,
2598 'pluginfile.php', $context->id, 'coursecat', 'description', null);
2599 return format_text($text, $descriptionformat, $options);
2601 return null;
2605 * Returns given course's summary with proper embedded files urls and formatted
2607 * @param core_course_list_element $course
2608 * @param array|stdClass $options additional formatting options
2609 * @return string
2611 public function get_course_formatted_summary($course, $options = array()) {
2612 global $CFG;
2613 require_once($CFG->libdir. '/filelib.php');
2614 if (!$course->has_summary()) {
2615 return '';
2617 $options = (array)$options;
2618 $context = context_course::instance($course->id);
2619 if (!isset($options['context'])) {
2620 // TODO see MDL-38521
2621 // option 1 (current), page context - no code required
2622 // option 2, system context
2623 // $options['context'] = context_system::instance();
2624 // option 3, course context:
2625 // $options['context'] = $context;
2626 // option 4, course category context:
2627 // $options['context'] = $context->get_parent_context();
2629 $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null);
2630 $summary = format_text($summary, $course->summaryformat, $options, $course->id);
2631 if (!empty($this->searchcriteria['search'])) {
2632 $summary = highlight($this->searchcriteria['search'], $summary);
2634 return $summary;
2638 * Returns course name as it is configured to appear in courses lists formatted to course context
2640 * @param core_course_list_element $course
2641 * @param array|stdClass $options additional formatting options
2642 * @return string
2644 public function get_course_formatted_name($course, $options = array()) {
2645 $options = (array)$options;
2646 if (!isset($options['context'])) {
2647 $options['context'] = context_course::instance($course->id);
2649 $name = format_string(get_course_display_name_for_list($course), true, $options);
2650 if (!empty($this->searchcriteria['search'])) {
2651 $name = highlight($this->searchcriteria['search'], $name);
2653 return $name;