dolibarr 25.0.0-alpha
box_graph_ticket_by_severity.php
Go to the documentation of this file.
1<?php
2/* Module descriptor for ticket system
3 * Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
4 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
5 * Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
28
33{
34 public $boxcode = "box_graph_ticket_by_severity";
35 public $boximg = "ticket";
39 public $boxlabel;
40 public $depends = array("ticket");
41
42 public $widgettype = 'graph';
43
49 public function __construct($db, $param = '') // @phpstan-ignore constructor.unusedParameter
50 {
51 global $langs;
52 $langs->load("boxes");
53 $this->db = $db;
54
55 $this->boxlabel = $langs->transnoentitiesnoconv("BoxTicketSeverity");
56 }
57
64 public function loadBox($max = 5)
65 {
66 global $conf, $user, $langs;
67
68 $badgeStatus0 = '#cbd3d3'; // draft
69 $badgeStatus1 = '#bc9526'; // validated
70 $badgeStatus1b = '#bc9526'; // validated
71 $badgeStatus2 = '#9c9c26'; // approved
72 $badgeStatus3 = '#bca52b';
73 $badgeStatus4 = '#25a580'; // Color ok
74 $badgeStatus4b = '#25a580'; // Color ok
75 $badgeStatus5 = '#cad2d2';
76 $badgeStatus6 = '#cad2d2';
77 $badgeStatus7 = '#baa32b';
78 $badgeStatus8 = '#993013';
79 $badgeStatus9 = '#e7f0f0';
80 $theme_vars_file = dol_getThemeFilePath('theme_vars.inc.php');
81 if ($theme_vars_file) {
82 include $theme_vars_file;
83 }
84 $this->max = $max;
85
86 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
87
88 $text = $langs->trans("BoxTicketSeverity", $max);
89 $this->info_box_head = array(
90 'text' => $text,
91 'limit' => dol_strlen($text)
92 );
93
94 $listofopplabel = array();
95 $listofoppcode = array();
96 $colorseriesstat = array();
97 if ($user->hasRight('ticket', 'read')) {
98 $sql = "SELECT cts.rowid, cts.label, cts.code";
99 $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_severity as cts";
100 $sql .= " WHERE cts.entity IN (".getEntity('c_ticket_severity').")";
101 $sql .= " AND cts.active = 1";
102 $sql .= $this->db->order('cts.rowid', 'ASC');
103 $resql = $this->db->query($sql);
104
105 if ($resql) {
106 $num = $this->db->num_rows($resql);
107 $i = 0;
108 while ($i < $num) {
109 $objp = $this->db->fetch_object($resql);
110 $listofoppcode[$objp->rowid] = $objp->code;
111 $listofopplabel[$objp->rowid] = $objp->label;
112 switch ($objp->code) {
113 case 'LOW':
114 $colorseriesstat[$objp->rowid] = $badgeStatus4;
115 break;
116 case 'NORMAL':
117 $colorseriesstat[$objp->rowid] = $badgeStatus2;
118 break;
119 case 'HIGH':
120 $colorseriesstat[$objp->rowid] = $badgeStatus1;
121 break;
122 case 'BLOCKING':
123 $colorseriesstat[$objp->rowid] = $badgeStatus8;
124 break;
125 default:
126 break;
127 }
128 $i++;
129 }
130 } else {
131 dol_print_error($this->db);
132 }
133
134 $dataseries = array();
135 $data = array();
136 $sql = "SELECT t.severity_code, COUNT(t.severity_code) as nb";
137 $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
138 $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
139 $sql .= " AND t.fk_statut <> 8";
140 $sql .= " GROUP BY t.severity_code";
141 $resql = $this->db->query($sql);
142 if ($resql) {
143 $num = $this->db->num_rows($resql);
144 $i = 0;
145 while ($i < $num) {
146 $objp = $this->db->fetch_object($resql);
147 $data[$objp->severity_code] = $objp->nb;
148 $i++;
149 }
150 foreach ($listofoppcode as $rowid => $code) {
151 $dataseries[] = array(
152 'label' => $langs->getLabelFromKey($this->db, 'TicketSeverityShort' . $code, 'c_ticket_severity', 'code', 'label', $code),
153 'data' => (empty($data[$code]) ? 0 : $data[$code])
154 );
155 }
156 } else {
157 dol_print_error($this->db);
158 }
159 $stringtoprint = '';
160 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
161 if (!empty($dataseries) && count($dataseries) > 0) {
162 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
163 $px1 = new DolGraph();
164 $mesg = $px1->isGraphKo();
165 $totalnb = 0;
166 if (!$mesg) {
167 //$px1->SetDataColor(array_values($colorseriesstat));
168 $data = array();
169 $legend = array();
170 foreach ($dataseries as $value) {
171 $data[] = array($value['label'], $value['data']);
172 $totalnb += $value['data'];
173 }
174
175 $px1->SetData($data);
176 $px1->setShowLegend(0);
177 $px1->SetType(array('bars'));
178 $px1->SetLegend($legend);
179 $px1->SetMaxValue($px1->GetCeilMaxValue());
180 //$px1->SetHeight($HEIGHT);
181 $px1->SetShading(3);
182 $px1->SetHorizTickIncrement(1);
183 $px1->SetCssPrefix("cssboxes");
184 $px1->mode = 'depth';
185
186 $px1->draw('idgraphticketseverity');
187 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
188 }
189 $stringtoprint .= '</div>';
190 $this->info_box_contents[][] = array(
191 'td' => 'class="center"',
192 'text' => $stringtoprint
193 );
194 } else {
195 $this->info_box_contents[0][0] = array(
196 'td' => '',
197 'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
198 );
199 }
200 } else {
201 $this->info_box_contents[0][0] = array(
202 'td' => '',
203 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
204 );
205 }
206 }
207
208
209
218 public function showBox($head = null, $contents = null, $nooutput = 0)
219 {
220 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
221 }
222}
Class to build graphs.
Class ModeleBoxes.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.