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 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [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   * Tour.
  19   *
  20   * @package    tool_usertours
  21   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  use core_external\external_api;
  26  use tool_usertours\helper;
  27  
  28  /**
  29   * Manage inplace editable saves.
  30   *
  31   * @param string $itemtype The type of item.
  32   * @param int $itemid The ID of the item.
  33   * @param mixed $newvalue The new value
  34   * @return \core\output\inplace_editable
  35   */
  36  function tool_usertours_inplace_editable($itemtype, $itemid, $newvalue) {
  37      $context = \context_system::instance();
  38      external_api::validate_context($context);
  39      require_capability('tool/usertours:managetours', $context);
  40  
  41      if ($itemtype === 'tourname') {
  42          $tour = helper::get_tour($itemid);
  43          $tour->set_name($newvalue)->persist();
  44  
  45          return helper::render_tourname_inplace_editable($tour);
  46      } else if ($itemtype === 'tourdescription') {
  47          $tour = helper::get_tour($itemid);
  48          $tour->set_description($newvalue)->persist();
  49  
  50          return helper::render_tourdescription_inplace_editable($tour);
  51      } else if ($itemtype === 'tourenabled') {
  52          $tour = helper::get_tour($itemid);
  53          $tour->set_enabled(!!$newvalue)->persist();
  54          return helper::render_tourenabled_inplace_editable($tour);
  55      } else if ($itemtype === 'stepname') {
  56          $step = helper::get_step($itemid);
  57          $step->set_title($newvalue)->persist();
  58  
  59          return helper::render_stepname_inplace_editable($step);
  60      }
  61  }
  62  
  63  /**
  64   * Extend the user navigation to bootstrap tours.
  65   */
  66  function tool_usertours_extend_navigation_user() {
  67      \tool_usertours\helper::bootstrap();
  68  }
  69  
  70  /**
  71   * Add JS to bootstrap tours. Only in Moodle 3.3+
  72   */
  73  function tool_usertours_before_footer() {
  74      \tool_usertours\helper::bootstrap();
  75  }
  76  
  77  /**
  78   * Map icons for font-awesome themes.
  79   */
  80  function tool_usertours_get_fontawesome_icon_map() {
  81      return [
  82          'tool_usertours:t/export' => 'fa-download',
  83          'tool_usertours:i/reload' => 'fa-refresh',
  84          'tool_usertours:t/filler' => 'fa-spacer',
  85      ];
  86  }
  87  
  88  
  89  /**
  90   * Serves any files associated with the user tour content.
  91   *
  92   * @param stdClass $course Course object
  93   * @param stdClass $cm Course module object
  94   * @param context $context Context
  95   * @param string $filearea File area for data privacy
  96   * @param array $args Arguments
  97   * @param bool $forcedownload If we are forcing the download
  98   * @param array $options More options
  99   * @return bool Returns false if we don't find a file.
 100   */
 101  function tool_usertours_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []): bool {
 102      if ($context->contextlevel != CONTEXT_SYSTEM) {
 103          return false;
 104      }
 105  
 106      $fs = get_file_storage();
 107      $file = $fs->get_file($context->id, 'tool_usertours', $filearea, $args[0], '/', $args[1]);
 108      if (!$file) {
 109          return false; // No such file.
 110      }
 111      send_stored_file($file, null, 0, $forcedownload, $options);
 112      return true;
 113  }