Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4083 [Dashboard] add: name and filter on graphs #4137

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions class/accident.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ public function LibStatut(int $status, int $mode = 0): string
*/
public function load_dashboard(): array
{
global $conf, $langs;
global $user, $langs, $conf;

$confName = dol_stroupper($this->module) . '_DASHBOARD_CONFIG';
$dashboardConfig = json_decode($user->conf->$confName);
$array = ['graphs' => [], 'disabledGraphs' => []];

$join = ' LEFT JOIN ' . MAIN_DB_PREFIX . $this->table_element . ' as a ON a.rowid = t.fk_accident';
$accidentsWithWorkStops = saturne_fetch_all_object_type('AccidentWorkStop', 'DESC', 't.rowid', 0, 0, [], 'AND', false, true, false, $join);
Expand All @@ -426,8 +430,6 @@ public function load_dashboard(): array
}

$arrayNbDaysWithoutAccident = $this->getNbDaysWithoutAccident($accidents);
$arrayNbAccidents = $this->getNbAccidents($accidents, $accidentsWithWorkStops);
$arrayNbAccidentsLast3Years = $this->getNbAccidentsLast3years($accidents);
$arrayNbWorkstopDays = $this->getNbWorkstopDays($accidentsWithWorkStops);

$arrayNbPresquAccidents = $this->getNbPresquAccidents();
Expand Down Expand Up @@ -464,7 +466,16 @@ public function load_dashboard(): array
]
];

$array['graphs'] = [$arrayNbAccidents, $arrayNbAccidentsLast3Years];
if (empty($dashboardConfig->graphs->AccidentRepartition->hide)) {
$array['graphs'][] = $this->getNbAccidents($accidents, $accidentsWithWorkStops);
} else {
$array['disabledGraphs']['AccidentRepartition'] = $langs->transnoentities('AccidentRepartition');
}
if (empty($dashboardConfig->graphs->AccidentByYear->hide)) {
$array['graphs'][] = $this->getNbAccidentsLast3years($accidents);
} else {
$array['disabledGraphs']['AccidentByYear'] = $langs->transnoentities('AccidentByYear');
}

