-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathShowtabitem.php
More file actions
204 lines (197 loc) Β· 8.73 KB
/
Showtabitem.php
File metadata and controls
204 lines (197 loc) Β· 8.73 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* -------------------------------------------------------------------------
* Example plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Example.
*
* Example 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 2 of the License, or
* (at your option) any later version.
*
* Example 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 Example. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2006-2022 by Example plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/example
* -------------------------------------------------------------------------
*/
namespace GlpiPlugin\Example;
/**
* Summary of GlpiPlugin\Example\Showtabitem
* Example of pre_show_xxx and post_show_xxx implementation
*
*
* pre_show_item will be fired before an item is shown
* ex: when viewing a ticket, change, computer,...
*
* will be fired at each sub-item
* ex: for each TicketTask, ITILFollowup, ...
*
* post_show_item will be fired after the item show
*
*
* pre_show_tab will be fired before a tab is shown
* when tabs are loaded,
* ex: when viewing the Followup tab
*
* post_show_tab will be fired after the tab show
*
* */
class Showtabitem
{
/**
* Summary of pre_show_tab
* @param array $params is an array like following
* array( 'item', 'options')
* where 'item' is the parent object (like 'Ticket'),
* and 'options' are options like following
* array( 'tabnum', 'itemtype')
* where 'tabnum' is the internal name of the tab that will be shown
* and 'itemtype' is the type of the tab (ex: 'ITILFollowup' when showing followup tab in a ticket)
* Note: you may pass datas to post_show_tab using the $param['options'] array (see example below)
*/
public static function pre_show_tab($params)
{
switch ($params['item']->getType()) {
case 'Ticket':
// if tasks are not all done
// then prevent solution div to show
// this is an example to prevent solving of ticket
if ($params['options']['itemtype'] == 'TicketValidation' && $params['options']['tabnum'] == 2 && true) {
// here you should test if some tasks are in todo status.
$params['options']['prevent_solution'] = true;
// this will be passed to the post_show hook
echo "<div id='toHideSolution' style='display: none;'>";
// in order to hide the default solution div
}
}
}
/**
* Summary of post_show_tab
* @param array $params is identical to pre_show_tab parameter
* Note: you may get datas from pre_show_tab in $param['options'] array (see example below)
*/
public static function post_show_tab($params)
{
switch ($params['item']->getType()) {
case 'Ticket':
if (isset($params['options']['prevent_solution'])) {
echo '</div>';
echo "<div style='margin-bottom: 20px;' class='box'>
<div class='box-tleft'>
<div class='box-tright'>
<div class='box-tcenter'>
</div>
</div>
</div>
<div class='box-mleft'>
<div class='box-mright'>
<div class='box-mcenter'>
<h3>
<span class='red'>" . "Can't solve ticket" . '
<br>
</span>
</h3>
<h3>
<span >' . 'Tasks are waiting to be done' . "
</span>
</h3>
</div>
</div>
</div>
<div class='box-bleft'>
<div class='box-bright'>
<div class='box-bcenter'>
</div>
</div>
</div>
</div> ";
}
break;
case 'Computer':
break;
}
}
/**
* Summary of pre_show_item
* @param array $params is an array like following
* array( 'item', 'options')
* where 'item' is the object to show (like 'Ticket', 'TicketTask', ...),
* BEWARE that sometimes it can be an array of data and not an object (ex: for solution item)
* and 'options' are options like following
* if item is a main object like a ticket, change, problem, ... then it contains
* array( 'id' )
* where 'id' is the id of object that will be shown (same than $param['item']->fields['id'])
* or if item contains a sub-object like followup, task, ... then it contains
* array( 'parent', 'rand', 'showprivate')
* where 'parent' is the main object related to the current item (ex: if 'item' is ITILFollowup then it will be the related Ticket)
* and 'rand' contains the random number that will be used to render the item
* and 'showprivate' is the right to show private items
* Note: you may pass datas to post_show_item using the $param['options'] array
*/
public static function pre_show_item($params)
{
if (!is_array($params['item'])) {
switch ($params['item']->getType()) {
case 'Ticket':
//echo 'test' ;
break;
case 'TicketTask':
//echo 'test' ;
break;
case 'ITILFollowup':
//echo 'test' ;
break;
}
} else {
// here we are going to view a Solution
return;
}
}
/**
* Summary of post_show_item
* @param array $params is an array like following
* array( 'item', 'options')
* where 'item' is the object to show (like 'Ticket', 'TicketTask', ...),
* and 'options' are options like following
* if item is a main object like a ticket, change, problem, ... then it contains
* array( 'id' )
* where 'id' is the id of object that will be shown (same than $param['item']->fields['id'])
* or if item contains a sub-object like followup, task, ... then it contains
* array( 'parent', 'rand', 'showprivate')
* where 'parent' is the main object related to the current item (ex: if 'item' is ITILFollowup then it will be the related Ticket)
* and 'rand' contains the random number that will be used to render the item
* and 'showprivate' is the right to show private items
* Note: you may get datas from pre_show_item using the $param['options'] array
*/
public static function post_show_item($params)
{
if (!is_array($params['item'])) {
switch ($params['item']->getType()) {
case 'Ticket':
//echo 'test' ;
break;
case 'TicketTask':
//echo 'test' ;
break;
case 'ITILFollowup':
//echo 'test' ;
break;
}
} else {
// here we are going to view a Solution
return;
}
}
}