-
Notifications
You must be signed in to change notification settings - Fork 3
/
renderer.php
188 lines (157 loc) · 7.17 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?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/>.
defined('MOODLE_INTERNAL') || die();
/**
* A custom renderer class that extends the plugin_renderer_base.
*
* @package local_trigger
* @copyright COPYRIGHTNOTICE
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_trigger_renderer extends plugin_renderer_base {
/**
* Return HTML to display add first page links
* @param lesson $lesson
* @return string
*/
public function add_edit_page_links($edittype) {
global $CFG;
$itemid = 0;
switch($edittype){
case 'webhooks':
$links = array();
$itemurl = new moodle_url('/local/trigger/managewebhooks.php',
array('itemid'=>$itemid));
$links[] = html_writer::link($itemurl, get_string('additemwebhook', "local_trigger"));
break;
case 'customactions':
$links = array();
$itemurl = new moodle_url('/local/trigger/managecustomactions.php',
array('itemid'=>$itemid));
$links[] = html_writer::link($itemurl, get_string('additemcustomaction', "local_trigger"));
break;
}
return $this->output->box('<p>'.implode('</p><p>', $links).'</p>', 'generalbox firstpageoptions');
}
public function add_customaction_sync(){
$items = array();
$itemurl = new moodle_url('/local/trigger/managecustomactions.php',
array('action'=>'sync'));
$items[] = html_writer::link($itemurl, get_string('sync_customactions', "local_trigger"),array('class'=>'btn btn-primary'));
$items[] = html_writer::span(get_string('sync_customactions_help', "local_trigger"));
return $this->output->box('<p>'.implode('</p><p>', $items).'</p>', 'generalbox firstpageoptions');
}
/**
* Return the table of items
* @param array homework objects
* @param integer $courseid
* @return string html of table
*/
function show_webhook_items_list($items){
if(!$items){
return $this->output->heading(get_string('noitems',"local_trigger"), 3, 'main');
}
$table = new html_table();
$table->id = 'local_trigger_qpanel';
$table->head = array(
get_string('event', "local_trigger"),
get_string('webhook', "local_trigger"),
get_string('description', "local_trigger"),
get_string('enabled', "local_trigger"),
get_string('actions', "local_trigger")
);
$table->headspan = array(1,1,1,1,2);
$table->colclasses = array(
'eventcol', 'webhookcol', 'descriptioncol','enabledcol', 'edit','preview','delete'
);
//sort by start date
core_collator::asort_objects_by_property($items,'timecreated',core_collator::SORT_NUMERIC);
//loop through the homoworks and add to table
foreach ($items as $item) {
$row = new html_table_row();
$eventcell = new html_table_cell($item->event);
$webhookcell = new html_table_cell($item->webhook);
$descriptioncell = new html_table_cell($item->description);
$enabledcell = $item->enabled ? new html_table_cell(get_string('yes')) : new html_table_cell(get_string('no')) ;
$actionurl = '/local/trigger/managewebhooks.php';
$editurl = new moodle_url($actionurl, array('itemid'=>$item->id));
$editlink = html_writer::link($editurl, get_string('edititem', "local_trigger"));
$editcell = new html_table_cell($editlink);
/*
$actionurl = '/local/trigger/managewebhooks.php';
$sampleurl = new moodle_url($actionurl, array('itemid'=>$item->id,'action'=>'sampledata'));
$samplelink = html_writer::link($sampleurl, 'SampleData');
$samplecell = new html_table_cell($samplelink);
*/
$deleteurl = new moodle_url($actionurl, array('itemid'=>$item->id,'action'=>'confirmdelete'));
$deletelink = html_writer::link($deleteurl, get_string('deleteitem', "local_trigger"));
$deletecell = new html_table_cell($deletelink);
$row->cells = array(
$eventcell, $webhookcell, $descriptioncell,$enabledcell, $editcell, $deletecell, // $samplecell
);
$table->data[] = $row;
}
return html_writer::table($table);
}
/**
* Return the table of items
* @param array homework objects
* @param integer $courseid
* @return string html of table
*/
function show_customaction_items_list($items){
if(!$items){
return $this->output->heading(get_string('noitems',"local_trigger"), 3, 'main');
}
$table = new html_table();
$table->id = 'local_trigger_qpanel';
$table->head = array(
get_string('customaction', "local_trigger"),
get_string('params', "local_trigger"),
get_string('description', "local_trigger"),
get_string('synced', "local_trigger"),
get_string('enabled', "local_trigger"),
get_string('actions', "local_trigger")
);
$table->headspan = array(1,1,1,1,1,2);
$table->colclasses = array(
'actioncol','paramscol', 'descriptioncol','synced','enabledcol', 'edit','preview','delete'
);
//sort by start date
core_collator::asort_objects_by_property($items,'timecreated',core_collator::SORT_NUMERIC);
//loop through the homeworks and add to table
foreach ($items as $item) {
$row = new html_table_row();
$actioncell = new html_table_cell($item->action);
$paramscell = new html_table_cell(shorten_text ($item->params, 50));
$descriptioncell = new html_table_cell($item->description);
$enabledcell = $item->enabled ? new html_table_cell(get_string('yes')) : new html_table_cell(get_string('no')) ;
$syncedcell = new html_table_cell($item->needs_sync ? '<i class="fa fa-times"></i>' : '<i class="fa fa-check"></i>');
$actionurl = '/local/trigger/managecustomactions.php';
$editurl = new moodle_url($actionurl, array('itemid'=>$item->id));
$editlink = html_writer::link($editurl, get_string('edititem', "local_trigger"));
$editcell = new html_table_cell($editlink);
$deleteurl = new moodle_url($actionurl, array('itemid'=>$item->id,'action'=>'confirmdelete'));
$deletelink = html_writer::link($deleteurl, get_string('deleteitem', "local_trigger"));
$deletecell = new html_table_cell($deletelink);
$row->cells = array(
$actioncell, $paramscell, $descriptioncell,$syncedcell,$enabledcell, $editcell, $deletecell
);
$table->data[] = $row;
}
return html_writer::table($table);
}
}