Skip to content

Commit 7eca946

Browse files
committed
Twig for Ticket
1 parent 156ce3a commit 7eca946

2 files changed

Lines changed: 171 additions & 116 deletions

File tree

src/Ticket.php

Lines changed: 17 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use CommonITILObject;
3737
use CommonGLPI;
3838
use Dropdown;
39+
use Glpi\Application\View\TemplateRenderer;
3940
use Group;
4041
use Group_Ticket;
4142
use Group_User;
@@ -183,129 +184,29 @@ public function showFormMcv($ticket)
183184
}
184185

185186

186-
$id_ticket = $ticket->getID();
187-
$id_user = $_SESSION["glpiID"];
188-
189-
echo "<form action='" . $this->getFormURL() . "' method='post'>";
190-
echo "<div class='card'>";
191-
192-
echo "<div class='card-header'>";
193-
echo "<h3 class='card-title'>";
194-
echo __('Transfer the ticket', 'transferticketentity')." - ".$entity->getName();
195-
echo "</h3>";
196-
echo "</div>";
197-
198-
echo "<div class='card-body'>";
199-
echo "<div class='card-text'>";
200-
201-
echo "<p class='alert alert-warning'>" . __(
202-
"Once the transfer has been completed, the ticket will remain visible only if you have the required rights.",
203-
"transferticketentity"
204-
) . "</p>";
205-
206-
echo "<div class='form-field row align-items-center col-12 col-sm-12 mb-2 tt_entity_choice'>";
207-
echo "<label class='col-form-label col-xxl-5 text-xxl-end' for='entity_choice'>" . __(
208-
"Select ticket entity to transfer",
209-
"transferticketentity"
210-
);
211-
echo "</label>";
212-
213-
echo "<div class='col-xxl-7 field-container'>";
214-
$entities[0] = Dropdown::EMPTY_VALUE;
215-
foreach ($getEntitiesRights as $entity) {
216-
if ($entity['allow_transfer']) {
217-
$entities[$entity['entities_id']] = $entity['name'];
187+
$entities_selection[0] = Dropdown::EMPTY_VALUE;
188+
foreach ($getEntitiesRights as $getEntitiesRight) {
189+
if ($getEntitiesRight['allow_transfer']) {
190+
$entities_selection[$getEntitiesRight['entities_id']] = $getEntitiesRight['name'];
218191
}
219192
}
220-
$rand = Dropdown::showFromArray(
221-
'entity_choice',
222-
$entities,
223-
);
224193

225-
Ajax::updateItemOnSelectEvent(
226-
"dropdown_entity_choice$rand",
227-
"show_entitygroup",
228-
PLUGIN_TRANSFERTICKETENTITY_FULLWEBDIR . "/ajax/showentitygroups.php",
229-
[
230-
'entity_selection' => '__VALUE__',
231-
]
232-
);
194+
$target = $this->getFormURL();
233195

234-
Ajax::updateItemOnSelectEvent(
235-
"dropdown_entity_choice$rand",
236-
"showmandatoryjustification",
237-
PLUGIN_TRANSFERTICKETENTITY_FULLWEBDIR . "/ajax/showentitymandatoryjustification.php",
196+
TemplateRenderer::getInstance()->display(
197+
'@transferticketentity/ticket.html.twig',
238198
[
239-
'entity_selection' => '__VALUE__',
240-
]
241-
);
242-
243-
Ajax::updateItemOnSelectEvent(
244-
"dropdown_entity_choice$rand",
245-
"showmandatorygroup",
246-
PLUGIN_TRANSFERTICKETENTITY_FULLWEBDIR . "/ajax/showentitymandatorygroup.php",
247-
[
248-
'entity_selection' => '__VALUE__',
249-
]
250-
);
251-
252-
echo "</div>";
253-
echo "</div>";
254-
255-
echo "<div class='form-field row align-items-center col-12 col-sm-12 mb-2'>";
256-
echo "<label class='col-form-label col-xxl-5 text-xxl-end' for='group_choice'>";
257-
echo __("Select the group to assign", "transferticketentity");
258-
echo "<span id='showmandatorygroup'>";
259-
echo "</span>";
260-
echo "</label>";
261-
262-
echo "<div class='col-xxl-7 field-container'>";
263-
echo "<span id='show_entitygroup'>";
264-
265-
echo "</span>";
266-
echo "</div>";
267-
echo "</div>";
268-
269-
270-
echo "<div class='form-field row align-items-start col-12 col-sm-12 mb-2'>";
271-
echo "<label class='col-form-label col-xxl-5 text-xxl-end' for='justification' style='vertical-align: middle;'>";
272-
echo __("Justification", "transferticketentity");
273-
echo "<span id='showmandatoryjustification'>";
274-
echo "</span>";
275-
echo "</label>";
276-
277-
echo "<div class='col-xxl-7 field-container'>";
278-
279-
Html::textarea([
280-
'name' => "justification",
281-
'cols' => '45',
282-
'rows' => '5',
283-
'enable_richtext' => false,
284-
'enable_fileupload' => false
285-
]);
286-
287-
echo "<br><p class='alert alert-warning'>" . __(
288-
"Warning, category will be reset if it does not exist in the target entity.",
289-
"transferticketentity"
290-
) . "</p>";
291-
292-
echo Html::hidden("id_ticket", ["value" => "$id_ticket"]);
293-
echo Html::hidden("id_user", ["value" => "$id_user"]);
294-
295-
echo "</div><br>";
296-
echo "<div class='text-end'>";
297-
echo Html::submit(
298-
__('Confirm', 'transferticketentity'),
299-
['name' => 'transfertticket', 'class' => 'btn btn-primary']
199+
'can_edit' => Session::haveRight(self::$rightname, READ),
200+
'root_plugin' => PLUGIN_TRANSFERTICKETENTITY_WEBDIR,
201+
'action' => $target,
202+
'id_ticket' => $ticket->getID(),
203+
'id_user' => $_SESSION['glpiID'],
204+
'entities_id' => $ticket->getID(),
205+
'entities_name' => $entity->getName(),
206+
'entities' => $entities_selection,
207+
],
300208
);
301-
echo "</div>";
302-
echo "</div>";
303-
304-
echo "</div>";
305-
echo "</div>";
306-
echo "</div>";
307209

308-
Html::closeForm();
309210
}
310211

311212

templates/ticket.html.twig

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{#
2+
# -------------------------------------------------------------------------
3+
# Transferticketentity plugin for GLPI
4+
# -------------------------------------------------------------------------
5+
#
6+
# LICENSE
7+
#
8+
# This file is part of Transferticketentity.
9+
#
10+
# Transferticketentity is free software; you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation; either version 2 of the License, or
13+
# (at your option) any later version.
14+
#
15+
# Transferticketentity is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with Transferticketentity. If not, see <http://www.gnu.org/licenses/>.
22+
# -------------------------------------------------------------------------
23+
# @copyright Copyright (C) 2026-2026 by Transferticketentity plugin team.
24+
# @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
25+
# @link https://github.com/InfotelGLPI/Transferticketentity
26+
# -------------------------------------------------------------------------
27+
#}
28+
29+
{% import "components/form/fields_macros.html.twig" as fields %}
30+
{% set field_options = {'label_class': 'col-5', 'input_class': 'col-7', 'full_width': false} %}
31+
{{ include('components/form/header.html.twig') }}
32+
33+
{% set rand = random() %}
34+
35+
{% if can_edit %}
36+
<form name="form" action="{{ action }}" method="post">
37+
<div class="card">
38+
<div class="card-header">
39+
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}">
40+
<input type="hidden" name="id_ticket" value="{{ id_ticket }}">
41+
<input type="hidden" name="id_user" value="{{ id_user }}">
42+
<input type="hidden" name="entities_id" value="{{ entities_id }}">
43+
<h3 class="card-title">
44+
{{ __('Transfer the ticket', 'transferticketentity') }} - {{ entities_name }}
45+
</h3>
46+
</div>
47+
48+
<div class="card-body">
49+
<div class="card-text">
50+
<p class='alert alert-warning'>
51+
{{ __('Once the transfer has been completed, the ticket will remain visible only if you have the required rights.', 'transferticketentity') }}
52+
</p>
53+
54+
<div class='form-field row align-items-center col-12 col-sm-12 mb-2 tt_entity_choice'>
55+
<label class='col-form-label col-xxl-5 text-xxl-end' for='entity_choice'>
56+
{{ __("Select ticket entity to transfer","transferticketentity") }}
57+
</label>
58+
59+
<div class='col-xxl-7 field-container'>
60+
{% do call('Dropdown::showFromArray', [
61+
'entity_choice',
62+
entities,
63+
{
64+
'multiple' : false,
65+
'value' : null,
66+
'required' : checkMandatoryCategory,
67+
'rand': rand
68+
}
69+
]) %}
70+
71+
{% do call('Ajax::updateItemOnSelectEvent', [
72+
'dropdown_entity_choice' ~ rand,
73+
'show_entitygroup',
74+
config('root_doc') ~ '/' ~ root_plugin ~ '/ajax/showentitygroups.php',
75+
{
76+
'entity_selection': '__VALUE__',
77+
'rand': rand
78+
}
79+
]) %}
80+
81+
{% do call('Ajax::updateItemOnSelectEvent', [
82+
'dropdown_entity_choice' ~ rand,
83+
'showmandatoryjustification',
84+
config('root_doc') ~ '/' ~ root_plugin ~ '/ajax/showentitymandatoryjustification.php',
85+
{
86+
'entity_selection': '__VALUE__',
87+
'rand': rand
88+
}
89+
]) %}
90+
91+
{% do call('Ajax::updateItemOnSelectEvent', [
92+
'dropdown_entity_choice' ~ rand,
93+
'showmandatorygroup',
94+
config('root_doc') ~ '/' ~ root_plugin ~ '/ajax/showentitymandatorygroup.php',
95+
{
96+
'entity_selection': '__VALUE__',
97+
'rand': rand
98+
}
99+
]) %}
100+
</div>
101+
</div>
102+
103+
<div class='form-field row align-items-center col-12 col-sm-12 mb-2'>
104+
<label class='col-form-label col-xxl-5 text-xxl-end' for='group_choice'>
105+
{{ __("Select the group to assign", "transferticketentity") }}
106+
<span id='showmandatorygroup'>
107+
</span>
108+
</label>
109+
<div class='col-xxl-7 field-container'>
110+
<span id='show_entitygroup'>
111+
</span>
112+
</div>
113+
</div>
114+
115+
<div class='form-field row align-items-start col-12 col-sm-12 mb-2'>
116+
<label class='col-form-label col-xxl-5 text-xxl-end' for='justification'
117+
style='vertical-align: middle;'>
118+
{{ __("Justification", "transferticketentity") }}
119+
<span id='showmandatoryjustification'>
120+
</span>
121+
</label>
122+
<div class='col-xxl-7 field-container'>
123+
{{ fields.textareaField(
124+
'justification',
125+
null,
126+
null,
127+
{
128+
'label_class': "",
129+
'input_class': "col-xxl-11",
130+
'field_class' : "col-12",
131+
}
132+
) }}
133+
134+
</div>
135+
</div>
136+
137+
<p class='alert alert-warning'>
138+
{{ __("Warning, category will be reset if it does not exist in the target entity.","transferticketentity") }}
139+
</p>
140+
141+
<div class="hr mt-3 mb-3"></div>
142+
<div class="hstack gap-1">
143+
<div class="pe-5 ms-auto">
144+
<button class="btn btn-primary" type="submit" name="transfertticket" value="1">
145+
<i class="ti ti-device-floppy"></i>
146+
<span>{{ __('Confirm', 'transferticketentity') }}</span>
147+
</button>
148+
</div>
149+
</div>
150+
</div>
151+
</div>
152+
</div>
153+
</form>
154+
{% endif %}

0 commit comments

Comments
 (0)