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