dolibarr 20.0.0
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 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26require_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27
32{
33 public $boxcode = "box_ticket_by_severity";
34 public $boximg = "ticket";
35 public $boxlabel;
36 public $depends = array("ticket");
37
38 public $widgettype = 'graph';
39
45 public function __construct($db, $param = '')
46 {
47 global $langs;
48 $langs->load("boxes");
49 $this->db = $db;
50
51 $this->boxlabel = $langs->transnoentitiesnoconv("BoxTicketSeverity");
52 }
53
60 public function loadBox($max = 5)
61 {
62 global $conf, $user, $langs;
63
64 $badgeStatus0 = '#cbd3d3'; // draft
65 $badgeStatus1 = '#bc9526'; // validated
66 $badgeStatus1b = '#bc9526'; // validated
67 $badgeStatus2 = '#9c9c26'; // approved
68 $badgeStatus3 = '#bca52b';
69 $badgeStatus4 = '#25a580'; // Color ok
70 $badgeStatus4b = '#25a580'; // Color ok
71 $badgeStatus5 = '#cad2d2';
72 $badgeStatus6 = '#cad2d2';
73 $badgeStatus7 = '#baa32b';
74 $badgeStatus8 = '#993013';
75 $badgeStatus9 = '#e7f0f0';
76 if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php')) {
77 include DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php';
78 }
79 $this->max = $max;
80
81 require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
82
83 $text = $langs->trans("BoxTicketSeverity", $max);
84 $this->info_box_head = array(
85 'text' => $text,
86 'limit' => dol_strlen($text)
87 );
88
89 $listofopplabel = array();
90 $listofoppcode = array();
91 $colorseriesstat = array();
92 if ($user->hasRight('ticket', 'read')) {
93 $sql = "SELECT cts.rowid, cts.label, cts.code";
94 $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_severity as cts";
95 $sql .= " WHERE cts.active = 1";
96 $sql .= $this->db->order('cts.rowid', 'ASC');
97 $resql = $this->db->query($sql);
98
99 if ($resql) {
100 $num = $this->db->num_rows($resql);
101 $i = 0;
102 while ($i < $num) {
103 $objp = $this->db->fetch_object($resql);
104 $listofoppcode[$objp->rowid] = $objp->code;
105 $listofopplabel[$objp->rowid] = $objp->label;
106 switch ($objp->code) {
107 case 'LOW':
108 $colorseriesstat[$objp->rowid] = $badgeStatus4;
109 break;
110 case 'NORMAL':
111 $colorseriesstat[$objp->rowid] = $badgeStatus2;
112 break;
113 case 'HIGH':
114 $colorseriesstat[$objp->rowid] = $badgeStatus1;
115 break;
116 case 'BLOCKING':
117 $colorseriesstat[$objp->rowid] = $badgeStatus8;
118 break;
119 default:
120 break;
121 }
122 $i++;
123 }
124 } else {
125 dol_print_error($this->db);
126 }
127
128 $dataseries = array();
129 $data = array();
130 $sql = "SELECT t.severity_code, COUNT(t.severity_code) as nb";
131 $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
132 $sql .= " WHERE t.fk_statut <> 8";
133 $sql .= " GROUP BY t.severity_code";
134 $resql = $this->db->query($sql);
135 if ($resql) {
136 $num = $this->db->num_rows($resql);
137 $i = 0;
138 while ($i < $num) {
139 $objp = $this->db->fetch_object($resql);
140 $data[$objp->severity_code] = $objp->nb;
141 $i++;
142 }
143 foreach ($listofoppcode as $rowid => $code) {
144 $dataseries[] = array(
145 'label' => $langs->getLabelFromKey($this->db, 'TicketSeverityShort' . $code, 'c_ticket_severity', 'code', 'label', $code),
146 'data' => (empty($data[$code]) ? 0 : $data[$code])
147 );
148 }
149 } else {
150 dol_print_error($this->db);
151 }
152 $stringtoprint = '';
153 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
154 if (!empty($dataseries) && count($dataseries) > 0) {
155 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
156 $px1 = new DolGraph();
157 $mesg = $px1->isGraphKo();
158 $totalnb = 0;
159 if (!$mesg) {
160 //$px1->SetDataColor(array_values($colorseriesstat));
161 $data = array();
162 $legend = array();
163 foreach ($dataseries as $value) {
164 $data[] = array($value['label'], $value['data']);
165 $totalnb += $value['data'];
166 }
167
168 $px1->SetData($data);
169 $px1->setShowLegend(0);
170 $px1->SetType(array('bars'));
171 $px1->SetLegend($legend);
172 $px1->SetMaxValue($px1->GetCeilMaxValue());
173 //$px1->SetHeight($HEIGHT);
174 $px1->SetShading(3);
175 $px1->SetHorizTickIncrement(1);
176 $px1->SetCssPrefix("cssboxes");
177 $px1->mode = 'depth';
178
179 $px1->draw('idgraphticketseverity');
180 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
181 }
182 $stringtoprint .= '</div>';
183 $this->info_box_contents[][]=array(
184 'td' => 'class="center"',
185 'text' => $stringtoprint
186 );
187 } else {
188 $this->info_box_contents[0][0] = array(
189 'td' => '',
190 'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
191 );
192 }
193 } else {
194 $this->info_box_contents[0][0] = array(
195 'td' => '',
196 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
197 );
198 }
199 }
200
209 public function showBox($head = null, $contents = null, $nooutput = 0)
210 {
211 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
212 }
213}
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...