-
Notifications
You must be signed in to change notification settings - Fork 6
/
block_helpdesk.php
179 lines (159 loc) · 6.47 KB
/
block_helpdesk.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
<?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/>.
/**
* This script extends a moodle block_base and is the entry point for all
* helpdesk ability.
*
* @package block_helpdesk
* @copyright 2010 VLACS
* @author Jonathan Doane <jdoane@vlacs.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') or die("Direct access to this location is not allowed.");
require_once("$CFG->dirroot/blocks/helpdesk/lib.php");
class block_helpdesk extends block_base {
var $hd;
/**
* Overridden block_base method. All this method does is sets the block's
* title and version.
*
* @return null
*/
function init() {
$this->title = get_string('helpdesk', 'block_helpdesk');
$this->version = 2010091400;
$this->cron = 1;
}
/**
* This overridden method gets called after the block's tables are created.
*
* @return bool
*/
function after_install() {
$hd = helpdesk::get_helpdesk();
$rval = $hd->install();
}
/**
* Overridden block_base method. This generates the content in the body of
* the block and returns it.
*
* @return string
*/
function get_content() {
global $CFG, $USER;
// Get objects initialized and variables declared.
$this->content = new stdClass;
// First thing is first, user must have some form of capbility on the
// helpdesk. Otherwise they shouldn't be able to access it.
$cap = helpdesk_is_capable();
$this->content->text = '';
$this->content->footer = '';
$noticketstr = get_string('noticketstodisplay', 'block_helpdesk');
if ($cap == false) {
return $this->content;
}
// Lets get the helpdesk initialized.
$hd = helpdesk::get_helpdesk();
// Show assigned ticket if answerer.
if ($cap == HELPDESK_CAP_ANSWER) {
$title = '<h3>' . get_string('myassignedtickets', 'block_helpdesk') . '</h3>';
$this->content->text .= $title;
$tickets = $hd->get_tickets($USER->id, $hd->get_default_relation(HELPDESK_CAP_ANSWER), 0, 5);
if (is_array($tickets)) {
$this->content->text .= "<ul>";
foreach($tickets as $ticket) {
$summary = $ticket->get_summary();
if(strlen($summary) > 12) {
$summary = substr($summary, 0, 12) . '...';
}
$url = new moodle_url("$CFG->wwwroot/blocks/helpdesk/view.php");
$url->param('id', $ticket->get_idstring());
$url = $url->out();
$this->content->text .= "<li>
<a href=\"$url\">
$summary (" . $ticket->get_status_string() . ")
</a>
</li>";
}
$this->content->text .= '</ul>';
} else {
$this->content->text .= notify($noticketstr, 'notifyproblem', 'center', true);
}
}
// Print my tickets title. Block itself just displays first 5 user
// tickets. Other tickets are found in ticket listing.
$this->content->text .= '<h3>' . get_string('mytickets', 'block_helpdesk') . '</h3>';
// Grab the tickets to display and add to the content.
$tickets = $hd->get_tickets($USER->id, $hd->get_default_relation(), 0, 5);
if (is_array($tickets)) {
$this->content->text .= '<ul>';
foreach($tickets as $ticket) {
$summary = $ticket->get_summary();
if(strlen($summary) > 12) {
$summary = substr($summary, 0, 12) . '...';
}
$url = new moodle_url("$CFG->wwwroot/blocks/helpdesk/view.php");
$url->param('id', $ticket->get_idstring());
$url = $url->out();
$this->content->text .= "<li>
<a href=\"$url\">
$summary (" . $ticket->get_status_string() . ')
</a>
</li>';
}
$this->content->text .= '</ul>';
} else {
$this->content->text .= notify($noticketstr, 'notifyproblem', 'center', true);
}
// Link for viewing all kinds of tickets.
$url = "$CFG->wwwroot/blocks/helpdesk/view.php";
$text = get_string('viewalltickets', 'block_helpdesk');
$this->content->text .= "<a href=\"$url\">$text</a><br />";
// Link for submitting a new ticket.
$url = $hd->default_submit_url()->out();
$text = get_string('submitnewticket', 'block_helpdesk');
$this->content->text .= "<a href=\"$url\">$text</a><br /><br />";
// print a footer.
$url = new moodle_url("$CFG->wwwroot/blocks/helpdesk/preferences.php");
$url = $url->out();
$translated = get_string('preferences');
$prefhelp = helpdesk_simple_helpbutton($translated, 'pref');
$this->content->footer = "<a href=\"$url\">$translated</a>$prefhelp";
return $this->content;
}
/**
* This is an overriden method. This method is called when Moodle's cron
* runs. Currently this method does nothing and returns nothing.
*
* @return null
*/
function cron() {
$hd = helpdesk::get_helpdesk();
if(!$hd->cron()) {
notify('Warning: Plugin cron returned non-true value.');
}
}
function instance_allow_multiple() {
return false;
}
function has_config() {
return true;
}
function instance_allow_config() {
return false;
}
}
?>