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 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   * Table to show the list of tours.
  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  
  32  require_once($CFG->libdir . '/tablelib.php');
  33  
  34  /**
  35   * Table to show the list of tours.
  36   *
  37   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class tour_list extends \flexible_table {
  41      /**
  42       * Construct the tour table.
  43       */
  44      public function __construct() {
  45          parent::__construct('tours');
  46  
  47          $baseurl = new \moodle_url('/tool/usertours/configure.php');
  48          $this->define_baseurl($baseurl);
  49  
  50          // Column definition.
  51          $this->define_columns(array(
  52              'name',
  53              'description',
  54              'appliesto',
  55              'enabled',
  56              'actions',
  57          ));
  58  
  59          $this->define_headers(array(
  60              get_string('name', 'tool_usertours'),
  61              get_string('description', 'tool_usertours'),
  62              get_string('appliesto', 'tool_usertours'),
  63              get_string('enabled', 'tool_usertours'),
  64              get_string('actions', 'tool_usertours'),
  65          ));
  66  
  67          $this->set_attribute('class', 'admintable generaltable');
  68          $this->setup();
  69  
  70          $this->tourcount = helper::count_tours();
  71      }
  72  
  73      /**
  74       * Format the current row's name column.
  75       *
  76       * @param   tour    $tour       The tour for this row.
  77       * @return  string
  78       */
  79      protected function col_name(tour $tour) {
  80          global $OUTPUT;
  81          return $OUTPUT->render(helper::render_tourname_inplace_editable($tour));
  82      }
  83  
  84      /**
  85       * Format the current row's description column.
  86       *
  87       * @param   tour    $tour       The tour for this row.
  88       * @return  string
  89       */
  90      protected function col_description(tour $tour) {
  91          global $OUTPUT;
  92          return $OUTPUT->render(helper::render_tourdescription_inplace_editable($tour));
  93      }
  94  
  95      /**
  96       * Format the current row's appliesto column.
  97       *
  98       * @param   tour    $tour       The tour for this row.
  99       * @return  string
 100       */
 101      protected function col_appliesto(tour $tour) {
 102          return $tour->get_pathmatch();
 103      }
 104  
 105      /**
 106       * Format the current row's enabled column.
 107       *
 108       * @param   tour    $tour       The tour for this row.
 109       * @return  string
 110       */
 111      protected function col_enabled(tour $tour) {
 112          global $OUTPUT;
 113          return $OUTPUT->render(helper::render_tourenabled_inplace_editable($tour));
 114      }
 115  
 116      /**
 117       * Format the current row's actions column.
 118       *
 119       * @param   tour    $tour       The tour for this row.
 120       * @return  string
 121       */
 122      protected function col_actions(tour $tour) {
 123          $actions = [];
 124  
 125          if ($tour->is_first_tour()) {
 126              $actions[] = helper::get_filler_icon();
 127          } else {
 128              $actions[] = helper::format_icon_link($tour->get_moveup_link(), 't/up',
 129                      get_string('movetourup', 'tool_usertours'));
 130          }
 131  
 132          if ($tour->is_last_tour($this->tourcount)) {
 133              $actions[] = helper::get_filler_icon();
 134          } else {
 135              $actions[] = helper::format_icon_link($tour->get_movedown_link(), 't/down',
 136                      get_string('movetourdown', 'tool_usertours'));
 137          }
 138  
 139          $actions[] = helper::format_icon_link($tour->get_view_link(), 't/viewdetails', get_string('view'));
 140          $actions[] = helper::format_icon_link($tour->get_edit_link(), 't/edit', get_string('edit'));
 141          $actions[] = helper::format_icon_link($tour->get_duplicate_link(), 't/copy', get_string('duplicate'));
 142          $actions[] = helper::format_icon_link($tour->get_export_link(), 't/export',
 143                  get_string('exporttour', 'tool_usertours'), 'tool_usertours');
 144          $actions[] = helper::format_icon_link($tour->get_delete_link(), 't/delete', get_string('delete'), null, [
 145                  'data-action'   => 'delete',
 146                  'data-id'       => $tour->get_id(),
 147              ]);
 148  
 149          return implode('&nbsp;', $actions);
 150      }
 151  }