Skip to content

Commit

Permalink
#4112 [Dashboard] fix: moreparam for dashboard request
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Oct 9, 2024
1 parent 1968cce commit bdd3527
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
12 changes: 9 additions & 3 deletions class/accident.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,19 @@ public function getNbPresquAccidents(): array
/**
* Get number accident investigations
*
* @param array $moreParam More param (Object/user/etc)
* @return array
* @throws Exception
*/
public function getNbAccidentInvestigations(): array
public function getNbAccidentInvestigations(array $moreParam = []): array
{
$accidentInvestigation = new AccidentInvestigation($this->db);
$accidentInvestigations = $accidentInvestigation->fetchAll('', '', 0, 0, ['customsql' => ' t.status > ' . AccidentInvestigation::STATUS_DRAFT]);
require_once __DIR__ . '/accidentinvestigation.class.php';

$accidentInvestigation = new AccidentInvestigation($this->db);
if (strpos($moreParam['filter'], 't.entity') !== false) {
$accidentInvestigation->ismultientitymanaged = 0;
}
$accidentInvestigations = $accidentInvestigation->fetchAll('', '', 0, 0, ['customsql' => ' t.status > ' . AccidentInvestigation::STATUS_DRAFT . $moreParam['filter']]);
if (!empty($accidentInvestigations) && is_array($accidentInvestigations)) {
$array['nbaccidentinvestigations'] = count($accidentInvestigations);
} else {
Expand Down
12 changes: 7 additions & 5 deletions class/evaluator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ public function load_dashboard(): array
/**
* Get number employees involved.
*
* @return array
* @param array $moreParam More param (Object/user/etc)
* @return array
* @throws Exception
*/
public function getNbEmployeesInvolved() {
public function getNbEmployeesInvolved(array $moreParam = []) {
// Number employees involved
$allevaluators = $this->fetchAll('','', 0, 0, array(), 'AND', 'fk_user');
$allevaluators = $this->fetchAll('','', 0, 0, ['customsql' => $moreParam['filter']], 'AND', 'fk_user');
if (is_array($allevaluators) && !empty($allevaluators)) {
$array['nbemployeesinvolved'] = count($allevaluators);
} else {
Expand All @@ -175,17 +176,18 @@ public function getNbEmployeesInvolved() {
/**
* Get number employees
*
* @param array $moreParam More param (Object/user/etc)
* @return array
* @throws Exception
*/
public function getNbEmployees(): array
public function getNbEmployees(array $moreParam = []): array
{
global $user;

if (getDolGlobalInt('DIGIRISKDOLIBARR_NB_EMPLOYEES') > 0 && getDolGlobalInt('DIGIRISKDOLIBARR_MANUAL_INPUT_NB_EMPLOYEES')) {
$array['nbemployees'] = getDolGlobalInt('DIGIRISKDOLIBARR_NB_EMPLOYEES');
} else {
$users = $user->get_full_tree(0, 'u.employee = 1');
$users = $user->get_full_tree(0, 'u.employee = 1' . $moreParam['filter']);
if (!empty($users) && is_array($users)) {
$array['nbemployees'] = count($users);
} else {
Expand Down
6 changes: 3 additions & 3 deletions class/riskanalysis/risk.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,11 @@ public function load_dashboard(): array
/**
* Get risks by cotation
*
* @param string $filter SQL Filter
* @param array $moreParam More param (Object/user/etc)
* @return array
* @throws Exception
*/
public function getRisksByCotation(string $filter = ''): array
public function getRisksByCotation(array $moreParam = []): array
{
global $conf, $langs;

Expand All @@ -667,7 +667,7 @@ public function getRisksByCotation(string $filter = ''): array
$join = ' LEFT JOIN ' . MAIN_DB_PREFIX . $this->table_element . ' as r ON r.rowid = t.fk_risk';
$join .= ' LEFT JOIN ' . MAIN_DB_PREFIX . $digiriskElement->table_element . ' as d ON d.rowid = r.fk_element';

$riskAssessments = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 't.status = ' . RiskAssessment::STATUS_VALIDATED . ' AND r.fk_element NOT IN ' . $filter], 'AND', false, true, false, $join);
$riskAssessments = saturne_fetch_all_object_type('RiskAssessment', '', '', 0, 0, ['customsql' => 't.status = ' . RiskAssessment::STATUS_VALIDATED . ' AND r.fk_element NOT IN ' . $moreParam['filter']], 'AND', false, $moreParam['multiEntityManagement'], false, $join);
$array['data'] = $riskAssessment->getRiskAssessmentCategoriesNumber($riskAssessments);

return $array;
Expand Down

0 comments on commit bdd3527

Please sign in to comment.