forked from yllen/pdf
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathitem_ticketmodel.class.php
More file actions
140 lines (121 loc) · 5.36 KB
/
item_ticketmodel.class.php
File metadata and controls
140 lines (121 loc) · 5.36 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
<?php
class PluginPdfItem_TicketModel extends PluginPdfItem_Ticket
{
static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $sub=false)
{
global $DB;
$dbu = new DbUtils();
$instID = $ticket->fields['id'];
if (!$ticket->can($instID, READ)) {
return false;
}
$result = $DB->request('glpi_items_tickets',
['SELECT' => 'itemtype',
'DISTINCT' => true,
'WHERE' => ['tickets_id' => $instID],
'ORDER' => 'itemtype']);
$number = count($result);
$pdf->setColumnsSize(100);
$title = '<b>'._n('Item', 'Items', $number).'</b>';
if (!$number) {
$pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display')));
} else {
$title = sprintf(__('%1$s: %2$s'), $title, '');
$pdf->displayTitle($title);
$pdf->setColumnsSize(14, 14, 18, 12, 12, 12, 18);
$pdf->displayTitle("<i>".__('Type'), __('Name'), __('Model'), __('Serial number'),
__('Inventory number'), __('Location'), __('Comments')."</i>");
$totalnb = 0;
foreach ($result as $row) {
$itemtype = $row['itemtype'];
if (!($item = $dbu->getItemForItemtype($itemtype))) {
continue;
}
if ($item->canView()) {
$itemtable = $dbu->getTableForItemType($itemtype);
$model_name = substr($itemtable, 5, -1).'models';
$query = [
"SELECT" => [
"`$itemtable`" => ["*"],
"`glpi_items_tickets`" => ["`id` AS `IDD`"],
"`glpi_entities`" => ["`id` AS `entity`"]
],
"FROM" => [
"`$itemtable`"
]
];
if ($itemtype != "Entity") {
$query["LEFT JOIN"] = [
"`glpi_entities`" => [
"ON" => [
"`$itemtable`" => "`entities_id`",
"`glpi_entities`" => "`id`"
]
]
];
}
$query["INNER JOIN"] = [
"`glpi_items_tickets`" => [
"ON" => [
"`$itemtable`" => "`id`",
"`glpi_items_tickets`" => "`items_id`"
]
]
];
$query["WHERE"] = [
"`glpi_items_tickets`.`itemtype`" => "$itemtype",
"`glpi_items_tickets`.`tickets_id`" => "$instID"
];
if ($item->maybeTemplate()) {
$query["WHERE"]["AND"]["`$itemtable`.is_template"] = "0";
}
$query["ORDER"] = [
"`glpi_entities`.`completename`",
"`$itemtable`.`name`"
];
$result_linked = $DB->request($query);
$nb = count($result_linked);
$prem = true;
foreach ($result_linked as $data) {
$name = $data["name"];
if (empty($data["name"])) {
$name = "(".$data["id"].")";
}
if (isset($data[$model_name."_id"])) {
$model = Dropdown::getDropdownName("glpi_".$model_name, $data[$model_name."_id"]);
} else {
$model = "";
}
if (isset($data["locations_id"])) {
$location = Dropdown::getDropdownName("glpi_locations", $data["locations_id"]);
} else {
$location = "";
}
if ($prem) {
$typename = $item->getTypeName($nb);
$pdf->displayLine(Toolbox::stripTags(sprintf(__('%1$s: %2$s'), $typename, $nb)),
Toolbox::stripTags($name),
Toolbox::stripTags($model),
isset($data["serial"])?Toolbox::stripTags($data["serial"]):'',
isset($data["otherserial"])?Toolbox::stripTags($data["otherserial"]):'',
Toolbox::stripTags($location),
Toolbox::stripTags($data['comment']??''),$nb);
} else {
$pdf->displayLine('',
Toolbox::stripTags($name),
Toolbox::stripTags($model),
isset($data["serial"])?Toolbox::stripTags($data["serial"]):'',
isset($data["otherserial"])?Toolbox::stripTags($data["otherserial"]):'',
Toolbox::stripTags($location),
Toolbox::stripTags($data['comment']??''),$nb);
}
$prem = false;
}
$totalnb += $nb;
}
}
$pdf->displayLine("<b><i>".sprintf(__('%1$s = %2$s')."</b></i>", __('Total'), $totalnb));
}
$pdf->displaySpace();
}
}