dolibarr 19.0.3
box_graph_nb_tickets_type.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_graph_nb_tickets_type";
34 public $boximg = "ticket";
35 public $boxlabel;
36 public $depends = array("ticket");
37
38 public $param;
39 public $info_box_head = array();
40 public $info_box_contents = array();
41
42 public $widgettype = 'graph';
43
44
50 public function __construct($db, $param = '')
51 {
52 global $langs;
53 $langs->load("boxes");
54 $this->db = $db;
55
56 $this->boxlabel = $langs->transnoentitiesnoconv("BoxTicketType");
57 }
58
65 public function loadBox($max = 5)
66 {
67 global $conf, $user, $langs;
68 global $theme_datacolor, $badgeStatus8;
69
70 require_once DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php";
71 require_once DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
72
73
74 $badgeStatus8 = '#993013';
75
76 $text = $langs->trans("BoxTicketType");
77 $this->info_box_head = array(
78 'text' => $text,
79 'limit' => dol_strlen($text)
80 );
81
82 $listofopplabel = array();
83 $listofoppcode = array();
84 $colorseriesstat = array();
85 if ($user->hasRight('ticket', 'read')) {
86 $sql = "SELECT ctt.rowid, ctt.label, ctt.code";
87 $sql .= " FROM " . MAIN_DB_PREFIX . "c_ticket_type as ctt";
88 $sql .= " WHERE ctt.active = 1";
89 $sql .= $this->db->order('ctt.rowid', 'ASC');
90 $resql = $this->db->query($sql);
91
92 if ($resql) {
93 $num = $this->db->num_rows($resql);
94 $i = 0;
95 $newcolorkey = 0;
96 $colorused = array();
97 while ($i < $num) {
98 $objp = $this->db->fetch_object($resql);
99 $listofoppcode[$objp->rowid] = $objp->code;
100 $listofopplabel[$objp->rowid] = $objp->label;
101 if (empty($colorused[$objp->code])) {
102 if ($objp->code == 'ISSUE') {
103 $colorused[$objp->code] = $badgeStatus8;
104 } else {
105 $colorused[$objp->code] = colorArrayToHex($theme_datacolor[$newcolorkey]);
106 $newcolorkey++;
107 }
108 }
109 $colorseriesstat[$objp->rowid] = $colorused[$objp->code];
110
111 $i++;
112 }
113 } else {
114 dol_print_error($this->db);
115 }
116 $dataseries = array();
117 $data = array();
118 $sql = "SELECT t.type_code, COUNT(t.type_code) as nb";
119 $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
120 $sql .= " WHERE t.fk_statut <> 8";
121 $sql .= " GROUP BY t.type_code";
122 $resql = $this->db->query($sql);
123 if ($resql) {
124 $num = $this->db->num_rows($resql);
125 $i = 0;
126 while ($i < $num) {
127 $objp = $this->db->fetch_object($resql);
128 $data[$objp->type_code] = $objp->nb;
129 $i++;
130 }
131 foreach ($listofoppcode as $rowid => $code) {
132 $dataseries[] = array(
133 'label' => $langs->getLabelFromKey($this->db, 'TicketTypeShort' . $code, 'c_ticket_type', 'code', 'label', $code),
134 'data' => (empty($data[$code]) ? 0 : $data[$code])
135 );
136 }
137 } else {
138 dol_print_error($this->db);
139 }
140 $stringtoprint = '';
141 $stringtoprint .= '<div class="div-table-responsive-no-min ">';
142 if (!empty($dataseries) && count($dataseries) > 0) {
143 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
144 $px1 = new DolGraph();
145
146 $mesg = $px1->isGraphKo();
147 $totalnb = 0;
148 if (!$mesg) {
149 $px1->SetDataColor(array_values($colorseriesstat));
150 $data = array();
151 $legend = array();
152 foreach ($dataseries as $value) {
153 $data[] = array($value['label'], $value['data']);
154 $totalnb += $value['data'];
155 }
156 $px1->SetData($data);
157 $px1->setShowLegend(2);
158 if (!empty($conf->dol_optimize_smallscreen)) {
159 $px1->SetWidth(320);
160 }
161 $px1->SetType(array('pie'));
162 $px1->SetLegend($legend);
163 $px1->SetMaxValue($px1->GetCeilMaxValue());
164 $px1->SetShading(3);
165 $px1->SetHorizTickIncrement(1);
166 $px1->SetCssPrefix("cssboxes");
167 $px1->mode = 'depth';
168 $px1->draw('idgraphtickettype');
169 $stringtoprint .= $px1->show($totalnb ? 0 : 1);
170 }
171 $stringtoprint .= '</div>';
172 $this->info_box_contents[][]=array(
173 'td' => 'class="center"',
174 'text' => $stringtoprint
175 );
176 } else {
177 $this->info_box_contents[0][0] = array(
178 'td' => 'class="center opacitymedium"',
179 'text' => '<span class="opacitymedium">'.$langs->trans("BoxNoTicketSeverity").'</span>'
180 );
181 }
182 } else {
183 $this->info_box_contents[0][0] = array(
184 'td' => 'class="left"',
185 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
186 );
187 }
188 }
189
198 public function showBox($head = null, $contents = null, $nooutput = 0)
199 {
200 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
201 }
202}
Class to build graphs.
Class ModeleBoxes.
Class to manage the box to show number of ticket types.
__construct($db, $param='')
Constructor.
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.
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.