-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspreader.php
61 lines (53 loc) · 2.1 KB
/
spreader.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
<?php
/**
* osTicket plugin for spreading tickets between manager using round-robin algorithm
* @author Alexey Berezuev <[email protected]>
* @license http://opensource.org/licenses/MIT
* @version 0.1
*/
require_once(INCLUDE_DIR . 'class.plugin.php');
require_once(INCLUDE_DIR . 'class.signal.php');
require_once(INCLUDE_DIR . 'class.app.php');
require_once('config.php');
class SpreaderPlugin extends Plugin {
var $config_class = 'SpreaderConfig';
private static $config;
function bootstrap() {
self::$config = self::getConfig();
if (!self::$config->get('spreader_current_staff')) {
self::$config->set('spreader_current_staff', 0);
}
$object = Signal::connect('ticket.created', array('SpreaderPlugin', 'spreadTicket'));
}
function getCurrentStaffId() {
$staff = self::$config->getStaffList();
$plugin_staff = array();
$current_staff = self::$config->get('spreader_current_staff');
foreach ($staff as $id => $fullname) {
if(self::$config->get("spreader_staff_id_".$id)){
array_push($plugin_staff, $id);
}
}
$current = $plugin_staff[$current_staff];
$spreader_current_staff = ($current_staff < (count($plugin_staff) - 1))
? self::$config->get('spreader_current_staff')+1
: 0;
self::$config->set('spreader_current_staff', $spreader_current_staff);
return $current;
}
function isCategorySelected($cid) {
return self::$config->get("spreader_category_id_{$cid}");
}
function spreadTicket($object, $data){
if (get_class($object) === 'Ticket') {
$cid = $object->getTopicId();
self::$config = self::getConfig();
if (self::isCategorySelected($cid)){
$staff_id = self::getCurrentStaffId();
$object->assignToStaff($staff_id, 'Auto assigning', true);
return true;
}
}
return false;
}
}