dolibarr 21.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 * 2016 Christophe Battarel <christophe@altairis.fr>
5 * Copyright (C) 2019-2021 Frédéric France <frederic.france@netlogic.fr>
6 * Copyright (C) 2024 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_ticket_by_severity";
35 public $boximg = "ticket";
36 public $boxlabel;
37 public $depends = array("ticket");
38
39 public $widgettype = 'graph';
40
46 public function __construct($db, $param = '')
47 {
48 global $langs;
49 $langs->load("boxes");
50 $this->db = $db;
51
52 $this->boxlabel = $langs->transnoentitiesnoconv("BoxTicketSeverity");
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $conf, $user, $langs;
64
65 $badgeStatus0 = '#cbd3d3'; // draft
66 $badgeStatus1 = '#bc9526'; // validated
67 $badgeStatus1b = '#bc9526'; // validated
68 $badgeStatus2 = '#9c9c26'; // approved
69 $badgeStatus3 = '#bca52b';
70 $badgeStatus4 = '#25a580'; // Color ok
71 $badgeStatus4b = '#25a580'; // Color ok
72 $badgeStatus5 = '#cad2d2';
73 $badgeStatus6 = '#cad2d2';
74 $badgeStatus7 = '#baa32b';
75 $badgeStatus8 = '#993013';
76 $badgeStatus9 = '#e7f0f0';
77 if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php')) {
78 include DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php';
79 }
80 $this->max = $max;
81
82 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
83
84 $text = $langs->trans("BoxTicketSeverity", $max);
85 $this->info_box_head = array(
86 'text' => $text,
87 'limit' => dol_strlen($text)
88 );
89
90 $listofopplabel = array();
91 $listofoppcode = array();
92 $colorseriesstat = array();
93 if ($user->hasRight('ticket', 'read')) {
94 $sql = "SELECT cts.rowid, cts.label, cts.code";
95 $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_severity as cts";
96 $sql .= " WHERE cts.active = 1";
97 $sql .= $this->db->order('cts.rowid', 'ASC');
98 $resql = $this->db->query($sql);
99
100 if ($resql) {
101 $num = $this->db->num_rows($resql);
102 $i = 0;
103 while ($i < $num) {
104 $objp = $this->db->fetch_object($resql);
105 $listofoppcode[$objp->rowid] = $objp->code;
106 $listofopplabel[$objp->rowid] = $objp->label;
107 switch ($objp->code) {
108 case 'LOW':
109 $colorseriesstat[$objp->rowid] = $badgeStatus4;
110 break;
111 case 'NORMAL':
112 $colorseriesstat[$objp->rowid] = $badgeStatus2;
113 break;
114 case 'HIGH':
115 $colorseriesstat[$objp->rowid] = $badgeStatus1;
116 break;
117 case 'BLOCKING':
118 $colorseriesstat[$objp->rowid] = $badgeStatus8;
119 break;
120 default:
121 break;
122 }
123 $i++;
124 }
125 } else {
126 dol_print_error($this->db);
127 }
128
129 $dataseries = array();
130 $data = array();
131 $sql = "SELECT t.severity_code, COUNT(t.severity_code) as nb";
132 $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
133 $sql .= " WHERE t.fk_statut <> 8";
134 $sql .= " GROUP BY t.severity_code";
135 $resql = $this->db->query($sql);
136 if ($resql) {
137 $num = $this->db->num_rows($resql);
138 $i = 0;
139 while ($i < $num) {
140 $objp = $this->db->fetch_object($resql);
141 $data[$objp->severity_code] = $objp->nb;
142 $i++;
143 }
144 foreach ($listofoppcode as $rowid => $code) {
145 $dataseries[] = array(
146 'label' => $langs->getLabelFromKey($this->db, 'TicketSeverityShort' . $code, 'c_ticket_severity', 'code', 'label', $code),
147 'data' => (empty($data[$code]) ? 0 : $data[$code])
148 );
149 }
150 } else {
151 dol_print_error($this->db);
152 }
153 $stringtoprint = '';
154 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
155 if (!empty($dataseries) && count($dataseries) > 0) {
156 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
157 $px1 = new DolGraph();
158 $mesg = $px1->isGraphKo();
159 $totalnb = 0;
160 if (!$mesg) {
161 //$px1->SetDataColor(array_values($colorseriesstat));
162 $data = array();
163 $legend = array();
164 foreach ($dataseries as $value) {
165 $data[] = array($value['label'], $value['data']);
166 $totalnb += $value['data'];
167 }
168
169 $px1->SetData($data);
170 $px1->setShowLegend(0);
171 $px1->SetType(array('bars'));
172 $px1->SetLegend($legend);
173 $px1->SetMaxValue($px1->GetCeilMaxValue());
174 //$px1->SetHeight($HEIGHT);
175 $px1->SetShading(3);
176 $px1->SetHorizTickIncrement(1);
177 $px1->SetCssPrefix("cssboxes");
178 $px1->mode = 'depth';
179
180 $px1->draw('idgraphticketseverity');
181 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
182 }
183 $stringtoprint .= '</div>';
184 $this->info_box_contents[][] = array(
185 'td' => 'class="center"',
186 'text' => $stringtoprint
187 );
188 } else {
189 $this->info_box_contents[0][0] = array(
190 'td' => '',
191 'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
192 );
193 }
194 } else {
195 $this->info_box_contents[0][0] = array(
196 'td' => '',
197 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
198 );
199 }
200 }
201
210 public function showBox($head = null, $contents = null, $nooutput = 0)
211 {
212 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
213 }
214}
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.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...