return $array;
}
Expand Down Expand Up @@ -500,6 +511,7 @@ public function getNbAccidents(array $accidents = [], array $accidentsWithWorkSt

// Graph Title parameters
$array['title'] = $langs->transnoentities('AccidentRepartition');
$array['name'] = 'AccidentRepartition';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down Expand Up @@ -538,6 +550,7 @@ public function getNbAccidentsLast3years(array $accidents = []): array

// Graph Title parameters
$array['title'] = $langs->transnoentities('AccidentByYear');
$array['name'] = 'AccidentByYear';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down
22 changes: 18 additions & 4 deletions class/digiriskelement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function create(User $user, bool $notrigger = false): int
{
global $conf;
if (empty($this->ref)) {
$type = 'DIGIRISKDOLIBARR_' . strtoupper($this->element_type) . '_ADDON';
$type = 'DIGIRISKDOLIBARR_' . dol_stroupper($this->element_type) . '_ADDON';
$objectMod = $conf->global->$type;
$numberingModules = [
'digiriskelement/' . $this->element_type => $objectMod
Expand Down Expand Up @@ -563,10 +563,22 @@ public function getTriggerDescription(SaturneObject $object): string
*/
public function load_dashboard(): array
{
$getDigiriskElementListsByDepth = $this->getDigiriskElementListsByDepth();
$getRisksByDigiriskElement = $this->getRisksByDigiriskElement();
global $user, $langs;

$array['graphs'] = [$getDigiriskElementListsByDepth, $getRisksByDigiriskElement];
$confName = strtoupper($this->module) . '_DASHBOARD_CONFIG';
$dashboardConfig = json_decode($user->conf->$confName);
$array = ['graphs' => [], 'disabledGraphs' => []];

if (empty($dashboardConfig->graphs->DigiriskElementsRepartitionByDepth->hide)) {
$array['graphs'][] = $this->getDigiriskElementListsByDepth();
} else {
$array['disabledGraphs']['DigiriskElementsRepartitionByDepth'] = $langs->transnoentities('DigiriskElementsRepartitionByDepth');
}
if (empty($dashboardConfig->graphs->RisksRepartitionByDigiriskElement->hide)) {
$array['graphs'][] = $this->getRisksByDigiriskElement();
} else {
$array['disabledGraphs']['RisksRepartitionByDigiriskElement'] = $langs->transnoentities('RisksRepartitionByDigiriskElement');
}

return $array;
}
Expand All @@ -585,6 +597,7 @@ public function getRisksByDigiriskElement(string $riskType = 'risk'): array

// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartitionByDigiriskElement');
$array['name'] = 'RisksRepartitionByDigiriskElement';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down Expand Up @@ -637,6 +650,7 @@ public function getDigiriskElementListsByDepth(): array

// Graph Title parameters
$array['title'] = $langs->transnoentities('DigiriskElementsRepartitionByDepth', getDolGlobalInt('DIGIRISKDOLIBARR_DIGIRISKELEMENT_DEPTH_GRAPH'));
$array['name'] = 'DigiriskElementsRepartitionByDepth';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down
51 changes: 42 additions & 9 deletions class/riskanalysis/risk.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,22 +619,51 @@ public function getTasksWithFkRisk()
*/
public function load_dashboard(): array
{
$dangerCategories = $this->getDangerCategories();
global $user, $langs;

$confName = dol_stroupper($this->module) . '_DASHBOARD_CONFIG';
$dashboardConfig = json_decode($user->conf->$confName);
$array = ['graphs' => [], 'lists' => [], 'disabledGraphs' => []];

$riskType = !empty($dashboardConfig->filters->riskType) ? $dashboardConfig->filters->riskType : 'risk';

$digiriskElement = new DigiriskElement($this->db);

$filter = $digiriskElement->getTrashExclusionSqlFilter();

$riskByDangerCategoriesAndRiskAssessments = $this->getRiskByDangerCategoriesAndRiskAssessments($dangerCategories, $filter, 'risk');

$dangerCategories = $this->getDangerCategories();
$riskByDangerCategoriesAndRiskAssessments = $this->getRiskByDangerCategoriesAndRiskAssessments($dangerCategories, $filter, $riskType);
$moreParam['filter'] = $filter;
$getRisksByCotation = $this->getRisksByCotation($moreParam);
$getRisksByDangerCategoriesAndCriticality = $this->getRisksByDangerCategoriesAndCriticality($dangerCategories, $riskByDangerCategoriesAndRiskAssessments);
$getRisksByDangerCategories = $this->getRisksByDangerCategories($dangerCategories, $riskByDangerCategoriesAndRiskAssessments);
$getRiskListsByDangerCategories = $this->getRiskListsByDangerCategories($dangerCategories, $riskByDangerCategoriesAndRiskAssessments, $filter, 'risk');

$array['graphs'] = [$getRisksByDangerCategoriesAndCriticality, $getRisksByDangerCategories, $getRisksByCotation];
$array['lists'] = [$getRiskListsByDangerCategories];
$array['graphsFilters'] = [
'riskType' => [
'title' => $langs->transnoentities('DisplayRiskOfType'),
'type' => 'selectarray',
'filter' => 'riskType',
'values' => ['risk' => $langs->transnoentities('Risk'), 'riskenvironmental' => $langs->transnoentities('Riskenvironmental')],
'currentValue' => $riskType
]];

if (empty($dashboardConfig->graphs->RisksRepartitionByDangerCategoriesAndCriticality->hide)) {
$array['graphs'][] = $this->getRisksByDangerCategoriesAndCriticality($dangerCategories, $riskByDangerCategoriesAndRiskAssessments);
} else {
$array['disabledGraphs']['RisksRepartitionByDangerCategoriesAndCriticality'] = $langs->transnoentities('RisksRepartitionByDangerCategoriesAndCriticality');
}
if (empty($dashboardConfig->graphs->RisksRepartitionByDangerCategories->hide)) {
$array['graphs'][] = $this->getRisksByDangerCategories($dangerCategories, $riskByDangerCategoriesAndRiskAssessments);
} else {
$array['disabledGraphs']['RisksRepartitionByDangerCategories'] = $langs->transnoentities('RisksRepartitionByDangerCategories');
}
if (empty($dashboardConfig->graphs->RisksRepartitionByCotation->hide)) {
$array['graphs'][] = $this->getRisksByCotation($moreParam);
} else {
$array['disabledGraphs']['RisksRepartitionByCotation'] = $langs->transnoentities('RisksRepartitionByCotation');
}
if (empty($dashboardConfig->graphs->RiskListsByDangerCategories->hide)) {
$array['lists'][] = $this->getRiskListsByDangerCategories($dangerCategories, $riskByDangerCategoriesAndRiskAssessments, $filter, $riskType);
} else {
$array['disabledGraphs']['RiskListsByDangerCategories'] = $langs->transnoentities('RiskListsByDangerCategories');
}

return $array;
}
Expand All @@ -655,6 +684,7 @@ public function getRisksByCotation(array $moreParam = []): array

// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartition');
$array['name'] = 'RisksRepartition';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down Expand Up @@ -687,6 +717,7 @@ public function getRisksByDangerCategoriesAndCriticality(array $dangerCategories

// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartitionByDangerCategoriesAndCriticality');
$array['name'] = 'RisksRepartitionByDangerCategoriesAndCriticality';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down Expand Up @@ -723,6 +754,7 @@ public function getRisksByDangerCategories(array $dangerCategories, array $riskB

// Graph Title parameters
$array['title'] = $langs->transnoentities('RisksRepartitionByDangerCategories');
$array['name'] = 'RisksRepartitionByDangerCategories';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down Expand Up @@ -768,6 +800,7 @@ public function getRiskListsByDangerCategories(array $dangerCategories, array $r

// Graph Title parameters
$array['title'] = $langs->transnoentities('RiskListsByDangerCategories');
$array['name'] = 'RiskListsByDangerCategories';
$array['picto'] = $this->picto;

// Graph parameters
Expand Down
37 changes: 29 additions & 8 deletions class/ticketdashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,36 @@ public function getNbTicketByDigiriskElementAndTicketTags(int $dateStart, int $d
*/
public function load_dashboard(array $moreParams = []): array
{
$getTicketsByMonth = $this->getTicketsByMonth();
global $user, $langs;

$confName = dol_stroupper($this->module) . '_DASHBOARD_CONFIG';
$dashboardConfig = json_decode($user->conf->$confName);
$array = ['graphs' => [], 'lists' => [], 'disabledGraphs' => []];

$category = new Categorie($this->db);
$category->fetch(getDolGlobalInt('DIGIRISKDOLIBARR_TICKET_MAIN_CATEGORY'));
$mainCategories = $category->get_filles();

$getTicketsByMainTagAndByDigiriskElement = $this->getTicketsByMainTagAndByDigiriskElement($mainCategories);
$getTicketsByMainSubTagAndByDigiriskElement = $this->getTicketsByMainSubTagAndByDigiriskElement($mainCategories);

$getTicketsByYear = $this->getTicketsByYear();

$array['graphs'] = [$getTicketsByMonth, $getTicketsByMainTagAndByDigiriskElement, $getTicketsByMainSubTagAndByDigiriskElement];
$array['lists'] = [$getTicketsByYear];
if (empty($dashboardConfig->graphs->NumberOfTicketsByMonth->hide)) {
$array['graphs'][] = $this->getTicketsByMonth();
} else {
$array['disabledGraphs']['NumberOfTicketsByMonth'] = $langs->transnoentities('NumberOfTicketsByMonth');
}
if (empty($dashboardConfig->graphs->NumberOfTicketsByMainTagAndByDigiriskElement->hide)) {
$array['graphs'][] = $this->getTicketsByMainTagAndByDigiriskElement($mainCategories);
} else {
$array['disabledGraphs']['NumberOfTicketsByMainTagAndByDigiriskElement'] = $langs->transnoentities('NumberOfTicketsByMainTagAndByDigiriskElement');
}
if (empty($dashboardConfig->graphs->NumberOfTicketsByMainSubTagAndByDigiriskElement->hide)) {
$array['graphs'][] = $this->getTicketsByMainSubTagAndByDigiriskElement($mainCategories);
} else {
$array['disabledGraphs']['NumberOfTicketsByMainSubTagAndByDigiriskElement'] = $langs->transnoentities('NumberOfTicketsByMainSubTagAndByDigiriskElement');
}
if (empty($dashboardConfig->graphs->NumberOfTicketsByYear->hide)) {
$array['lists'][] = $this->getTicketsByYear();
} else {
$array['disabledGraphs']['NumberOfTicketsByYear'] = $langs->transnoentities('NumberOfTicketsByYear');
}

return $array;
}
Expand All @@ -295,6 +312,7 @@ public function getTicketsByMonth(): array

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

// Graph parameters
Expand Down Expand Up @@ -352,6 +370,7 @@ public function getTicketsByMainTagAndByDigiriskElement($mainCategories): array

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

// Graph parameters
Expand Down Expand Up @@ -398,6 +417,7 @@ public function getTicketsByMainSubTagAndByDigiriskElement($mainCategories): arr

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

// Graph parameters
Expand Down Expand Up @@ -449,6 +469,7 @@ public function getTicketsByYear(): array

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

// Graph parameters
Expand Down