Skip to content

Commit

Permalink
#3718 [TicketStats] add: graph getTicketsByTag
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed May 6, 2024
1 parent f92e36d commit efca63a
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions class/ticketdigiriskstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,11 @@ public function getNbTicketByDigiriskElementAndTicketTags($date_start = 0, $date
*/
public function load_dashboard(): array
{
$getTicketsByYear = $this->getTicketsByYear();
$getTicketsByMonth = $this->getTicketsByMonth();
$getTicketsByMonth = $this->getTicketsByMonth();
$getTicketsByTag = $this->getTicketsByTag();
$getTicketsByYear = $this->getTicketsByYear();

$array['graphs'] = [$getTicketsByMonth];
$array['graphs'] = [$getTicketsByMonth, $getTicketsByTag];
$array['lists'] = [$getTicketsByYear];

return $array;
Expand All @@ -333,7 +334,7 @@ public function getTicketsByMonth(): array
$array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';

// Graph parameters
$array['type'] = 'graph';
$array['type'] = 'bar';
$array['showlegend'] = 1;

$date_start = dol_mktime(0, 0, 0, GETPOST('datestartmonth', 'int'), GETPOST('datestartday', 'int'), GETPOST('datestartyear', 'int'));
Expand Down Expand Up @@ -395,4 +396,54 @@ public function getTicketsByYear(): array

return $array;
}

/**
* Get tickets by tag
*
* @return array Graph datas (label/color/type/title/data etc..)
* @throws Exception
*/
public function getTicketsByTag(): array
{
global $conf, $langs;

// Graph Title parameters
$array['title'] = $langs->transnoentities('NumberOfTicketsByTag');
$array['picto'] = 'fontawesome_fa-ticket-alt_fas_#3bbfa8';

// Graph parameters
$array['width'] = '100%';
$array['height'] = 400;
$array['type'] = 'bar';
$array['showlegend'] = 1;
$array['dataset'] = 2;
$array['moreCSS'] = 'grid-2';

$array['labels'] = [
0 => [
'label' => $langs->transnoentities('NumberOfTickets'),
'color' => '#A1467E'
]
];

$category = new Categorie($this->db);

$category->fetch($conf->global->DIGIRISKDOLIBARR_TICKET_MAIN_CATEGORY);
$mainCategories = $category->get_filles();
if (is_array($mainCategories) && !empty($mainCategories)) {
foreach ($mainCategories as $mainCategory) {
$category->fetch($mainCategory->id);
$mainSubCategories = $category->get_filles();
if (is_array($mainSubCategories) && !empty($mainSubCategories)) {
foreach ($mainSubCategories as $mainSubCategory) {
$tickets = saturne_fetch_all_object_type('Ticket', '', '', 0, 0, ['customsql' => 'cp.fk_categorie = ' . $mainSubCategory->id], 'AND', false, true, true);
$array['data'][$mainSubCategory->id][0] = $mainSubCategory->label;
$array['data'][$mainSubCategory->id][1] = is_array($tickets) && !empty($tickets) ? count($tickets) : 0;
}
}
}
}

return $array;
}
}

0 comments on commit efca63a

Please sign in to comment.