1 |
efrain |
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 |
/** @var int The count of all tours. */
|
|
|
42 |
protected int $tourcount = 0;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Construct the tour table.
|
|
|
46 |
*/
|
|
|
47 |
public function __construct() {
|
|
|
48 |
parent::__construct('tours');
|
|
|
49 |
|
|
|
50 |
$baseurl = new \moodle_url('/tool/usertours/configure.php');
|
|
|
51 |
$this->define_baseurl($baseurl);
|
|
|
52 |
|
|
|
53 |
// Column definition.
|
|
|
54 |
$this->define_columns([
|
|
|
55 |
'name',
|
|
|
56 |
'description',
|
|
|
57 |
'appliesto',
|
|
|
58 |
'enabled',
|
|
|
59 |
'actions',
|
|
|
60 |
]);
|
|
|
61 |
|
|
|
62 |
$this->define_headers([
|
|
|
63 |
get_string('name', 'tool_usertours'),
|
|
|
64 |
get_string('description', 'tool_usertours'),
|
|
|
65 |
get_string('appliesto', 'tool_usertours'),
|
|
|
66 |
get_string('enabled', 'tool_usertours'),
|
|
|
67 |
get_string('actions', 'tool_usertours'),
|
|
|
68 |
]);
|
|
|
69 |
|
|
|
70 |
$this->set_attribute('class', 'admintable generaltable');
|
|
|
71 |
$this->setup();
|
|
|
72 |
|
|
|
73 |
$this->tourcount = helper::count_tours();
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Format the current row's name column.
|
|
|
78 |
*
|
|
|
79 |
* @param tour $tour The tour for this row.
|
|
|
80 |
* @return string
|
|
|
81 |
*/
|
|
|
82 |
protected function col_name(tour $tour) {
|
|
|
83 |
global $OUTPUT;
|
|
|
84 |
return $OUTPUT->render(helper::render_tourname_inplace_editable($tour));
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Format the current row's description column.
|
|
|
89 |
*
|
|
|
90 |
* @param tour $tour The tour for this row.
|
|
|
91 |
* @return string
|
|
|
92 |
*/
|
|
|
93 |
protected function col_description(tour $tour) {
|
|
|
94 |
global $OUTPUT;
|
|
|
95 |
return $OUTPUT->render(helper::render_tourdescription_inplace_editable($tour));
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* Format the current row's appliesto column.
|
|
|
100 |
*
|
|
|
101 |
* @param tour $tour The tour for this row.
|
|
|
102 |
* @return string
|
|
|
103 |
*/
|
|
|
104 |
protected function col_appliesto(tour $tour) {
|
|
|
105 |
return $tour->get_pathmatch();
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
/**
|
|
|
109 |
* Format the current row's enabled column.
|
|
|
110 |
*
|
|
|
111 |
* @param tour $tour The tour for this row.
|
|
|
112 |
* @return string
|
|
|
113 |
*/
|
|
|
114 |
protected function col_enabled(tour $tour) {
|
|
|
115 |
global $OUTPUT;
|
|
|
116 |
return $OUTPUT->render(helper::render_tourenabled_inplace_editable($tour));
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
* Format the current row's actions column.
|
|
|
121 |
*
|
|
|
122 |
* @param tour $tour The tour for this row.
|
|
|
123 |
* @return string
|
|
|
124 |
*/
|
|
|
125 |
protected function col_actions(tour $tour) {
|
|
|
126 |
$actions = [];
|
|
|
127 |
|
|
|
128 |
if ($tour->is_first_tour()) {
|
|
|
129 |
$actions[] = helper::get_filler_icon();
|
|
|
130 |
} else {
|
|
|
131 |
$actions[] = helper::format_icon_link(
|
|
|
132 |
$tour->get_moveup_link(),
|
|
|
133 |
't/up',
|
|
|
134 |
get_string('movetourup', 'tool_usertours')
|
|
|
135 |
);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
if ($tour->is_last_tour($this->tourcount)) {
|
|
|
139 |
$actions[] = helper::get_filler_icon();
|
|
|
140 |
} else {
|
|
|
141 |
$actions[] = helper::format_icon_link(
|
|
|
142 |
$tour->get_movedown_link(),
|
|
|
143 |
't/down',
|
|
|
144 |
get_string('movetourdown', 'tool_usertours')
|
|
|
145 |
);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
$actions[] = helper::format_icon_link($tour->get_view_link(), 't/viewdetails', get_string('view'));
|
|
|
149 |
$actions[] = helper::format_icon_link($tour->get_edit_link(), 't/edit', get_string('edit'));
|
|
|
150 |
$actions[] = helper::format_icon_link($tour->get_duplicate_link(), 't/copy', get_string('duplicate'));
|
|
|
151 |
$actions[] = helper::format_icon_link(
|
|
|
152 |
$tour->get_export_link(),
|
|
|
153 |
't/export',
|
|
|
154 |
get_string('exporttour', 'tool_usertours'),
|
|
|
155 |
'tool_usertours'
|
|
|
156 |
);
|
|
|
157 |
$actions[] = helper::format_icon_link($tour->get_delete_link(), 't/delete', get_string('delete'), null, [
|
|
|
158 |
'data-action' => 'delete',
|
|
|
159 |
'data-id' => $tour->get_id(),
|
|
|
160 |
]);
|
|
|
161 |
|
|
|
162 |
return implode(' ', $actions);
|
|
|
163 |
}
|
|
|
164 |
}
|