Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Contains the default section course format output class.
  19   *
  20   * @package   core_courseformat
  21   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_courseformat\output;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  global $CFG;
  30  require_once($CFG->dirroot . '/course/renderer.php');
  31  
  32  use action_menu;
  33  use action_menu_link_secondary;
  34  use cm_info;
  35  use coding_exception;
  36  use context_course;
  37  use core_course_renderer;
  38  use core_courseformat\base as course_format;
  39  use html_writer;
  40  use moodle_page;
  41  use moodle_url;
  42  use pix_icon;
  43  use renderable;
  44  use section_info;
  45  use templatable;
  46  use url_select;
  47  
  48  /**
  49   * Base class to render a course add section buttons.
  50   *
  51   * @package   core_courseformat
  52   * @copyright 2020 Ferran Recio <ferran@moodle.com>
  53   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  54   */
  55  abstract class section_renderer extends core_course_renderer {
  56  
  57      /**
  58       * @var core_course_renderer contains an instance of core course renderer
  59       * @deprecated since 4.0 - use $this to access course renderer methods
  60       */
  61      protected $courserenderer;
  62  
  63      /**
  64       * Constructor method, calls the parent constructor.
  65       *
  66       * @deprecated since 4.0
  67       *
  68       * Note: this method exists only for compatibilitiy with legacy course formats. Legacy formats
  69       * depends on $this->courserenderer to access the course renderer methods. Since Moodle 4.0
  70       * core_courseformat\output\section_renderer extends core_course_renderer and all metdhos can be used directly from $this.
  71       *
  72       * @param moodle_page $page
  73       * @param string $target one of rendering target constants
  74       */
  75      public function __construct(moodle_page $page, $target) {
  76          parent::__construct($page, $target);
  77          $this->courserenderer = $this->page->get_renderer('core', 'course');
  78      }
  79  
  80      /**
  81       * Renders the provided widget and returns the HTML to display it.
  82       *
  83       * Course format templates uses a similar subfolder structure to the renderable classes.
  84       * This method find out the specific template for a course widget. That's the reason why
  85       * this render method is different from the normal plugin renderer one.
  86       *
  87       * course format templatables can be rendered using the core_course/local/* templates.
  88       * Format plugins are free to override the default template location using render_xxx methods as usual.
  89       *
  90       * @param renderable $widget instance with renderable interface
  91       * @return string the widget HTML
  92       */
  93      public function render(renderable $widget) {
  94          global $CFG;
  95          $fullpath = str_replace('\\', '/', get_class($widget));
  96          $classparts = explode('/', $fullpath);
  97          // Strip namespaces.
  98          $classname = array_pop($classparts);
  99          // Remove _renderable suffixes.
 100          $classname = preg_replace('/_renderable$/', '', $classname);
 101  
 102          $rendermethod = 'render_' . $classname;
 103          if (method_exists($this, $rendermethod)) {
 104              return $this->$rendermethod($widget);
 105          }
 106  
 107          // If nothing works, let the parent class decide.
 108          return parent::render($widget);
 109      }
 110  
 111      /**
 112       * Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page
 113       *
 114       * @param stdClass $section The course_section entry from DB
 115       * @param stdClass $course The course entry from DB
 116       * @return string HTML to output.
 117       */
 118      public function section_title($section, $course) {
 119          $title = get_section_name($course, $section);
 120          $url = course_get_url($course, $section->section, array('navigation' => true));
 121          if ($url) {
 122              $title = html_writer::link($url, $title);
 123          }
 124          return $title;
 125      }
 126  
 127      /**
 128       * Generate the section title to be displayed on the section page, without a link
 129       *
 130       * @param stdClass $section The course_section entry from DB
 131       * @param stdClass $course The course entry from DB
 132       * @return string HTML to output.
 133       */
 134      public function section_title_without_link($section, $course) {
 135          return get_section_name($course, $section);
 136      }
 137  
 138      /**
 139       * Get the updated rendered version of a cm list item.
 140       *
 141       * This method is used when an activity is duplicated or copied in on the client side without refreshing the page.
 142       * It replaces the course renderer course_section_cm_list_item method but it's scope is different.
 143       * Note that the previous method is used every time an activity is rendered, independent of it is the initial page
 144       * loading or an Ajax update. In this case, course_section_updated_cm_item will only be used when the course editor
 145       * requires to get an updated cm item HTML to perform partial page refresh. It will be used for suporting the course
 146       * editor webservices.
 147       *
 148       * By default, the template used for update a cm_item is the same as when it renders initially, but format plugins are
 149       * free to override this methos to provide extra affects or so.
 150       *
 151       * @param course_format $format the course format
 152       * @param section_info $section the section info
 153       * @param cm_info $cm the course module ionfo
 154       * @param array $displayoptions optional extra display options
 155       * @return string the rendered element
 156       */
 157      public function course_section_updated_cm_item(
 158          course_format $format,
 159          section_info $section,
 160          cm_info $cm,
 161          array $displayoptions = []
 162      ) {
 163  
 164          $cmitemclass = $format->get_output_classname('content\\section\\cmitem');
 165          $cmitem = new $cmitemclass($format, $section, $cm, $displayoptions);
 166          return $this->render($cmitem);
 167      }
 168  
 169      /**
 170       * Get the updated rendered version of a section.
 171       *
 172       * This method will only be used when the course editor requires to get an updated cm item HTML
 173       * to perform partial page refresh. It will be used for supporting the course editor webservices.
 174       *
 175       * By default, the template used for update a section is the same as when it renders initially,
 176       * but format plugins are free to override this method to provide extra effects or so.
 177       *
 178       * @param course_format $format the course format
 179       * @param section_info $section the section info
 180       * @return string the rendered element
 181       */
 182      public function course_section_updated(
 183          course_format $format,
 184          section_info $section
 185      ): string {
 186          $sectionclass = $format->get_output_classname('content\\section');
 187          $output = new $sectionclass($format, $section);
 188          return $this->render($output);
 189      }
 190  
 191      /**
 192       * Get the course index drawer with placeholder.
 193       *
 194       * The default course index is loaded after the page is ready. Format plugins can override
 195       * this method to provide an alternative course index.
 196       *
 197       * If the format is not compatible with the course index, this method will return an empty string.
 198       *
 199       * @param course_format $format the course format
 200       * @return String the course index HTML.
 201       */
 202      public function course_index_drawer(course_format $format): ?String {
 203          if ($format->uses_course_index()) {
 204              include_course_editor($format);
 205              return $this->render_from_template('core_courseformat/local/courseindex/drawer', []);
 206          }
 207          return '';
 208      }
 209  
 210      /**
 211       * Render the enable bulk editing button.
 212       * @param course_format $format the course format
 213       * @return string|null the enable bulk button HTML (or null if no bulk available).
 214       */
 215      public function bulk_editing_button(course_format $format): ?string {
 216          if (!$format->show_editor() || !$format->supports_components()) {
 217              return null;
 218          }
 219          $widgetclass = $format->get_output_classname('content\\bulkedittoggler');
 220          $widget = new $widgetclass($format);
 221          return $this->render($widget);
 222      }
 223  
 224      /**
 225       * Generate the edit control action menu
 226       *
 227       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 228       *
 229       * The section edit controls are now part of the main core_courseformat\output\local\content\section output
 230       * and does not use renderer methods anymore.
 231       *
 232       * @param array $controls The edit control items from section_edit_control_items
 233       * @param stdClass $course The course entry from DB (not used)
 234       * @param stdClass $section The course_section entry from DB
 235       * @return string HTML to output.
 236       */
 237      protected function section_edit_control_menu($controls, $course, $section) {
 238          debugging('section_edit_control_menu() can not be used anymore. Please use ' .
 239              'core_courseformat\\output\\local\\content\\section to render a section. In case you need to modify those controls ' .
 240              'override core_courseformat\\output\\local\\content\\section\\controlmenu in your format plugin.', DEBUG_DEVELOPER);
 241  
 242          $o = "";
 243          if (!empty($controls)) {
 244              $menu = new action_menu();
 245              $menu->set_menu_trigger(get_string('edit'));
 246              $menu->attributes['class'] .= ' section-actions';
 247              foreach ($controls as $value) {
 248                  $url = empty($value['url']) ? '' : $value['url'];
 249                  $icon = empty($value['icon']) ? '' : $value['icon'];
 250                  $name = empty($value['name']) ? '' : $value['name'];
 251                  $attr = empty($value['attr']) ? array() : $value['attr'];
 252                  $class = empty($value['pixattr']['class']) ? '' : $value['pixattr']['class'];
 253                  $al = new action_menu_link_secondary(
 254                      new moodle_url($url),
 255                      new pix_icon($icon, '', null, array('class' => "smallicon " . $class)),
 256                      $name,
 257                      $attr
 258                  );
 259                  $menu->add($al);
 260              }
 261  
 262              $o .= html_writer::div(
 263                  $this->render($menu),
 264                  'section_action_menu',
 265                  array('data-sectionid' => $section->id)
 266              );
 267          }
 268  
 269          return $o;
 270      }
 271  
 272      /**
 273       * Generate the content to displayed on the right part of a section
 274       * before course modules are included
 275       *
 276       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 277       *
 278       * Spatial references like "left" or "right" are limiting the way formats and themes can
 279       * extend courses. The elements from this method are now included in the
 280       * core_courseformat\output\local\content\section output components.
 281       *
 282       * @param stdClass $section The course_section entry from DB
 283       * @param stdClass $course The course entry from DB
 284       * @param bool $onsectionpage true if being printed on a section page
 285       * @return string HTML to output.
 286       */
 287      protected function section_right_content($section, $course, $onsectionpage) {
 288  
 289          debugging('section_right_content() can not be used anymore. Please use ' .
 290              'core_courseformat\\output\\local\\content\\section to render a section.', DEBUG_DEVELOPER);
 291  
 292          $o = $this->output->spacer();
 293  
 294          $controls = $this->section_edit_control_items($course, $section, $onsectionpage);
 295          $o .= $this->section_edit_control_menu($controls, $course, $section);
 296  
 297          return $o;
 298      }
 299  
 300      /**
 301       * Generate the content to displayed on the left part of a section
 302       * before course modules are included
 303       *
 304       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 305       *
 306       * Spatial references like "left" or "right" are limiting the way formats and themes can
 307       * extend courses. The elements from this method are now included in the
 308       * core_courseformat\output\local\content\section output components.
 309       *
 310       * @param stdClass $section The course_section entry from DB
 311       * @param stdClass $course The course entry from DB
 312       * @param bool $onsectionpage true if being printed on a section page
 313       * @return string HTML to output.
 314       */
 315      protected function section_left_content($section, $course, $onsectionpage) {
 316  
 317          debugging('section_left_content() can not be used anymore. Please use ' .
 318              'core_courseformat\\output\\local\\content\\section to render a section.', DEBUG_DEVELOPER);
 319  
 320          $o = '';
 321  
 322          if ($section->section != 0) {
 323              // Only in the non-general sections.
 324              if (course_get_format($course)->is_section_current($section)) {
 325                  $o = get_accesshide(get_string('currentsection', 'format_' . $course->format));
 326              }
 327          }
 328  
 329          return $o;
 330      }
 331  
 332      /**
 333       * Generate the display of the header part of a section before
 334       * course modules are included
 335       *
 336       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 337       *
 338       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 339       * mustache templates instead of a renderer method.
 340       *
 341       * @param stdClass $section The course_section entry from DB
 342       * @param stdClass $course The course entry from DB
 343       * @param bool $onsectionpage true if being printed on a single-section page
 344       * @param int $sectionreturn The section to return to after an action
 345       * @return string HTML to output.
 346       */
 347      protected function section_header($section, $course, $onsectionpage, $sectionreturn = null) {
 348          debugging('section_header() is deprecated. Please use ' .
 349              'core_courseformat\\output\\local\\content\\section to render a section ' .
 350              'or core_courseformat\output\\local\\content\\section\\header ' .
 351              'to print only the header.', DEBUG_DEVELOPER);
 352  
 353          $o = '';
 354          $sectionstyle = '';
 355  
 356          if ($section->section != 0) {
 357              // Only in the non-general sections.
 358              if (!$section->visible) {
 359                  $sectionstyle = ' hidden';
 360              }
 361              if (course_get_format($course)->is_section_current($section)) {
 362                  $sectionstyle = ' current';
 363              }
 364          }
 365  
 366          $o .= html_writer::start_tag('li', [
 367              'id' => 'section-' . $section->section,
 368              'class' => 'section main clearfix' . $sectionstyle,
 369              'role' => 'region',
 370              'aria-labelledby' => "sectionid-{$section->id}-title",
 371              'data-sectionid' => $section->section,
 372              'data-sectionreturnid' => $sectionreturn
 373          ]);
 374  
 375          $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
 376          $o .= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
 377  
 378          $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
 379          $o .= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
 380          $o .= html_writer::start_tag('div', array('class' => 'content'));
 381  
 382          // When not on a section page, we display the section titles except the general section if null.
 383          $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
 384  
 385          // When on a section page, we only display the general section title, if title is not the default one.
 386          $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
 387  
 388          $classes = ' accesshide';
 389          if ($hasnamenotsecpg || $hasnamesecpg) {
 390              $classes = '';
 391          }
 392          $sectionname = html_writer::tag('span', $this->section_title($section, $course));
 393          $o .= $this->output->heading($sectionname, 3, 'sectionname' . $classes, "sectionid-{$section->id}-title");
 394  
 395          $o .= $this->section_availability($section);
 396  
 397          $o .= html_writer::start_tag('div', array('class' => 'summary'));
 398          if ($section->uservisible || $section->visible) {
 399              // Show summary if section is available or has availability restriction information.
 400              // Do not show summary if section is hidden but we still display it because of course setting
 401              // "Hidden sections are shown as not available".
 402              $o .= $this->format_summary_text($section);
 403          }
 404          $o .= html_writer::end_tag('div');
 405  
 406          return $o;
 407      }
 408  
 409      /**
 410       * Generate the display of the footer part of a section.
 411       *
 412       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 413       *
 414       * This element is integrated into core_courseformat\output\local\content\section output component and it is
 415       * displayed using mustache templates instead of a renderer method.
 416       *
 417       * @return string HTML to output.
 418       */
 419      protected function section_footer() {
 420  
 421          debugging('section_footer() is deprecated. Please use ' .
 422              'core_courseformat\\output\\local\\content\\section to render individual sections or .' .
 423              'core_courseformat\\output\\local\\content to render the full course', DEBUG_DEVELOPER);
 424  
 425          $o = html_writer::end_tag('div');
 426          $o .= html_writer::end_tag('li');
 427          return $o;
 428      }
 429  
 430      /**
 431       * Generate the starting container html for a list of sections.
 432       *
 433       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 434       *
 435       * @return string HTML to output.
 436       */
 437      protected function start_section_list() {
 438          debugging('start_section_list() is deprecated. Please use ' .
 439              'core_courseformat\\output\\local\\content\\section to render individual sections or .' .
 440              'core_courseformat\\output\\local\\content to render the full course', DEBUG_DEVELOPER);
 441          return html_writer::start_tag('ul', ['class' => 'sections']);
 442      }
 443  
 444      /**
 445       * Generate the closing container html for a list of sections.
 446       *
 447       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.y
 448       *
 449       * @return string HTML to output.
 450       */
 451      protected function end_section_list() {
 452          debugging('end_section_list() is deprecated. Please use ' .
 453              'core_courseformat\\output\\local\\content\\section to render individual sections or .' .
 454              'core_courseformat\\output\\local\\content to render the full course', DEBUG_DEVELOPER);
 455          return html_writer::end_tag('ul');
 456      }
 457  
 458      /**
 459       * Old method to print section edit controls. Do not use it!
 460       *
 461       * @deprecated since Moodle 3.0 MDL-48947 - Use core_courseformat\output\section_renderer::section_edit_control_items() instead
 462       */
 463      protected function section_edit_controls() {
 464          throw new coding_exception('section_edit_controls() can not be used anymore. Please use ' .
 465              'section_edit_control_items() instead.');
 466      }
 467  
 468      /**
 469       * Generate the edit control items of a section
 470       *
 471       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 472       *
 473       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 474       * mustache templates instead of a renderer method.
 475       *
 476       * @param stdClass $course The course entry from DB
 477       * @param stdClass $section The course_section entry from DB
 478       * @param bool $onsectionpage true if being printed on a section page
 479       * @return array of edit control items
 480       */
 481      protected function section_edit_control_items($course, $section, $onsectionpage = false) {
 482          debugging('section_edit_control_items() is deprecated, please use or extend' .
 483              'core_courseformat\output\\local\\content\\section\\controlmenu instead (like topics format does).', DEBUG_DEVELOPER);
 484  
 485          $format = course_get_format($course);
 486          $modinfo = $format->get_modinfo();
 487  
 488          if ($onsectionpage) {
 489              $format->set_section_number($section->section);
 490          }
 491  
 492          // We need a section_info object, not a record.
 493          $section = $modinfo->get_section_info($section->section);
 494  
 495          $widgetclass = $format->get_output_classname('content\\section\\controlmenu');
 496          $widget = new $widgetclass($format, $section);
 497          return $widget->section_control_items();
 498      }
 499  
 500      /**
 501       * Generate a summary of a section for display on the 'course index page'
 502       *
 503       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 504       *
 505       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 506       * mustache templates instead of a renderer method.
 507       *
 508       * @param stdClass $section The course_section entry from DB
 509       * @param stdClass $course The course entry from DB
 510       * @param array    $mods (argument not used)
 511       * @return string HTML to output.
 512       */
 513      protected function section_summary($section, $course, $mods) {
 514          debugging('section_summary() is deprecated. Please use ' .
 515              'core_courseformat\output\\local\\content\\section to render sections. If you need to modify those summary, extend ' .
 516              'core_courseformat\output\\local\\content\\section\\summary in your format plugin.', DEBUG_DEVELOPER);
 517  
 518          $classattr = 'section main section-summary clearfix';
 519          $linkclasses = '';
 520  
 521          // If section is hidden then display grey section link.
 522          if (!$section->visible) {
 523              $classattr .= ' hidden';
 524              $linkclasses .= ' dimmed_text';
 525          } else if (course_get_format($course)->is_section_current($section)) {
 526              $classattr .= ' current';
 527          }
 528  
 529          $title = get_section_name($course, $section);
 530          $o = '';
 531          $o .= html_writer::start_tag('li', [
 532              'id' => 'section-' . $section->section,
 533              'class' => $classattr,
 534              'role' => 'region',
 535              'aria-label' => $title,
 536              'data-sectionid' => $section->section
 537          ]);
 538  
 539          $o .= html_writer::tag('div', '', array('class' => 'left side'));
 540          $o .= html_writer::tag('div', '', array('class' => 'right side'));
 541          $o .= html_writer::start_tag('div', array('class' => 'content'));
 542  
 543          if ($section->uservisible) {
 544              $title = html_writer::tag(
 545                  'a',
 546                  $title,
 547                  array('href' => course_get_url($course, $section->section), 'class' => $linkclasses)
 548              );
 549          }
 550          $o .= $this->output->heading($title, 3, 'section-title');
 551  
 552          $o .= $this->section_availability($section);
 553          $o .= html_writer::start_tag('div', array('class' => 'summarytext'));
 554  
 555          if ($section->uservisible || $section->visible) {
 556              // Show summary if section is available or has availability restriction information.
 557              // Do not show summary if section is hidden but we still display it because of course setting
 558              // "Hidden sections are shown as not available".
 559              $o .= $this->format_summary_text($section);
 560          }
 561          $o .= html_writer::end_tag('div');
 562          $o .= $this->section_activity_summary($section, $course, null);
 563  
 564          $o .= html_writer::end_tag('div');
 565          $o .= html_writer::end_tag('li');
 566  
 567          return $o;
 568      }
 569  
 570      /**
 571       * Generate a summary of the activites in a section
 572       *
 573       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 574       *
 575       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 576       * mustache templates instead of a renderer method.
 577       *
 578       * @param stdClass $section The course_section entry from DB
 579       * @param stdClass $course the course record from DB
 580       * @param array    $mods (argument not used)
 581       * @return string HTML to output.
 582       */
 583      protected function section_activity_summary($section, $course, $mods) {
 584  
 585          debugging('section_activity_summary() is deprecated. Please use ' .
 586              'core_courseformat\output\\local\\content\\section to render sections. ' .
 587              'If you need to modify those information, extend ' .
 588              'core_courseformat\output\\local\\content\\section\\cmsummary in your format plugin.', DEBUG_DEVELOPER);
 589  
 590          $format = course_get_format($course);
 591          $widgetclass = $format->get_output_classname('content\\section\\cmsummary');
 592          $widget = new $widgetclass($format, $section);
 593          $this->render($widget);
 594      }
 595  
 596      /**
 597       * If section is not visible, display the message about that ('Not available
 598       * until...', that sort of thing). Otherwise, returns blank.
 599       *
 600       * For users with the ability to view hidden sections, it shows the
 601       * information even though you can view the section and also may include
 602       * slightly fuller information (so that teachers can tell when sections
 603       * are going to be unavailable etc). This logic is the same as for
 604       * activities.
 605       *
 606       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 607       *
 608       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 609       * mustache templates instead of a renderer method.
 610       *
 611       * @param section_info $section The course_section entry from DB
 612       * @param bool $canviewhidden True if user can view hidden sections
 613       * @return string HTML to output
 614       */
 615      protected function section_availability_message($section, $canviewhidden) {
 616          global $CFG;
 617  
 618          debugging('section_availability_message() is deprecated. Please use ' .
 619              'core_courseformat\output\\local\\content\\section to render sections. If you need to modify this element, extend ' .
 620              'core_courseformat\output\\local\\content\\section\\availability in your format plugin.', DEBUG_DEVELOPER);
 621  
 622          $course = $section->course;
 623          $format = course_get_format($course);
 624          $widgetclass = $format->get_output_classname('content\\section\\availability');
 625          $widget = new $widgetclass($format, $section);
 626          $this->render($widget);
 627      }
 628  
 629      /**
 630       * Displays availability information for the section (hidden, not available unles, etc.)
 631       *
 632       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 633       *
 634       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 635       * mustache templates instead of a renderer method.
 636       *
 637       * @param section_info $section
 638       * @return string
 639       */
 640      public function section_availability($section) {
 641          debugging('section_availability() is deprecated. Please use ' .
 642              'core_courseformat\output\\local\\content\\section to render sections. If you need to modify this element, extend ' .
 643              'core_courseformat\output\\local\\content\\section\\availability in your format plugin.', DEBUG_DEVELOPER);
 644  
 645          $context = context_course::instance($section->course);
 646          $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
 647          return html_writer::div($this->section_availability_message($section, $canviewhidden), 'section_availability');
 648      }
 649  
 650      /**
 651       * Show if something is on on the course clipboard (moving around)
 652       *
 653       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 654       *
 655       * While the non ajax course eidtion is still supported, the old clipboard will be
 656       * emulated by core_courseformat\output\local\content\section\cmlist.
 657       *
 658       * @param stdClass $course The course entry from DB
 659       * @param int $sectionno The section number in the course which is being displayed
 660       * @return string HTML to output.
 661       */
 662      protected function course_activity_clipboard($course, $sectionno = null) {
 663          global $USER;
 664          debugging('Non ajax course edition using course_activity_clipboard is not supported anymore.', DEBUG_DEVELOPER);
 665  
 666          $o = '';
 667          // If currently moving a file then show the current clipboard.
 668          if (ismoving($course->id)) {
 669              $url = new moodle_url(
 670                  '/course/mod.php',
 671                  array(
 672                      'sesskey' => sesskey(),
 673                      'cancelcopy' => true,
 674                      'sr' => $sectionno,
 675                  )
 676              );
 677  
 678              $o .= html_writer::start_tag('div', array('class' => 'clipboard'));
 679              $o .= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
 680              $o .= ' (' . html_writer::link($url, get_string('cancel')) . ')';
 681              $o .= html_writer::end_tag('div');
 682          }
 683  
 684          return $o;
 685      }
 686  
 687      /**
 688       * Generate next/previous section links for naviation.
 689       *
 690       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 691       *
 692       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 693       * mustache templates instead of a renderer method.
 694       *
 695       * @param stdClass $course The course entry from DB
 696       * @param array $sections The course_sections entries from the DB
 697       * @param int $sectionno The section number in the course which is being displayed
 698       * @return array associative array with previous and next section link
 699       */
 700      protected function get_nav_links($course, $sections, $sectionno) {
 701  
 702          debugging('get_nav_links() is deprecated. Please use ' .
 703              'core_courseformat\\output\\local\\content to render a course. If you need to modify this element, extend ' .
 704              'core_courseformat\\output\\local\\content\\sectionnavigation in your format plugin.', DEBUG_DEVELOPER);
 705  
 706          // FIXME: This is really evil and should by using the navigation API.
 707          $course = course_get_format($course)->get_course();
 708          $canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
 709              or !$course->hiddensections;
 710  
 711          $links = array('previous' => '', 'next' => '');
 712          $back = $sectionno - 1;
 713          while ($back > 0 and empty($links['previous'])) {
 714              if ($canviewhidden || $sections[$back]->uservisible) {
 715                  $params = array();
 716                  if (!$sections[$back]->visible) {
 717                      $params = array('class' => 'dimmed_text');
 718                  }
 719                  $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
 720                  $previouslink .= get_section_name($course, $sections[$back]);
 721                  $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
 722              }
 723              $back--;
 724          }
 725  
 726          $forward = $sectionno + 1;
 727          $numsections = course_get_format($course)->get_last_section_number();
 728          while ($forward <= $numsections and empty($links['next'])) {
 729              if ($canviewhidden || $sections[$forward]->uservisible) {
 730                  $params = array();
 731                  if (!$sections[$forward]->visible) {
 732                      $params = array('class' => 'dimmed_text');
 733                  }
 734                  $nextlink = get_section_name($course, $sections[$forward]);
 735                  $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
 736                  $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
 737              }
 738              $forward++;
 739          }
 740  
 741          return $links;
 742      }
 743  
 744      /**
 745       * Generate the header html of a stealth section
 746       *
 747       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 748       *
 749       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 750       * mustache templates instead of a renderer method.
 751       *
 752       * @param int $sectionno The section number in the course which is being displayed
 753       * @return string HTML to output.
 754       */
 755      protected function stealth_section_header($sectionno) {
 756          debugging('stealth_section_header() is deprecated. Please use ' .
 757              'core_courseformat\output\\local\\content\\section to render sections.', DEBUG_DEVELOPER);
 758  
 759          $o = '';
 760          $o .= html_writer::start_tag('li', [
 761              'id' => 'section-' . $sectionno,
 762              'class' => 'section main clearfix orphaned hidden',
 763              'data-sectionid' => $sectionno
 764          ]);
 765          $o .= html_writer::tag('div', '', array('class' => 'left side'));
 766          $course = course_get_format($this->page->course)->get_course();
 767          $section = course_get_format($this->page->course)->get_section($sectionno);
 768          $rightcontent = $this->section_right_content($section, $course, false);
 769          $o .= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
 770          $o .= html_writer::start_tag('div', array('class' => 'content'));
 771          $o .= $this->output->heading(
 772              get_string('orphanedactivitiesinsectionno', '', $sectionno),
 773              3,
 774              'sectionname'
 775          );
 776          return $o;
 777      }
 778  
 779      /**
 780       * Generate footer html of a stealth section
 781       *
 782       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 783       *
 784       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 785       * mustache templates instead of a renderer method.
 786       *
 787       * @return string HTML to output.
 788       */
 789      protected function stealth_section_footer() {
 790          debugging('stealth_section_footer() is deprecated. Please use ' .
 791              'core_courseformat\output\\local\\content\\section to render sections.', DEBUG_DEVELOPER);
 792  
 793          $o = html_writer::end_tag('div');
 794          $o .= html_writer::end_tag('li');
 795          return $o;
 796      }
 797  
 798      /**
 799       * Generate the html for a hidden section
 800       *
 801       * @param int $sectionno The section number in the course which is being displayed
 802       * @param int|stdClass $courseorid The course to get the section name for (object or just course id)
 803       * @return string HTML to output.
 804       */
 805      protected function section_hidden($sectionno, $courseorid = null) {
 806          if ($courseorid) {
 807              $sectionname = get_section_name($courseorid, $sectionno);
 808              $strnotavailable = get_string('notavailablecourse', '', $sectionname);
 809          } else {
 810              $strnotavailable = get_string('notavailable');
 811          }
 812  
 813          $o = '';
 814          $o .= html_writer::start_tag('li', [
 815              'id' => 'section-' . $sectionno,
 816              'class' => 'section main clearfix hidden',
 817              'data-sectionid' => $sectionno
 818          ]);
 819          $o .= html_writer::tag('div', '', array('class' => 'left side'));
 820          $o .= html_writer::tag('div', '', array('class' => 'right side'));
 821          $o .= html_writer::start_tag('div', array('class' => 'content'));
 822          $o .= html_writer::tag('div', $strnotavailable);
 823          $o .= html_writer::end_tag('div');
 824          $o .= html_writer::end_tag('li');
 825          return $o;
 826      }
 827  
 828      /**
 829       * Generate the html for the 'Jump to' menu on a single section page.
 830       *
 831       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
 832       *
 833       * This element is now a core_courseformat\output\content\section output component and it is displayed using
 834       * mustache templates instead of a renderer method.
 835       *
 836       * @param stdClass $course The course entry from DB
 837       * @param array $sections The course_sections entries from the DB
 838       * @param int $displaysection the current displayed section number.
 839       *
 840       * @return string HTML to output.
 841       */
 842      protected function section_nav_selection($course, $sections, $displaysection) {
 843  
 844          debugging('section_nav_selection() can not be used anymore. Please use ' .
 845              'core_courseformat\\output\\local\\content to render a course. If you need to modify this element, extend ' .
 846              'core_courseformat\\output\\local\\content\\sectionnavigation or ' .
 847              'core_courseformat\\output\\local\\content\\sectionselector in your format plugin.', DEBUG_DEVELOPER);
 848  
 849          $o = '';
 850          $sectionmenu = array();
 851          $sectionmenu[course_get_url($course)->out(false)] = get_string('maincoursepage');
 852          $modinfo = get_fast_modinfo($course);
 853          $section = 1;
 854          $numsections = course_get_format($course)->get_last_section_number();
 855          while ($section <= $numsections) {
 856              $thissection = $modinfo->get_section_info($section);
 857              if (($thissection->uservisible) && ($section != $displaysection) && ($url = course_get_url($course, $section))) {
 858                  $sectionmenu[$url->out(false)] = get_section_name($course, $section);
 859              }
 860              $section++;
 861          }
 862  
 863          $select = new url_select($sectionmenu, '', array('' => get_string('jumpto')));
 864          $select->class = 'jumpmenu';
 865          $select->formid = 'sectionmenu';
 866          $o .= $this->output->render($select);
 867  
 868          return $o;
 869      }
 870  
 871      /**
 872       * Output the html for a single section page.
 873       *
 874       * @deprecated since 4.0
 875       *
 876       * This is a deprecated method and it is mantain only for compatibilitiy with legacy course formats.
 877       * Please, to render a single section page use:
 878       *
 879       * $format = course_get_format($course);
 880       * // Set the section to display.
 881       * $format->set_section_number($displaysection);
 882       * $outputclass = $format->get_output_classname('content');
 883       * $widget = new $outputclass($format);
 884       * echo $this->render($widget);
 885       *
 886       * @param stdClass $course The course entry from DB
 887       * @param array $sections (argument not used)
 888       * @param array $mods (argument not used)
 889       * @param array $modnames (argument not used)
 890       * @param array $modnamesused (argument not used)
 891       * @param int $displaysection The section number in the course which is being displayed
 892       */
 893      public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
 894  
 895          debugging('Method print_single_section_page is deprecated, please use' .
 896              'core_courseformat\\output\\local\\content instead ' .
 897              'or override render_content method to use a different template', DEBUG_DEVELOPER);
 898  
 899          // Some abstract methods are not needed anymore. We simulate them in case they are not present.
 900          if (method_exists($this, 'start_section_list')) {
 901              $startlist = $this->start_section_list();
 902          } else {
 903              $startlist = html_writer::start_tag('ul', ['class' => '']);
 904          }
 905          if (method_exists($this, 'end_section_list')) {
 906              $endlist = $this->end_section_list();
 907          } else {
 908              $endlist = html_writer::end_tag('ul');
 909          }
 910  
 911          $format = course_get_format($course);
 912  
 913          // Set the section to display.
 914          $format->set_section_number($displaysection);
 915  
 916          $modinfo = $format->get_modinfo();
 917          $course = $format->get_course();
 918  
 919          // Can we view the section in question?
 920          if (!($sectioninfo = $modinfo->get_section_info($displaysection)) || !$sectioninfo->uservisible) {
 921              // This section doesn't exist or is not available for the user.
 922              // We actually already check this in course/view.php but just in case exit from this function as well.
 923              throw new \moodle_exception(
 924                  'unknowncoursesection',
 925                  'error',
 926                  course_get_url($course),
 927                  format_string($course->fullname)
 928              );
 929          }
 930  
 931          // Copy activity clipboard..
 932          echo $this->course_activity_clipboard($course, $displaysection);
 933          $thissection = $modinfo->get_section_info(0);
 934          if ($thissection->summary or !empty($modinfo->sections[0]) or $format->show_editor()) {
 935              echo $startlist;
 936              echo $this->section_header($thissection, $course, true, $displaysection);
 937              echo $this->course_section_cm_list($course, $thissection, $displaysection);
 938              echo $this->course_section_add_cm_control($course, 0, $displaysection);
 939              echo $this->section_footer();
 940              echo $endlist;
 941          }
 942  
 943          // Start single-section div.
 944          echo html_writer::start_tag('div', array('class' => 'single-section'));
 945  
 946          // The requested section page.
 947          $thissection = $modinfo->get_section_info($displaysection);
 948  
 949          // Title with section navigation links.
 950          $sectionnavlinks = $this->get_nav_links($course, $modinfo->get_section_info_all(), $displaysection);
 951          $sectiontitle = '';
 952          $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation navigationtitle'));
 953          $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
 954          $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
 955          // Title attributes.
 956          $classes = 'sectionname';
 957          if (!$thissection->visible) {
 958              $classes .= ' dimmed_text';
 959          }
 960          $sectionname = html_writer::tag('span', $this->section_title_without_link($thissection, $course));
 961          $sectiontitle .= $this->output->heading($sectionname, 3, $classes);
 962  
 963          $sectiontitle .= html_writer::end_tag('div');
 964          echo $sectiontitle;
 965  
 966          // Now the list of sections.
 967          echo $startlist;
 968  
 969          echo $this->section_header($thissection, $course, true, $displaysection);
 970  
 971          echo $this->course_section_cm_list($course, $thissection, $displaysection);
 972          echo $this->course_section_add_cm_control($course, $displaysection, $displaysection);
 973          echo $this->section_footer();
 974          echo $endlist;
 975  
 976          // Display section bottom navigation.
 977          $sectionbottomnav = '';
 978          $sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom'));
 979          $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
 980          $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
 981          $sectionbottomnav .= html_writer::tag(
 982              'div',
 983              $this->section_nav_selection($course, $sections, $displaysection),
 984              array('class' => 'mdl-align')
 985          );
 986          $sectionbottomnav .= html_writer::end_tag('div');
 987          echo $sectionbottomnav;
 988  
 989          // Close single-section div.
 990          echo html_writer::end_tag('div');
 991      }
 992  
 993      /**
 994       * Output the html for a multiple section page
 995       *
 996       * @deprecated since 4.0
 997       *
 998       * This is a deprecated method and it is mantain only for compatibilitiy with legacy course formats.
 999       * Please, to render a single section page use:
1000       *
1001       * $format = course_get_format($course);
1002       * $outputclass = $format->get_output_classname('content');
1003       * $widget = new $outputclass($format);
1004       * echo $this->render($widget);
1005       *
1006       * @param stdClass $course The course entry from DB
1007       * @param array $sections (argument not used)
1008       * @param array $mods (argument not used)
1009       * @param array $modnames (argument not used)
1010       * @param array $modnamesused (argument not used)
1011       */
1012      public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
1013  
1014          debugging('Method print_multiple_section_page is deprecated, please use' .
1015              'core_courseformat\\output\\local\\content instead ' .
1016              'or override render_content method to use a diferent template', DEBUG_DEVELOPER);
1017  
1018          // Some abstract methods are not needed anymore. We simulate them in case they are not present.
1019          if (method_exists($this, 'start_section_list')) {
1020              $startlist = $this->start_section_list();
1021          } else {
1022              $startlist = html_writer::start_tag('ul', ['class' => '']);
1023          }
1024          if (method_exists($this, 'end_section_list')) {
1025              $endlist = $this->end_section_list();
1026          } else {
1027              $endlist = html_writer::end_tag('ul');
1028          }
1029          if (method_exists($this, 'page_title')) {
1030              $pagetitle = $this->page_title();
1031          } else {
1032              $pagetitle = '';
1033          }
1034  
1035          $format = course_get_format($course);
1036  
1037          $modinfo = $format->get_modinfo();
1038          $course = $format->get_course();
1039  
1040          $context = context_course::instance($course->id);
1041          echo $this->output->heading($pagetitle, 2, 'accesshide');
1042  
1043          // Copy activity clipboard..
1044          echo $this->course_activity_clipboard($course, 0);
1045  
1046          // Now the list of sections..
1047          echo $startlist;
1048          $numsections = course_get_format($course)->get_last_section_number();
1049  
1050          foreach ($modinfo->get_section_info_all() as $section => $thissection) {
1051              if ($section == 0) {
1052                  // 0-section is displayed a little different then the others
1053                  if ($thissection->summary or !empty($modinfo->sections[0]) or $format->show_editor()) {
1054                      echo $this->section_header($thissection, $course, false, 0);
1055                      echo $this->course_section_cm_list($course, $thissection, 0);
1056                      echo $this->course_section_add_cm_control($course, 0, 0);
1057                      echo $this->section_footer();
1058                  }
1059                  continue;
1060              }
1061              if ($section > $numsections) {
1062                  // Activities inside this section are 'orphaned', this section will be printed as 'stealth' below.
1063                  continue;
1064              }
1065  
1066              if (!$format->is_section_visible($thissection)) {
1067                  continue;
1068              }
1069  
1070              if (!$format->show_editor() && $format->get_course_display() == COURSE_DISPLAY_MULTIPAGE) {
1071                  // Display section summary only.
1072                  echo $this->section_summary($thissection, $course, null);
1073              } else {
1074                  echo $this->section_header($thissection, $course, false, 0);
1075                  if ($thissection->uservisible) {
1076                      echo $this->course_section_cm_list($course, $thissection, 0);
1077                      echo $this->course_section_add_cm_control($course, $section, 0);
1078                  }
1079                  echo $this->section_footer();
1080              }
1081          }
1082  
1083          if ($format->show_editor()) {
1084              // Print stealth sections if present.
1085              foreach ($modinfo->get_section_info_all() as $section => $thissection) {
1086                  if ($section <= $numsections or empty($modinfo->sections[$section])) {
1087                      // This is not stealth section or it is empty.
1088                      continue;
1089                  }
1090                  echo $this->stealth_section_header($section);
1091                  echo $this->course_section_cm_list($course, $thissection, 0);
1092                  echo $this->stealth_section_footer();
1093              }
1094  
1095              echo $endlist;
1096  
1097              echo $this->change_number_sections($course, 0);
1098          } else {
1099              echo $endlist;
1100          }
1101      }
1102  
1103      /**
1104       * Returns controls in the bottom of the page to increase/decrease number of sections
1105       *
1106       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
1107       *
1108       * @param stdClass $course
1109       * @param int|null $sectionreturn
1110       */
1111      protected function change_number_sections($course, $sectionreturn = null) {
1112          debugging('Method change_number_sections is deprecated, please use' .
1113              'core_courseformat\\output\\local\\content\\addsection instead', DEBUG_DEVELOPER);
1114  
1115          $format = course_get_format($course);
1116          if ($sectionreturn) {
1117              $format->set_section_number($sectionreturn);
1118          }
1119          $outputclass = $format->get_output_classname('content\\addsection');
1120          $widget = new $outputclass($format);
1121          echo $this->render($widget);
1122      }
1123  
1124      /**
1125       * Generate html for a section summary text
1126       *
1127       * @deprecated since 4.0 MDL-72656 - use core_course output components instead.
1128       *
1129       * @param stdClass $section The course_section entry from DB
1130       * @return string HTML to output.
1131       */
1132      protected function format_summary_text($section) {
1133          debugging('Method format_summary_text is deprecated, please use' .
1134              'core_courseformat\output\\local\\content\\section\\summary::format_summary_text instead', DEBUG_DEVELOPER);
1135  
1136          $format = course_get_format($section->course);
1137          if (!($section instanceof section_info)) {
1138              $modinfo = $format->get_modinfo();
1139              $section = $modinfo->get_section_info($section->section);
1140          }
1141          $summaryclass = $format->get_output_classname('content\\section\\summary');
1142          $summary = new $summaryclass($format, $section);
1143          return $summary->format_summary_text();
1144      }
1145  }