dolibarr  16.0.5
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 
26 require_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 
41  public $db;
42 
43  public $param;
44  public $info_box_head = array();
45  public $info_box_contents = array();
46 
47  public $widgettype = 'graph';
48 
49 
55  public function __construct($db, $param = '')
56  {
57  global $langs;
58  $langs->load("boxes");
59  $this->db = $db;
60 
61  $this->boxlabel = $langs->transnoentitiesnoconv("BoxTicketSeverity");
62  }
63 
70  public function loadBox($max = 5)
71  {
72  global $conf, $user, $langs;
73 
74  $badgeStatus0 = '#cbd3d3'; // draft
75  $badgeStatus1 = '#bc9526'; // validated
76  $badgeStatus1b = '#bc9526'; // validated
77  $badgeStatus2 = '#9c9c26'; // approved
78  $badgeStatus3 = '#bca52b';
79  $badgeStatus4 = '#25a580'; // Color ok
80  $badgeStatus4b = '#25a580'; // Color ok
81  $badgeStatus5 = '#cad2d2';
82  $badgeStatus6 = '#cad2d2';
83  $badgeStatus7 = '#baa32b';
84  $badgeStatus8 = '#993013';
85  $badgeStatus9 = '#e7f0f0';
86  if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php')) {
87  include DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php';
88  }
89  $this->max = $max;
90 
91  require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
92 
93  $text = $langs->trans("BoxTicketSeverity", $max);
94  $this->info_box_head = array(
95  'text' => $text,
96  'limit' => dol_strlen($text)
97  );
98 
99  $listofopplabel = array();
100  $listofoppcode = array();
101  $colorseriesstat = array();
102  if ($user->rights->ticket->read) {
103  $sql = "SELECT cts.rowid, cts.label, cts.code";
104  $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_severity as cts";
105  $sql .= " WHERE cts.active = 1";
106  $sql .= $this->db->order('cts.rowid', 'ASC');
107  $resql = $this->db->query($sql);
108 
109  if ($resql) {
110  $num = $this->db->num_rows($resql);
111  $i = 0;
112  while ($i < $num) {
113  $objp = $this->db->fetch_object($resql);
114  $listofoppcode[$objp->rowid] = $objp->code;
115  $listofopplabel[$objp->rowid] = $objp->label;
116  switch ($objp->code) {
117  case 'LOW':
118  $colorseriesstat[$objp->rowid] = $badgeStatus4;
119  break;
120  case 'NORMAL':
121  $colorseriesstat[$objp->rowid] = $badgeStatus2;
122  break;
123  case 'HIGH':
124  $colorseriesstat[$objp->rowid] = $badgeStatus1;
125  break;
126  case 'BLOCKING':
127  $colorseriesstat[$objp->rowid] = $badgeStatus8;
128  break;
129  default:
130  break;
131  }
132  $i++;
133  }
134  } else {
135  dol_print_error($this->db);
136  }
137 
138  $dataseries = array();
139  $data = array();
140  $sql = "SELECT t.severity_code, COUNT(t.severity_code) as nb";
141  $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
142  $sql .= " WHERE t.fk_statut <> 8";
143  $sql .= " GROUP BY t.severity_code";
144  $resql = $this->db->query($sql);
145  if ($resql) {
146  $num = $this->db->num_rows($resql);
147  $i = 0;
148  while ($i < $num) {
149  $objp = $this->db->fetch_object($resql);
150  $data[$objp->severity_code] = $objp->nb;
151  $i++;
152  }
153  foreach ($listofoppcode as $rowid => $code) {
154  $dataseries[] = array(
155  'label' => $langs->getLabelFromKey($this->db, 'TicketSeverityShort' . $code, 'c_ticket_severity', 'code', 'label', $code),
156  'data' => (empty($data[$code]) ? 0 : $data[$code])
157  );
158  }
159  } else {
160  dol_print_error($this->db);
161  }
162  $stringtoprint = '';
163  $stringtoprint .= '<div class="div-table-responsive-no-min ">';
164  if (!empty($dataseries) && count($dataseries) > 0) {
165  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
166  $px1 = new DolGraph();
167  $mesg = $px1->isGraphKo();
168  $totalnb = 0;
169  if (!$mesg) {
170  //$px1->SetDataColor(array_values($colorseriesstat));
171  $data = array();
172  $legend = array();
173  foreach ($dataseries as $value) {
174  $data[] = array($value['label'], $value['data']);
175  $totalnb += $value['data'];
176  }
177 
178  $px1->SetData($data);
179  $px1->setShowLegend(0);
180  $px1->SetType(array('bars'));
181  $px1->SetLegend($legend);
182  $px1->SetMaxValue($px1->GetCeilMaxValue());
183  //$px1->SetHeight($HEIGHT);
184  $px1->SetShading(3);
185  $px1->SetHorizTickIncrement(1);
186  $px1->SetCssPrefix("cssboxes");
187  $px1->mode = 'depth';
188 
189  $px1->draw('idgraphticketseverity');
190  $stringtoprint .= $px1->show($totalnb ? 0 : 1);
191  }
192  $stringtoprint .= '</div>';
193  $this->info_box_contents[][]=array(
194  'td' => 'class="center"',
195  'text' => $stringtoprint
196  );
197  } else {
198  $this->info_box_contents[0][0] = array(
199  'td' => '',
200  'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
201  );
202  }
203  } else {
204  $this->info_box_contents[0][0] = array(
205  'td' => '',
206  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>',
207  );
208  }
209  }
210 
219  public function showBox($head = null, $contents = null, $nooutput = 0)
220  {
221  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
222  }
223 }
db
$conf db
API class for accounts.
Definition: inc.php:41
box_graph_ticket_by_severity
Class to manage the box.
Definition: box_graph_ticket_by_severity.php:31
box_graph_ticket_by_severity\loadBox
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_graph_ticket_by_severity.php:70
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
box_graph_ticket_by_severity\__construct
__construct($db, $param='')
Constructor.
Definition: box_graph_ticket_by_severity.php:55
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
box_graph_ticket_by_severity\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_graph_ticket_by_severity.php:219
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34