Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 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  namespace core_course\output;
  18  
  19  use core_completion\manager;
  20  use moodle_url;
  21  use renderable;
  22  use renderer_base;
  23  use templatable;
  24  use url_select;
  25  
  26  /**
  27   * Renderable class for the action bar elements in the course completion pages.
  28   *
  29   * @package    core_course
  30   * @copyright  2022 Mihail Geshoski <mihail@moodle.com>
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class completion_action_bar implements templatable, renderable {
  34  
  35      /** @var int $courseid The course id. */
  36      private $courseid;
  37  
  38      /** @var moodle_url $currenturl The URL of the current page. */
  39      private $currenturl;
  40  
  41      /**
  42       * The class constructor.
  43       *
  44       * @param int $courseid The course id.
  45       * @param moodle_url $pageurl The URL of the current page.
  46       */
  47      public function __construct(int $courseid, moodle_url $pageurl) {
  48          $this->courseid = $courseid;
  49          $this->currenturl = $pageurl;
  50      }
  51  
  52      /**
  53       * Export the data for the mustache template.
  54       *
  55       * @param renderer_base $output renderer to be used to render the action bar elements.
  56       * @return array The array which contains the data required to output the tertiary navigation selector for the course
  57       *               completion pages.
  58       */
  59      public function export_for_template(renderer_base $output): array {
  60          $urlselect = new url_select(manager::get_available_completion_options($this->courseid),
  61              $this->currenturl->out(false), null, 'coursecompletionactionselect');
  62          $urlselect->set_label(get_string('coursecompletionnavigation', 'completion'), ['class' => 'sr-only']);
  63  
  64          return [
  65              'urlselect' => $urlselect->export_for_template($output),
  66          ];
  67      }
  68  }