dolibarr 21.0.4
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_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 = '')
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 if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php')) {
81 include DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php';
82 }
83 $this->max = $max;
84
85 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
86
87 $text = $langs->trans("BoxTicketSeverity", $max);
88 $this->info_box_head = array(
89 'text' => $text,
90 'limit' => dol_strlen($text)
91 );
92
93 $listofopplabel = array();
94 $listofoppcode = array();
95 $colorseriesstat = array();
96 if ($user->hasRight('ticket', 'read')) {
97 $sql = "SELECT cts.rowid, cts.label, cts.code";
98 $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_severity as cts";
99 $sql .= " WHERE cts.entity IN (".getEntity('c_ticket_severity').")";
100 $sql .= " AND cts.active = 1";
101 $sql .= $this->db->order('cts.rowid', 'ASC');
102 $resql = $this->db->query($sql);
103
104 if ($resql) {
105 $num = $this->db->num_rows($resql);
106 $i = 0;
107 while ($i < $num) {
108 $objp = $this->db->fetch_object($resql);
109 $listofoppcode[$objp->rowid] = $objp->code;
110 $listofopplabel[$objp->rowid] = $objp->label;
111 switch ($objp->code) {
112 case 'LOW':
113 $colorseriesstat[$objp->rowid] = $badgeStatus4;
114 break;
115 case 'NORMAL':
116 $colorseriesstat[$objp->rowid] = $badgeStatus2;
117 break;
118 case 'HIGH':
119 $colorseriesstat[$objp->rowid] = $badgeStatus1;
120 break;
121 case 'BLOCKING':
122 $colorseriesstat[$objp->rowid] = $badgeStatus8;
123 break;
124 default:
125 break;
126 }
127 $i++;
128 }
129 } else {
130 dol_print_error($this->db);
131 }
132
133 $dataseries = array();
134 $data = array();
135 $sql = "SELECT t.severity_code, COUNT(t.severity_code) as nb";
136 $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
137 $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
138 $sql .= " AND t.fk_statut <> 8";
139 $sql .= " GROUP BY t.severity_code";
140 $resql = $this->db->query($sql);
141 if ($resql) {
142 $num = $this->db->num_rows($resql);
143 $i = 0;
144 while ($i < $num) {
145 $objp = $this->db->fetch_object($resql);
146 $data[$objp->severity_code] = $objp->nb;
147 $i++;
148 }
149 foreach ($listofoppcode as $rowid => $code) {
150 $dataseries[] = array(
151 'label' => $langs->getLabelFromKey($this->db, 'TicketSeverityShort' . $code, 'c_ticket_severity', 'code', 'label', $code),
152 'data' => (empty($data[$code]) ? 0 : $data[$code])
153 );
154 }
155 } else {
156 dol_print_error($this->db);
157 }
158 $stringtoprint = '';
159 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
160 if (!empty($dataseries) && count($dataseries) > 0) {
161 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
162 $px1 = new DolGraph();
163 $mesg = $px1->isGraphKo();
164 $totalnb = 0;
165 if (!$mesg) {
166 //$px1->SetDataColor(array_values($colorseriesstat));
167 $data = array();
168 $legend = array();
169 foreach ($dataseries as $value) {
170 $data[] = array($value['label'], $value['data']);
171 $totalnb += $value['data'];
172 }
173
174 $px1->SetData($data);
175 $px1->setShowLegend(0);
176 $px1->SetType(array('bars'));
177 $px1->SetLegend($legend);
178 $px1->SetMaxValue($px1->GetCeilMaxValue());
179 //$px1->SetHeight($HEIGHT);
180 $px1->SetShading(3);
181 $px1->SetHorizTickIncrement(1);
182 $px1->SetCssPrefix("cssboxes");
183 $px1->mode = 'depth';
184
185 $px1->draw('idgraphticketseverity');
186 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
187 }
188 $stringtoprint .= '</div>';
189 $this->info_box_contents[][] = array(
190 'td' => 'class="center"',
191 'text' => $stringtoprint
192 );
193 } else {
194 $this->info_box_contents[0][0] = array(
195 'td' => '',
196 'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
197 );
198 }
199 } else {
200 $this->info_box_contents[0][0] = array(
201 'td' => '',
202 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
203 );
204 }
205 }
206
207
208
217 public function showBox($head = null, $contents = null, $nooutput = 0)
218 {
219 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
220 }
221}
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79