Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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