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