Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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   * 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          return format_text(step::get_string_from_input($step->get_content()), FORMAT_HTML);
 100      }
 101  
 102      /**
 103       * Format the current row's target column.
 104       *
 105       * @param   step    $step       The step for this row.
 106       * @return  string
 107       */
 108      protected function col_target(step $step) {
 109          return $step->get_target()->get_displayname();
 110      }
 111  
 112      /**
 113       * Format the current row's actions column.
 114       *
 115       * @param   step    $step       The step for this row.
 116       * @return  string
 117       */
 118      protected function col_actions(step $step) {
 119          $actions = [];
 120  
 121          if ($step->is_first_step()) {
 122              $actions[] = helper::get_filler_icon();
 123          } else {
 124              $actions[] = helper::format_icon_link($step->get_moveup_link(), 't/up', get_string('movestepup', 'tool_usertours'));
 125          }
 126  
 127          if ($step->is_last_step()) {
 128              $actions[] = helper::get_filler_icon();
 129          } else {
 130              $actions[] = helper::format_icon_link($step->get_movedown_link(), 't/down',
 131                      get_string('movestepdown', 'tool_usertours'));
 132          }
 133  
 134          $actions[] = helper::format_icon_link($step->get_edit_link(), 't/edit', get_string('edit'));
 135  
 136          $actions[] = helper::format_icon_link($step->get_delete_link(), 't/delete', get_string('delete'), 'moodle', [
 137              'data-action'   => 'delete',
 138              'data-id'       => $step->get_id(),
 139          ]);
 140  
 141          return implode('&nbsp;', $actions);
 142      }
 143  }