-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenderer.php
162 lines (137 loc) · 6.15 KB
/
renderer.php
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
<?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/>.
/**
* @package local_vmoodle
* @category local
*/
defined('MOODLE_INTERNAL') || die;
class local_vmoodle_renderer extends plugin_renderer_base {
public function image_url($image, $subplugin = null) {
global $CFG;
if ($subplugin == 'moodle' || $subplugin == 'core') {
return $this->output->image_url($image, 'moodle');
}
if (!$subplugin) {
return $this->output->image_url($image, 'local_vmoodle');
}
list($type, $plugin) = explode('_', $subplugin);
$parts = pathinfo($image);
$filepath = $CFG->dirroot.'/local/vmoodle/plugins/'.$plugin.'/pix/'.$parts['filename'];
// We do not support SVG.
$realpath = local_vmoodle_renderer::image_exists($filepath, false);
$parts = pathinfo($realpath);
return $CFG->wwwroot.'/local/vmoodle/plugins/'.$plugin.'/pix/'.$parts['filename'].'.'.$parts['extension'];
}
public function tabs($view) {
assert(true);
}
/**
* Checks if file with any image extension exists.
*
* The order to these images was adjusted prior to the release of 2.4
* At that point the were the following image counts in Moodle core:
*
* - png = 667 in pix dirs (1499 total)
* - gif = 385 in pix dirs (606 total)
* - jpg = 62 in pix dirs (74 total)
* - jpeg = 0 in pix dirs (1 total)
*
* There is work in progress to move towards SVG presently hence that has been prioritiesed.
*
* @param string $filepath
* @param bool $svg If set to true SVG images will also be looked for.
* @return string image name with extension
*/
private static function image_exists($filepath, $svg = false) {
if ($svg && file_exists("$filepath.svg")) {
return "$filepath.svg";
} else if (file_exists("$filepath.png")) {
return "$filepath.png";
} else if (file_exists("$filepath.gif")) {
return "$filepath.gif";
} else if (file_exists("$filepath.jpg")) {
return "$filepath.jpg";
} else if (file_exists("$filepath.jpeg")) {
return "$filepath.jpeg";
} else {
return false;
}
}
/**
* Print the start of a collapsable block.
* @param string $id The id of the block.
* @param string $caption The caption of the block.
* @param string $content The HTMLcontent of the block.
* @param string $classes The CSS classes of the block.
* @param string $displayed True if the block is displayed by default, false otherwise.
*/
public function collapsable_block($id, $caption, $content, $classes = '', $displayed = true) {
static $i = 0;
$i++;
$template = new StdClass();
$template->id = $id;
$template->i = $i;
$template->caption = $caption;
$template->captionnotags = strip_tags($caption);
$pixpath = ($displayed) ? '/t/expanded' : '/t/collapsed';
$template->pixpathurl = $this->image_url($pixpath, 'core');
$template->showctlalt = ($displayed) ? get_string('hide') : get_string('show');
$template->hideclass = ($displayed) ? '' : ' vmoodle-hidden';
$template->blockcontent = $content;
return $this->output->render_from_template('local_vmoodle/collapsibleblock', $template);
}
public function namefilter($current) {
$template = new StdClass;
$template->namefilter = $current;
$template->filterurl = new moodle_url('/local/vmoodle/view.php', ['view' => 'management', 'what' => 'list', 'vpage' => 0]);
return $this->output->render_from_template('local_vmoodle/namefilter', $template);
}
public function success_hosts_report($hosts, $command) {
$template = new StdClass;
$i = 0;
foreach ($hosts as $hostroot => $hostname) {
$hosttpl = new StdClass;
$hosttpl->i = $i;
$hosttpl->hostname = $hostname;
$status = $command->get_result($hostroot, 'status');
$hosttpl->rpcstatus = get_string('rpcstatus'.$status, 'local_vmoodle');
$hosttpl->resultmessage = $command->get_result($hostroot, 'message');
$template->hosts[] = $hosttpl;
$i = ($i + 1) % 2;
}
return $this->output->render_from_template('local_vmoodle/success_hosts_report', $template);
}
public function failed_hosts_report($hosts, $command) {
$template = new StdClass;
$i = 0;
foreach ($hosts as $hostroot => $hostname) {
$hosttpl = new StdClass;
$hosttpl->i = $i;
$hosttpl->hostname = $hostname;
$hosttpl->rpcstatus = get_string('rpcstatus'.$command->get_result($hostroot, 'status'), 'local_vmoodle');
if ($command->get_result($hostroot, 'status') > 200 && $command->get_result($hostroot, 'status') < 520) {
$params = array('view' => 'sadmin', 'what' => 'runcmdagain', 'platform' => urlencode($hostroot));
$btnurl = new moodle_url('view.php', $params);
$label = get_string('runcmdagain', 'local_vmoodle');
$hosttpl->runagainbutton = $this->output->single_button($btnurl, $label, 'get');
}
$hosttpl->errors = implode('<br/>', $command->get_result($hostroot, 'errors'));
$template->hosts[] = $hosttpl;
$i = ($i + 1) % 2;
}
return $this->output->render_from_template('local_vmoodle/failed_hosts_report', $template);
}
}