From c1cb86b5ce84b2262f53829afa66c98b18461f7a Mon Sep 17 00:00:00 2001 From: Narindra ezway Date: Wed, 12 Mar 2025 16:48:11 +0300 Subject: [PATCH] Enhance statistics retrieval by adding user role checks for Thanato users in PageController and MenuStatisticService --- gestion/lib/Controller/PageController.php | 5 +- gestion/lib/Db/Bdd.php | 21 ++++++- gestion/lib/Service/MenuStatisticService.php | 4 +- gestion/templates/navigation/index.php | 65 ++++++++++---------- 4 files changed, 56 insertions(+), 39 deletions(-) diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index aaaab28..1828f8c 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -1982,7 +1982,10 @@ class PageController extends Controller { * @NoCSRFRequired */ public function getStats(){ - $result = $this->menuStatisticService->getStats($this->idNextcloud); + $isThanato = in_array(UserGroupConstant::THANATOS_GROUP_NAME,$this->groups); + $isAdmin = in_array(UserGroupConstant::ADMIN_GROUP_NAME,$this->groups); + $isUserThanatoOnly = $isThanato && !$isAdmin; + $result = $this->menuStatisticService->getStats($this->idNextcloud,$isUserThanatoOnly); return json_encode($result); } diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index f657069..d68e533 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -1575,9 +1575,24 @@ class Bdd { /** * Number defunt */ - public function numberDefunt($idNextcloud){ - $sql = "SELECT count(*) as c from ".$this->tableprefix."defunt;"; - return $this->execSQL($sql, array()); + public function numberDefunt($idNextcloud,$isUserThanatoOnly = false){ + $defuntCount = 0; + if($isUserThanatoOnly == false){ + $sql = "SELECT count(*) as c from ".$this->tableprefix."defunt;"; + $defuntCountBythanato = $this->execSQLNoJsonReturn($sql, array()); + if(!empty($defuntCountBythanato)){ + $defuntCount = $defuntCountBythanato[0]['c']; + } + } + else{ + $thanato = $this->getThanatoByUserUuid($idNextcloud); + if($thanato != null){ + $thanatoId = $thanato["id"]; + $defuntsIdRelatedToThanato = $this->getDefuntIdsRelatedToThanato($thanatoId); + $defuntCount = count($defuntsIdRelatedToThanato); + } + } + return $defuntCount; } /** diff --git a/gestion/lib/Service/MenuStatisticService.php b/gestion/lib/Service/MenuStatisticService.php index bf445fe..4183fe8 100644 --- a/gestion/lib/Service/MenuStatisticService.php +++ b/gestion/lib/Service/MenuStatisticService.php @@ -58,10 +58,10 @@ class MenuStatisticService { * @NoAdminRequired * @NoCSRFRequired */ - public function getStats($idNextCloud){ + public function getStats($idNextCloud,$isUserThanatoOnly = false){ $res = array(); $res['client'] = json_decode($this->gestionBdd->numberClient($idNextCloud))[0]->c; - $res['defunt'] = json_decode($this->gestionBdd->numberDefunt($idNextCloud))[0]->c; + $res['defunt'] = $this->gestionBdd->numberDefunt($idNextCloud,$isUserThanatoOnly); $res['thanato'] = json_decode($this->gestionBdd->numberThanato($idNextCloud))[0]->c; $res['devis'] = json_decode($this->gestionBdd->numberDevis($idNextCloud))[0]->c; $res['lieu'] = json_decode($this->gestionBdd->numberLieu($idNextCloud))[0]->c; diff --git a/gestion/templates/navigation/index.php b/gestion/templates/navigation/index.php index 71b34a1..c5f7b86 100644 --- a/gestion/templates/navigation/index.php +++ b/gestion/templates/navigation/index.php @@ -1,5 +1,6 @@ -
  • - - - t('Lieux')); ?> - -
    -
      -
    • - -
      -
      -
    • -
    -
    -
  • +
  • + + + t('Lieux')); ?> + +
    +
      +
    • + +
      +
      +
    • +
    +
    +
  • @@ -98,23 +99,21 @@ $currentUserIsAdmin = (isset($_['groups']) && in_array('admin', $_['groups']));
  • - -
  • - - - t('Quotes')); ?> - -
    -
      -
    • - -
      -
      -
    • -
    -
    -
  • - +
  • + + + t('Quotes')); ?> + +
    +
      +
    • + +
      +
      +
    • +
    +
    +