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 310 and 400] [Versions 311 and 400] [Versions 39 and 400]

   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   * Table to show the list of steps in a 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  namespace tool_usertours\local\table;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use tool_usertours\helper;
  30  use tool_usertours\tour;
  31  use tool_usertours\step;
  32  
  33  require_once($CFG->libdir . '/tablelib.php');
  34  
  35  /**
  36   * Table to show the list of steps in a tour.
  37   *
  38   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class step_list extends \flexible_table {
  42  
  43      /**
  44       * @var     int     $tourid     The id of the tour.
  45       */
  46      protected $tourid;
  47  
  48      /**
  49       * Construct the table for the specified tour ID.
  50       *
  51       * @param   int     $tourid     The id of the tour.
  52       */
  53      public function __construct($tourid) {
  54          parent::__construct('steps');
  55          $this->tourid = $tourid;
  56  
  57          $baseurl = new \moodle_url('/tool/usertours/configure.php', array(
  58                  'id' => $tourid,
  59              ));
  60          $this->define_baseurl($baseurl);
  61  
  62          // Column definition.
  63          $this->define_columns(array(
  64              'title',
  65              'content',
  66              'target',
  67              'actions',
  68          ));
  69  
  70          $this->define_headers(array(
  71              get_string('title',   'tool_usertours'),
  72              get_string('content', 'tool_usertours'),
  73              get_string('target',  'tool_usertours'),
  74              get_string('actions', 'tool_usertours'),
  75          ));
  76  
  77          $this->set_attribute('class', 'admintable generaltable steptable');
  78          $this->setup();
  79      }
  80  
  81      /**
  82       * Format the current row's title column.
  83       *
  84       * @param   step    $step       The step for this row.
  85       * @return  string
  86       */
  87      protected function col_title(step $step) {
  88          global $OUTPUT;
  89          return $OUTPUT->render(helper::render_stepname_inplace_editable($step));
  90      }
  91  
  92      /**
  93       * Format the current row's content column.
  94       *
  95       * @param   step    $step       The step for this row.
  96       * @return  string
  97       */
  98      protected function col_content(step $step) {
  99          $content = $step->get_content();
 100          $systemcontext = \context_system::instance();
 101          $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $systemcontext->id,
 102              'tool_usertours', 'stepcontent', $step->get_id());
 103  
 104          $content = helper::get_string_from_input($content);
 105          $content = step::get_step_image_from_input($content);
 106  
 107          return format_text($content, $step->get_contentformat());
 108      }
 109  
 110      /**
 111       * Format the current row's target column.
 112       *
 113       * @param   step    $step       The step for this row.
 114       * @return  string
 115       */
 116      protected function col_target(step $step) {
 117          return $step->get_target()->get_displayname();
 118      }
 119  
 120      /**
 121       * Format the current row's actions column.
 122       *
 123       * @param   step    $step       The step for this row.
 124       * @return  string
 125       */
 126      protected function col_actions(step $step) {
 127          $actions = [];
 128  
 129          if ($step->is_first_step()) {
 130              $actions[] = helper::get_filler_icon();
 131          } else {
 132              $actions[] = helper::format_icon_link($step->get_moveup_link(), 't/up', get_string('movestepup', 'tool_usertours'));
 133          }
 134  
 135          if ($step->is_last_step()) {
 136              $actions[] = helper::get_filler_icon();
 137          } else {
 138              $actions[] = helper::format_icon_link($step->get_movedown_link(), 't/down',
 139                      get_string('movestepdown', 'tool_usertours'));
 140          }
 141  
 142          $actions[] = helper::format_icon_link($step->get_edit_link(), 't/edit', get_string('edit'));
 143  
 144          $actions[] = helper::format_icon_link($step->get_delete_link(), 't/delete', get_string('delete'), 'moodle', [
 145              'data-action'   => 'delete',
 146              'data-id'       => $step->get_id(),
 147          ]);
 148  
 149          return implode('&nbsp;', $actions);
 150      }
 151  }