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

#4082 [Dashboard] fix: rework getRisksByDigiriskElement and missing type on getRisksByCotation #4085

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
28 changes: 7 additions & 21 deletions class/digiriskelement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,30 +570,16 @@ public function getRisksByDigiriskElement(string $riskType = 'risk'): array
$array['showlegend'] = $conf->browser->layout == 'phone' ? 1 : 2;
$array['dataset'] = 1;

$digiriskElements = $this->fetchDigiriskElementFlat(GETPOSTISSET('id') ? GETPOST('id') : 0);

// Get current digirisk element and add data in $digiriskElements array
if (GETPOSTISSET('id')) {
$currentDigiriskElement = $this->fetchAll('', '', 0, 0, ['customsql' => 't.rowid = ' . GETPOST('id')]);
if (is_array($currentDigiriskElement) && !empty($currentDigiriskElement)) {
$currentDigiriskElement = array_shift($currentDigiriskElement);

$array['title'] = $langs->transnoentities('RisksRepartitionByDigiriskElement', ': ' . $currentDigiriskElement->ref . ' - ' . $currentDigiriskElement->label);

$digiriskElement[$currentDigiriskElement->id]['object'] = $currentDigiriskElement;
$digiriskElements = array_merge($digiriskElement, $digiriskElements);
}
}

if (!empty($digiriskElements)) {
$digiriskElements = $this->getActiveDigiriskElements(0, ['filter' => GETPOSTISSET('id') ? ' AND t.rowid = ' . GETPOST('id') : '']);
if (is_array($digiriskElements) && !empty($digiriskElements)) {
foreach ($digiriskElements as $digiriskElement) {
$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]);
$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->id]);
if (is_array($risks) && !empty($risks)) {
$array['labels'][$digiriskElement['object']->id] = [
'label' => $digiriskElement['object']->ref . ' - ' . $digiriskElement['object']->label,
'color' => SaturneDashboard::getColorRange($digiriskElement['object']->id)
$array['labels'][$digiriskElement->id] = [
'label' => $digiriskElement->ref . ' - ' . $digiriskElement->label,
'color' => SaturneDashboard::getColorRange($digiriskElement->id)
];
$array['data'][$digiriskElement['object']->id] = count($risks);
$array['data'][$digiriskElement->id] = count($risks);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions class/riskanalysis/risk.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,12 @@ public function load_dashboard(): array
/**
* Get risks by cotation
*
* @param string $type Risk type (risk, riskenvironmental or ...)
*
* @return array
* @throws Exception
*/
public function getRisksByCotation(): array
public function getRisksByCotation(string $type = 'risk'): array
{
global $conf, $langs;

Expand Down Expand Up @@ -671,7 +673,7 @@ public function getRisksByCotation(): array
$digiriskElementSqlFilter = rtrim($digiriskElementSqlFilter, ', ');
}
$digiriskElementSqlFilter .= ')';
$filter = ' AND r.fk_element NOT IN ' . $digiriskElementSqlFilter;
$filter = ' AND r.fk_element NOT IN ' . $digiriskElementSqlFilter . ' AND r.type = "' . $type . '"';
}

$riskAssessments = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 't.status = ' . RiskAssessment::STATUS_VALIDATED . $filter], 'AND', false, true, false, $join);
Expand Down