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