-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatamodel.itop-assign-to-me.xml
157 lines (141 loc) · 4.87 KB
/
datamodel.itop-assign-to-me.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">
<module_parameters>
<parameters id="itop-assign-to-me" _delta="define">
<agent_must_change type="bool">true</agent_must_change>
<allowed_classes type="hash">
<UserRequest type="hash">
<dispatched>ev_assign</dispatched>
<assigned>ev_reassign</assigned>
<redispatched>ev_assign</redispatched>
</UserRequest>
<Incident type="hash">
<dispatched>ev_assign</dispatched>
<assigned>ev_reassign</assigned>
<redispatched>ev_assign</redispatched>
</Incident>
</allowed_classes>
</parameters>
</module_parameters>
<snippets>
<snippet id="AssignToMeMenuExtension" _delta="define">
<placement>module</placement>
<rank>10</rank>
<module>itop-assign-to-me</module>
<content><![CDATA[
class AssignToMeMenuExtension implements iPopupMenuExtension {
/**
* Checks the ticket is in a state where assign to me action can be applied
*/
public static function IsActionAllowed($oTicket, $iAgentid, $sStimulus) {
$sTicketClass = get_class($oTicket);
// Check transition is valid
$aTransitions = $oTicket->EnumTransitions();
$aStimuli = MetaModel::EnumStimuli($sTicketClass);
if (!isset($aTransitions[$sStimulus])) {
return false;
}
// Check user has rights to perform the transition
if (!UserRights::IsStimulusAllowed($sTicketClass, $sStimulus)) {
return false;
}
// If agent must change, check ticket is not already assigned to me
$bAgentMustChange = MetaModel::GetModuleSetting('itop-assign-to-me', 'agent_must_change', true);
$iTicketAgentId = $oTicket->Get('agent_id');
if ($bAgentMustChange && ($iAgentid == $iTicketAgentId)) {
return false;
}
// Check agent is in current team
$iTicketTeamId = $oTicket->Get('team_id');
$bIsInTeam = false;
if (!is_null($iTicketTeamId))
{
$sOQL = "SELECT lnkPersonToTeam AS l WHERE l.person_id = :p_id AND l.team_id = :t_id";
$oLnkSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('p_id' => $iAgentid, 't_id' => $iTicketTeamId));
if ($oLnkSet->Count() > 0) {
$bIsInTeam = true;
}
}
if (!$bIsInTeam) {
return false;
}
return true;
}
public static function EnumItems($iMenuId, $param) {
switch($iMenuId) {
case iPopupMenuExtension::MENU_OBJLIST_ACTIONS:
// $param is a DBObjectSet
$aResult = array();
break;
case iPopupMenuExtension::MENU_OBJLIST_TOOLKIT:
// $param is a DBObjectSet
$aResult = array();
break;
case iPopupMenuExtension::MENU_OBJDETAILS_ACTIONS:
// $param is a DBObject
$aResult = array();
$oObj = $param;
// "Assign to me" applies to Tickets only
if ($oObj instanceof Ticket) {
$sTicketClass = get_class($oObj);
$aAllowedClasses = MetaModel::GetModuleSetting('itop-assign-to-me', 'allowed_classes', array());
foreach ($aAllowedClasses as $sAllowedClass => $aClass) {
// Check $sAllowedClass is a valid class
if (($sAllowedClass != '') && !MetaModel::IsValidClass($sAllowedClass)) {
IssueLog::Debug('Module itop-assign-to-me - invalid class #'.$sAllowedClass.' - name "'.$sAllowedClass.'" is not a valid class');
break;
}
if ($sAllowedClass == $sTicketClass) {
// Check ticket has status where event can be applied
$sTicketStatus = $oObj->Get('status');
$bIsInRightStatus = false;
foreach ($aClass as $sStatus => $sEvent) {
if ($sTicketStatus == $sStatus) {
$bIsInRightStatus = true;
$sEventToApply = $sEvent;
}
}
if ($bIsInRightStatus) {
$iAgentid = UserRights::GetContactId();
// Check that transition is allowed and that agent can apply it
if (self::IsActionAllowed($oObj, $iAgentid, $sEventToApply)) {
// Set Assign to me additional menu
$oAppContext = new ApplicationContext();
$aParams = $oAppContext->GetAsHash();
$aParams['class'] = $sTicketClass;
$aParams['id'] = $oObj->GetKey();
$aParams['operation'] = 'stimulus';
$aParams['stimulus'] = $sEventToApply;
$aParams['agent_id'] = $iAgentid;
$sMenu = 'Menu:AssignToMe';
$aResult = array(
new SeparatorPopupMenuItem(),
new URLPopupMenuItem(
$sMenu.' from '.$sTicketClass,
Dict::S($sMenu),
utils::GetAbsoluteUrlModulePage('itop-assign-to-me', 'assign-to-me.php', $aParams)
),
);
}
}
break;
}
}
}
break;
case iPopupMenuExtension::MENU_DASHBOARD_ACTIONS:
// $param is a Dashboard
$aResult = array();
break;
default:
// Unknown type of menu, do nothing
$aResult = array();
break;
}
return $aResult;
}
}
]]></content>
</snippet>
</snippets>
</itop_design>