-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclassificationvalues.php
More file actions
179 lines (147 loc) · 7.39 KB
/
classificationvalues.php
File metadata and controls
179 lines (147 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Allows editing taxons in the taxonomy source table.
* In first approach, is limited to the sharedresource_taxonomy internal table.
*
* @package mod_sharedresource
* @author Valery Fremaux <valery.fremaux@gmail.com>
* @copyright Valery Fremaux (activeprolearn.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require('../../config.php');
require_once($CFG->dirroot.'/mod/sharedresource/lib.php');
require_once($CFG->dirroot.'/local/sharedresources/classes/navigator.class.php');
$id = optional_param('id', 0, PARAM_TEXT); // The classification id.
$parent = optional_param('parent', 0, PARAM_TEXT); // The parent id.
$action = optional_param('what', '', PARAM_TEXT); // The controller action.
// Security.
$systemcontext = context_system::instance();
require_login();
require_capability('repository/sharedresources:manage', $systemcontext);
// Build page.
$url = new moodle_url('/mod/sharedresource/classificationvalues.php', ['id' => $id, 'parent' => $parent]);
$PAGE->set_url($url);
$PAGE->set_context($systemcontext);
$PAGE->set_title($SITE->fullname);
$PAGE->set_heading($SITE->fullname);
$PAGE->set_pagelayout('standard');
if (!empty($action)) {
include($CFG->dirroot.'/mod/sharedresource/classificationvalues.controller.php');
$controller = new \mod_sharedresource\classification\classificationvalues_controller();
$controller->receive($action);
$controller->process($action);
redirect(new moodle_url('/mod/sharedresource/classificationvalues.php', ['id' => $id, 'parent' => $parent]));
}
$classification = $DB->get_record('sharedresource_classif', ['id' => $id]);
if ($parent) {
$parenttoken = $DB->get_record('sharedresource_taxonomy', ['id' => $parent]);
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('classificationvalues', 'sharedresource'));
echo $OUTPUT->heading(get_string('classification', 'sharedresource').' '.format_string($classification->name), 3);
if ($classification->tablename != 'sharedresource_taxonomy') {
echo $OUTPUT->notification(get_string('notsupportedyet', 'sharedresource'));
} else {
$navigation = new \local_sharedresources\browser\navigation($classification);
if ($parent == 0) {
$params = ['classificationid' => $id, 'parent' => 0];
$tokens = $DB->get_records('sharedresource_taxonomy', $params, 'sortorder');
} else {
$tokens = $navigation->get_children($parent);
}
$table = new html_table();
$tokenstr = get_string('token', 'sharedresource');
$table->head = [$tokenstr, ''];
$table->width = '100%';
$table->size = ['70%', '30%'];
$table->align = ['left', 'right'];
$attrs = ['class' => 'mod-sharedresource-tokens-ctl'];
$editicon = $OUTPUT->pix_icon('t/edit', get_string('edit'), 'core', $attrs);
$attrs = ['class' => 'mod-sharedresource-tokens-ctl'];
$deleteicon = $OUTPUT->pix_icon('t/delete', get_string('delete'), 'core', $attrs);
$attrs = ['class' => 'mod-sharedresource-tokens-ctl'];
$upicon = $OUTPUT->pix_icon('t/up', '', 'core', $attrs);
$attrs = ['class' => 'mod-sharedresource-tokens-ctl'];
$downicon = $OUTPUT->pix_icon('t/down', '', 'core', $attrs);
foreach ($tokens as $tk) {
$data = [];
$params = ['parent' => $tk->id, 'id' => $id];
$suburl = new moodle_url('/mod/sharedresource/classificationvalues.php', $params);
$tokenstr = '';
if (!empty($tk->idnumber)) {
$tokenstr .= '['.$tk->idnumber.']';
}
$tokenstr .= '<a href="'.$suburl.'">'.$tk->value.'</a> ';
$children = count($navigation->get_children($tk->id));
if ($children) {
$tokenstr .= '('.$children.')';
}
$data[] = $tokenstr;
$cmds = '';
$params = ['classificationid' => $id, 'id' => $tk->id, 'parent' => $parent];
$editurl = new moodle_url('/mod/sharedresource/classificationvalue.php', $params);
$attrs = ['alt' => get_string('update'),
'title' => get_string('update')];
$cmds .= ' '.html_writer::link($editurl, $editicon, $attrs);
$params = ['what' => 'delete', 'tokenid' => $tk->id, 'id' => $id, 'parent' => $parent, 'sesskey' => sesskey()];
$deleteurl = new moodle_url('/mod/sharedresource/classificationvalues.php', $params);
$attrs = ['alt' => get_string('delete', 'sharedresource'),
'title' => get_string('delete', 'sharedresource')];
$cmds .= ' '.html_writer::link($deleteurl, $deleteicon, $attrs);
if ($tk->sortorder > 1) {
$params = ['what' => 'up', 'tokenid' => $tk->id, 'id' => $id, 'parent' => $parent, 'sesskey' => sesskey()];
$upurl = new moodle_url('/mod/sharedresource/classificationvalues.php', $params);
$attrs = ['alt' => get_string('up', 'sharedresource'),
'title' => get_string('up', 'sharedresource')];
$cmds .= ' '.html_writer::link($upurl, $upicon, $attrs);
}
$select = " parent = ? AND classificationid = ? ";
$params = [$tk->parent, $id];
$maxsortorder = $DB->get_field_select('sharedresource_taxonomy', " MAX(sortorder) ", $select, $params);
if ($tk->sortorder < $maxsortorder) {
$params = ['what' => 'down', 'tokenid' => $tk->id, 'id' => $id, 'parent' => $parent, 'sesskey' => sesskey()];
$downurl = new moodle_url('/mod/sharedresource/classificationvalues.php', $params);
$attrs = ['alt' => get_string('down', 'sharedresource'),
'title' => get_string('down', 'sharedresource')];
$cmds .= ' '.html_writer::link($downurl, $downicon, $attrs);
}
$data[] = $cmds;
$table->data[] = $data;
}
if ($parent) {
echo '<div class="parent-link">';
$params = ['id' => $id, 'parent' => $parenttoken->parent];
$upurl = new moodle_url('/mod/sharedresource/classificationvalues.php', $params);
echo html_writer::tag('a', get_string('goup', 'sharedresource'), ['href' => $upurl]);
echo '</div>';
}
if (!empty($parent)) {
echo '<div class="navigation-up-path">';
echo $navigation->get_printable_taxon_path($parent);
echo '</div>';
}
echo html_writer::table($table);
echo '<div style="text-align:right">';
$params = ['classificationid' => $id, 'parent' => $parent];
$addurl = new moodle_url('/mod/sharedresource/classificationvalue.php', $params);
echo $OUTPUT->single_button($addurl, get_string('addtoken', 'sharedresource'));
echo '</div>';
}
$label = get_string('backtoclassifications', 'sharedresource');
$buttonurl = new moodle_url('/mod/sharedresource/classifications.php');
echo $OUTPUT->single_button($buttonurl, $label);
echo $OUTPUT->footer();