Skip to content

Commit

Permalink
Evarisk#3784 [DigiriskElement] fix: rework graphs getRisksByDigiriskE…
Browse files Browse the repository at this point in the history
…lement
  • Loading branch information
nicolas-eoxia committed Apr 25, 2024
1 parent f0e5701 commit 91c0c44
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
64 changes: 20 additions & 44 deletions class/digiriskelement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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] = [
Expand Down
10 changes: 5 additions & 5 deletions class/riskanalysis/risk.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion langs/fr_FR/digiriskdolibarr.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down

0 comments on commit 91c0c44

Please sign in to comment.