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 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 |
* @var int $tourid The id of the tour.
|
|
|
44 |
*/
|
|
|
45 |
protected $tourid;
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Construct the table for the specified tour ID.
|
|
|
49 |
*
|
|
|
50 |
* @param int $tourid The id of the tour.
|
|
|
51 |
*/
|
|
|
52 |
public function __construct($tourid) {
|
|
|
53 |
parent::__construct('steps');
|
|
|
54 |
$this->tourid = $tourid;
|
|
|
55 |
|
|
|
56 |
$baseurl = new \moodle_url('/tool/usertours/configure.php', [
|
|
|
57 |
'id' => $tourid,
|
|
|
58 |
]);
|
|
|
59 |
$this->define_baseurl($baseurl);
|
|
|
60 |
|
|
|
61 |
// Column definition.
|
|
|
62 |
$this->define_columns([
|
|
|
63 |
'title',
|
|
|
64 |
'content',
|
|
|
65 |
'target',
|
|
|
66 |
'actions',
|
|
|
67 |
]);
|
|
|
68 |
|
|
|
69 |
$this->define_headers([
|
|
|
70 |
get_string('title', 'tool_usertours'),
|
|
|
71 |
get_string('content', 'tool_usertours'),
|
|
|
72 |
get_string('target', 'tool_usertours'),
|
|
|
73 |
get_string('actions', 'tool_usertours'),
|
|
|
74 |
]);
|
|
|
75 |
|
|
|
76 |
$this->set_attribute('class', 'admintable generaltable steptable');
|
|
|
77 |
$this->setup();
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Format the current row's title column.
|
|
|
82 |
*
|
|
|
83 |
* @param step $step The step for this row.
|
|
|
84 |
* @return string
|
|
|
85 |
*/
|
|
|
86 |
protected function col_title(step $step) {
|
|
|
87 |
global $OUTPUT;
|
|
|
88 |
return $OUTPUT->render(helper::render_stepname_inplace_editable($step));
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Format the current row's content column.
|
|
|
93 |
*
|
|
|
94 |
* @param step $step The step for this row.
|
|
|
95 |
* @return string
|
|
|
96 |
*/
|
|
|
97 |
protected function col_content(step $step) {
|
|
|
98 |
$content = $step->get_content();
|
|
|
99 |
$systemcontext = \context_system::instance();
|
|
|
100 |
$content = file_rewrite_pluginfile_urls(
|
|
|
101 |
$content,
|
|
|
102 |
'pluginfile.php',
|
|
|
103 |
$systemcontext->id,
|
|
|
104 |
'tool_usertours',
|
|
|
105 |
'stepcontent',
|
|
|
106 |
$step->get_id()
|
|
|
107 |
);
|
|
|
108 |
|
|
|
109 |
$content = helper::get_string_from_input($content);
|
|
|
110 |
$content = step::get_step_image_from_input($content);
|
|
|
111 |
|
|
|
112 |
return format_text($content, $step->get_contentformat());
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* Format the current row's target column.
|
|
|
117 |
*
|
|
|
118 |
* @param step $step The step for this row.
|
|
|
119 |
* @return string
|
|
|
120 |
*/
|
|
|
121 |
protected function col_target(step $step) {
|
|
|
122 |
return $step->get_target()->get_displayname();
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
* Format the current row's actions column.
|
|
|
127 |
*
|
|
|
128 |
* @param step $step The step for this row.
|
|
|
129 |
* @return string
|
|
|
130 |
*/
|
|
|
131 |
protected function col_actions(step $step) {
|
|
|
132 |
$actions = [];
|
|
|
133 |
|
|
|
134 |
if ($step->is_first_step()) {
|
|
|
135 |
$actions[] = helper::get_filler_icon();
|
|
|
136 |
} else {
|
|
|
137 |
$actions[] = helper::format_icon_link($step->get_moveup_link(), 't/up', get_string('movestepup', 'tool_usertours'));
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
if ($step->is_last_step()) {
|
|
|
141 |
$actions[] = helper::get_filler_icon();
|
|
|
142 |
} else {
|
|
|
143 |
$actions[] = helper::format_icon_link(
|
|
|
144 |
$step->get_movedown_link(),
|
|
|
145 |
't/down',
|
|
|
146 |
get_string('movestepdown', 'tool_usertours')
|
|
|
147 |
);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
$actions[] = helper::format_icon_link($step->get_edit_link(), 't/edit', get_string('edit'));
|
|
|
151 |
|
|
|
152 |
$actions[] = helper::format_icon_link($step->get_delete_link(), 't/delete', get_string('delete'), 'moodle', [
|
|
|
153 |
'data-action' => 'delete',
|
|
|
154 |
'data-id' => $step->get_id(),
|
|
|
155 |
]);
|
|
|
156 |
|
|
|
157 |
return implode(' ', $actions);
|
|
|
158 |
}
|
|
|
159 |
}
|