diff --git a/class/digiriskelement.class.php b/class/digiriskelement.class.php index 222bc996e..c59e53006 100644 --- a/class/digiriskelement.class.php +++ b/class/digiriskelement.class.php @@ -538,71 +538,47 @@ public function getTriggerDescription(SaturneObject $object): string */ public function load_dashboard(): array { - $urlTab = $_SERVER['PHP_SELF']; + $getDigiriskElementListsByDepth = $this->getDigiriskElementListsByDepth(); + $getRisksByDigiriskElement = $this->getRisksByDigiriskElement(); - if (preg_match('/digiriskelement_informations/', $urlTab)) { - $arrayRisksByGp = $this->getRisksByGp('single'); - } else { - $arrayRisksByGp = $this->getRisksByGp(); - $getDigiriskElementListsByDepth = $this->getDigiriskElementListsByDepth(); - } - $array['graphs'] = [$arrayRisksByGp, $getDigiriskElementListsByDepth ?? []]; + $array['graphs'] = [$getDigiriskElementListsByDepth, $getRisksByDigiriskElement]; return $array; } /** - * Get risks by GP + * Get list of risk by digirisk element * - * @param String $type Empty to get risks of every element or 'single' to get risk for the current and children element + * @param string $riskType Risk type (risk, riskenvironmental or ...) * * @return array * @throws Exception */ - public function getRisksByGp($type = ''): array + public function getRisksByDigiriskElement(string $riskType = 'risk'): array { global $conf, $langs; + // Graph Title parameters + $array['title'] = $langs->transnoentities('RisksRepartitionByDigiriskElement'); + $array['picto'] = $this->picto; + // Graph parameters $array['width'] = '100%'; $array['height'] = 400; $array['type'] = 'pie'; $array['showlegend'] = $conf->browser->layout == 'phone' ? 1 : 2; $array['dataset'] = 1; - $array['picto'] = $this->picto; - - $elements = $this->getActiveDigiriskElements(); - if ($type == 'single') { - $id = GETPOST('id'); - $this->fetch($id); - - // Graph Title parameters - $array['title'] = $langs->transnoentities('AddStatsGP', $this->ref, $this->label); - $children = recurse_tree($id, 0, $elements); - $ids[$id] = $this->label; - } else { - // Graph Title parameters - $array['title'] = $langs->transnoentities('AddStatsGP', 'DU', getDolGlobalString('MAIN_INFO_SOCIETE_NOM')); - - $children = $elements; - } - - array_walk_recursive($children, function ($item) use (&$ids) { - if (is_object($item)) { - $ids[$item->id] = $item->label; + $digiriskElements = $this->fetchDigiriskElementFlat(GETPOSTISSET('id') ? GETPOST('id') : 0); + if (!empty($digiriskElements)) { + foreach ($digiriskElements as $digiriskElement) { + $array['labels'][$digiriskElement['object']->id] = [ + 'label' => $digiriskElement['object']->ref . ' - ' . $digiriskElement['object']->label, + 'color' => SaturneDashboard::getColorRange($digiriskElement['object']->id) + ]; + $risks = saturne_fetch_all_object_type('Risk', '', '', 0, 0, ['customsql' => 't.status = ' . Risk::STATUS_VALIDATED . ' AND t.entity = ' . $conf->entity . ' AND t.type = "' . $riskType . '" AND t.fk_element = ' . $digiriskElement['object']->id]); + $array['data'][$digiriskElement['object']->id] = is_array($risks) && !empty($risks) ? count($risks) : 0; } - }, $ids); - - $i = 0; - foreach ($ids as $elementId => $label) { - $array['labels'][$elementId] = [ - 'label' => $label, - 'color' => SaturneDashboard::getColorRange($i) - ]; - $risks = saturne_fetch_all_object_type('Risk', '', '', 0, 0, ['customsql' => 't.fk_element = ' . $elementId . ' AND t.status = ' . Risk::STATUS_VALIDATED]); - $array['data'][$elementId] = (is_array($risks) && !empty($risks) ? count($risks) : 0); - $i++; } return $array; @@ -631,7 +607,7 @@ public function getDigiriskElementListsByDepth(): array $children = []; $digiriskElements = $this->fetchDigiriskElementFlat(0); - if (is_array($digiriskElements) && !empty($digiriskElements)) { + if (!empty($digiriskElements)) { foreach ($digiriskElements as $digiriskElement) { if ($digiriskElement['depth'] <= 1 && $digiriskElement['object']->element_type == 'groupment') { $array['labels'][$digiriskElement['object']->id] = [ diff --git a/class/riskanalysis/risk.class.php b/class/riskanalysis/risk.class.php index a6c7ab8e0..83dd516f2 100644 --- a/class/riskanalysis/risk.class.php +++ b/class/riskanalysis/risk.class.php @@ -610,8 +610,8 @@ public function getRisksByCotation(): array /** * Get risks by danger categories and criticality * - * @param array $dangerCategories Danger categories datas - * @param string $type risk type (risk, riskenvironmental or ...) + * @param array $dangerCategories Danger categories datas + * @param string $type Risk type (risk, riskenvironmental or ...) * * @return array * @throws Exception @@ -650,8 +650,8 @@ public function getRisksByDangerCategoriesAndCriticality(array $dangerCategories /** * Get risks by danger categories * - * @param array $dangerCategories Danger categories datas - * @param string $type risk type (risk, riskenvironmental or ...) + * @param array $dangerCategories Danger categories datas + * @param string $type Risk type (risk, riskenvironmental or ...) * * @return array * @throws Exception @@ -693,7 +693,7 @@ public function getRisksByDangerCategories(array $dangerCategories, string $type * Get list of risks by danger categories * * @param array $dangerCategories Danger categories datas - * @param string $type risk type (risk, riskenvironmental or ...) + * @param string $type Risk type (risk, riskenvironmental or ...) * * @return array * @throws Exception diff --git a/langs/fr_FR/digiriskdolibarr.lang b/langs/fr_FR/digiriskdolibarr.lang index 1dfada1d5..adafe9aed 100644 --- a/langs/fr_FR/digiriskdolibarr.lang +++ b/langs/fr_FR/digiriskdolibarr.lang @@ -987,7 +987,7 @@ DigiriskElementsRepartitionByDepth = Répartition des groupements RisksRepartitionByDangerCategoriesAndCriticality = Répartition des risques par catégorie de danger et criticité NumberOfRisks = Nombre de risques DangerCategories = Catégories de danger -AddStatsGP = Répartition des risques: %s - %s +RisksRepartitionByDigiriskElement = Répartition des risques par groupement / unité de travail