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