Skip to content

Commit

Permalink
#2431 [Dashboard] add: use name for keys instead integer
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Sep 28, 2022
1 parent 4a53829 commit 2ed3b3d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
24 changes: 12 additions & 12 deletions class/accident.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,20 +547,20 @@ public function getNbAccidents() {
global $langs;

// Number accidents
$array['title'] = $langs->transnoentities('AccidentRepartition');
$array['picto'] = '<i class="fas fa-user-injured"></i>';
$array['labels'] = array(
'accidents' => array(
'label' => $langs->transnoentities('AccidentWithDIAT'),
'color' => '#e05353'
),
'accidentswithoutDIAT' => array(
'label' => $langs->transnoentities('AccidentWithoutDIAT'),
'color' => '#e9ad4f'
),
);
$allaccidents = $this->fetchAll();
if (is_array($allaccidents) && !empty($allaccidents)) {
$array['title'] = $langs->transnoentities('AccidentRepartition');
$array['picto'] = '<i class="fas fa-user-injured"></i>';
$array['labels'] = array(
'accidents' => array(
'label' => $langs->transnoentities('AccidentWithDIAT'),
'color' => '#e05353'
),
'accidentswithoutDIAT' => array(
'label' => $langs->transnoentities('AccidentWithoutDIAT'),
'color' => '#e9ad4f'
),
);
$accidentworkstop = new AccidentWorkStop($this->db);
foreach ($allaccidents as $accident) {
$allaccidentworkstop = $accidentworkstop->fetchFromParent($accident->id);
Expand Down
1 change: 1 addition & 0 deletions class/dashboarddigiriskstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function show_dashboard()

if (is_array($dashboard_data['graphs']) && !empty($dashboard_data['graphs'])) {
foreach ($dashboard_data['graphs'] as $keyelement => $datagraph) {
$nbdata = 0;
if (is_array($datagraph['data']) && !empty($datagraph['data'])) {
foreach ($datagraph['data'] as $datagraphsingle) {
$nbdata += $datagraphsingle;
Expand Down
47 changes: 24 additions & 23 deletions class/digirisktask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,47 @@ public function load_dashboard()
/**
* Get tasks by progress.
*
* @return array|int
* @return array
* @throws Exception
*/
public function getTasksByProgress()
{
// Tasks by progress
global $conf, $langs;

$array['title'] = $langs->transnoentities('TasksRepartition');
$array['picto'] = '<i class="fas fa-tasks"></i>';
$array['labels'] = array(
'taskat0percent' => array(
'label' => $langs->transnoentities('TaskAt0Percent') . ' %',
'color' => '#e05353'
),
'taskinprogress' => array(
'label' => $langs->transnoentities('TaskInProgress'),
'color' => '#e9ad4f'
),
'taskat100percent' => array(
'label' => $langs->transnoentities('TaskAt100Percent') . ' %',
'color' => '#47e58e'
),
);
$taskarray = $this->getTasksArray(0, 0, $conf->global->DIGIRISKDOLIBARR_DU_PROJECT);
if (is_array($taskarray) && !empty($taskarray)) {
$array = array();
$array['title'] = $langs->transnoentities('TasksRepartition');
$array['picto'] = '<i class="fas fa-tasks"></i>';
$array['labels'] = array(
0 => array(
'label' => $langs->transnoentities('TaskAt0Percent') . ' %',
'color' => '#e05353'
),
1 => array(
'label' => $langs->transnoentities('TaskInProgress'),
'color' => '#e9ad4f'
),
2 => array(
'label' => $langs->transnoentities('TaskAt100Percent') . ' %',
'color' => '#47e58e'
),
);
foreach ($taskarray as $tasksingle) {
if ($tasksingle->progress == 0) {
$array['data'][0] = $array['data'][0] + 1;
$array['data']['taskat0percent'] = $array['data']['taskat0percent'] + 1;
} elseif ($tasksingle->progress > 0 && $tasksingle->progress < 100) {
$array['data'][1] = $array['data'][1] + 1;
$array['data']['taskinprogress'] = $array['data']['taskinprogress'] + 1;
} else {
$array['data'][2] = $array['data'][2] + 1;
$array['data']['taskat100percent'] = $array['data']['taskat100percent'] + 1;
}
}
return $array;
} else {
return -1;
$array['data']['taskat0percent'] = 0;
$array['data']['taskinprogress'] = 0;
$array['data']['taskat100percent'] = 0;
}
return $array;
}

/**
Expand Down

0 comments on commit 2ed3b3d

Please sign in to comment.