-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib.php
157 lines (125 loc) · 4.46 KB
/
lib.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
<?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_tickets
* @copyright 2024 3bood_kr
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_tickets\lib;
/**
* Add ticket widget to footer.
*/
function local_tickets_before_footer() {
global $PAGE, $USER, $OUTPUT;
lib::init();
// Show widget for logged in users only.
if (!lib::is_logged_in()) {
return;
}
// Removed: 'maintenance', 'report'.
$excludepages = ['embedded', 'frametop', 'popup', 'print', 'redirect'];
if (!in_array($PAGE->pagelayout, $excludepages)) { // Do not show on pages that may use $OUTPUT.
$title = lib::canmanagetickets() ? get_string('manage_tickets', 'local_tickets') : get_string('my_tickets', 'local_tickets');
$PAGE->requires->js_call_amd(
'local_tickets/modaldialouge',
'init',
['[data-action=openmodaldialouge]',
$title,
],
);
$PAGE->requires->js_call_amd('local_tickets/deletepopup', 'init');
$PAGE->requires->js_call_amd(
'local_tickets/modalforms',
'modalForm',
['[data-action=opensubmitticketform]',
\local_tickets\form\submitticketform::class,
get_string('submit_ticket', 'local_tickets'),
['hidebuttons' => 1]],
);
echo $OUTPUT->render_from_template('local_tickets/widget', ['title' => $title]);
}
}
function local_tickets_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $DB;
if ($context->contextlevel != CONTEXT_SYSTEM) {
return false;
}
require_login();
// Make sure the filearea is one of those used by local_tickets plugin.
if ($filearea != 'attachment') {
return false;
}
$itemid = (int)array_shift($args);
$fs = get_file_storage();
$filename = array_pop($args);
if (empty($args)) {
$filepath = '/';
} else {
$filepath = '/'.implode('/', $args).'/';
}
$file = $fs->get_file($context->id, 'local_tickets', $filearea, $itemid, $filepath, $filename);
if (!$file) {
return false;
}
// finally send the file
send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security!
}
/**
* This is used to send filter form html
* to modaldialouge.js so it be rendered
* in modaldialouge mustache
*
* @param array $args List of named arguments for the fragment loader.
* @return string
*/
function local_tickets_output_fragment_new_filter_form($args){
global $CFG;
require_once($CFG->dirroot . '/local/tickets/classes/form/filter_tickets.php');
$filterform = new filter_tickets(null, ['hidebuttons' => 1]);
return $filterform->render();
}
/**
* Get modal dialoug HTML
*
* @param array $args List of named arguments for the fragment loader.
* @return string
*/
function local_tickets_output_fragment_rerender_modal_dialouge($args){
global $CFG, $DB, $OUTPUT;
lib::init();
$totalcount = 0;
if (lib::$caps['canmanagetickets']) {
$totalcount = lib::get_tickets_count();
}else{
$totalcount = lib::get_own_tickets_count();
}
$page = $args['page'] ?? 0;
$pager = $OUTPUT->paging_bar($totalcount, $page , get_config('local_tickets', 'ticketspagesizesetting'), '', '');
$limitfrom = ($page) * get_config('local_tickets', 'ticketspagesizesetting');
$tickets = [];
if (lib::$caps['canmanagetickets']) {
$tickets = lib::get_tickets($limitfrom);
}else{
$tickets = lib::get_own_tickets($limitfrom);
}
$template = new stdClass();
$template->tickets = $tickets;
$template->pager = $pager;
$result = $OUTPUT->render_from_template('local_tickets/modaldialouge', $template);
return $result;
}