Merge branch 'features/feature-thanato-right-to-see-his-defunts' into staging
This commit is contained in:
commit
86c54c5f82
@ -2004,9 +2004,13 @@ class PageController extends Controller {
|
|||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function getStats(){
|
public function getStats(){
|
||||||
|
|
||||||
|
$isThanato = in_array('Thanatos',$this->groups);
|
||||||
|
$isAdmin = in_array('admin',$this->groups);
|
||||||
|
$isUserThanatoOnly = $isThanato && !$isAdmin;
|
||||||
$res = array();
|
$res = array();
|
||||||
$res['client'] = json_decode($this->myDb->numberClient($this->idNextcloud))[0]->c;
|
$res['client'] = json_decode($this->myDb->numberClient($this->idNextcloud))[0]->c;
|
||||||
$res['defunt'] = json_decode($this->myDb->numberDefunt($this->idNextcloud))[0]->c;
|
$res['defunt'] = $this->myDb->numberDefunt($this->idNextcloud,$isUserThanatoOnly);
|
||||||
$res['thanato'] = json_decode($this->myDb->numberThanato($this->idNextcloud))[0]->c;
|
$res['thanato'] = json_decode($this->myDb->numberThanato($this->idNextcloud))[0]->c;
|
||||||
$res['devis'] = json_decode($this->myDb->numberDevis($this->idNextcloud))[0]->c;
|
$res['devis'] = json_decode($this->myDb->numberDevis($this->idNextcloud))[0]->c;
|
||||||
$res['lieu'] = json_decode($this->myDb->numberLieu($this->idNextcloud))[0]->c;
|
$res['lieu'] = json_decode($this->myDb->numberLieu($this->idNextcloud))[0]->c;
|
||||||
@ -2060,9 +2064,12 @@ class PageController extends Controller {
|
|||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function getDefunts() {
|
public function getDefunts() {
|
||||||
return $this->myDb->getDefunts($this->idNextcloud);
|
$isThanato = in_array('Thanatos',$this->groups);
|
||||||
}
|
$isAdmin = in_array('admin',$this->groups);
|
||||||
|
$isUserThanatoOnly = $isThanato && !$isAdmin;
|
||||||
|
return $this->myDb->getDefunts($this->idNextcloud,$isUserThanatoOnly);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
|
|||||||
@ -404,7 +404,47 @@ class Bdd {
|
|||||||
return $this->execSQL($sql, array());
|
return $this->execSQL($sql, array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefunts($idNextcloud) {
|
private function getThanatoByIdNextcloud($idNextcloud){
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM ".$this->tableprefix."thanato as thanato
|
||||||
|
WHERE LOWER(thanato.nom) = LOWER(?)
|
||||||
|
ORDER BY thanato.id ASC;";
|
||||||
|
|
||||||
|
$thanato = $this->execSQLNoJsonReturn($sql, array($idNextcloud));
|
||||||
|
if(!empty($thanato)){
|
||||||
|
return $thanato[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDefuntIdsRelatedToThanato($thanatoId){
|
||||||
|
$devis = $this->getDevisMadeByAThanato($thanatoId);
|
||||||
|
$defuntIds = $this->getDefuntIdsFromDevisList($devis);
|
||||||
|
return $defuntIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDefuntIdsFromDevisList($devisList){
|
||||||
|
$defuntIds = [];
|
||||||
|
foreach($devisList as $devis){
|
||||||
|
$defuntIds[] = $devis["id_defunt"];
|
||||||
|
}
|
||||||
|
return $defuntIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDevisMadeByAThanato($thanatoId){
|
||||||
|
$sql = "SELECT
|
||||||
|
devis.id,
|
||||||
|
devis.id_thanato,
|
||||||
|
devis.id_defunt
|
||||||
|
FROM ".$this->tableprefix."devis as devis
|
||||||
|
WHERE devis.id_thanato = ? ;";
|
||||||
|
|
||||||
|
$devisList = $this->execSQLNoJsonReturn($sql, array($thanatoId));
|
||||||
|
return $devisList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefunts($idNextcloud, $isUserThanatoOnly = false)
|
||||||
|
{
|
||||||
$sql = "SELECT ".$this->tableprefix."defunt.id, ".$this->tableprefix."defunt.nom, ".$this->tableprefix."defunt.date_naissance, ".$this->tableprefix."defunt.ref_pacemaker, ".$this->tableprefix."defunt.sexe, "
|
$sql = "SELECT ".$this->tableprefix."defunt.id, ".$this->tableprefix."defunt.nom, ".$this->tableprefix."defunt.date_naissance, ".$this->tableprefix."defunt.ref_pacemaker, ".$this->tableprefix."defunt.sexe, "
|
||||||
.$this->tableprefix."client.nom as nom_client, ".$this->tableprefix."client.id as id_client, "
|
.$this->tableprefix."client.nom as nom_client, ".$this->tableprefix."client.id as id_client, "
|
||||||
.$this->tableprefix."devis.num as numero_devis, ".$this->tableprefix."devis.id as id_devis, ".$this->tableprefix."devis.user_id as user_id, "
|
.$this->tableprefix."devis.num as numero_devis, ".$this->tableprefix."devis.id as id_devis, ".$this->tableprefix."devis.user_id as user_id, "
|
||||||
@ -412,9 +452,23 @@ class Bdd {
|
|||||||
FROM ".$this->tableprefix."defunt
|
FROM ".$this->tableprefix."defunt
|
||||||
LEFT JOIN ".$this->tableprefix."devis ON ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
|
LEFT JOIN ".$this->tableprefix."devis ON ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
|
||||||
LEFT JOIN ".$this->tableprefix."client ON ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
LEFT JOIN ".$this->tableprefix."client ON ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
|
||||||
LEFT JOIN ".$this->tableprefix."lieu ON ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id
|
LEFT JOIN ".$this->tableprefix."lieu ON ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id";
|
||||||
ORDER BY ".$this->tableprefix."defunt.id DESC;";
|
|
||||||
return $this->execSQL($sql, array());
|
$conditions = [];
|
||||||
|
if($isUserThanatoOnly){
|
||||||
|
$thanato = $this->getThanatoByIdNextcloud($idNextcloud);
|
||||||
|
if($thanato != null){
|
||||||
|
$thanatoId = $thanato["id"];
|
||||||
|
$defuntsIdRelatedToThanato = $this->getDefuntIdsRelatedToThanato($thanatoId);
|
||||||
|
if(!empty($defuntsIdRelatedToThanato)){
|
||||||
|
$defuntListConditionPlaceholder = implode(',', array_fill(0, count($defuntsIdRelatedToThanato), '?'));
|
||||||
|
$conditions = $defuntsIdRelatedToThanato;
|
||||||
|
$sql .= " WHERE ".$this->tableprefix."defunt.id IN ($defuntListConditionPlaceholder)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sql .= " ORDER BY ".$this->tableprefix."defunt.id DESC;";
|
||||||
|
return $this->execSQL($sql, $conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUnusedDefunts($idNextcloud) {
|
public function getUnusedDefunts($idNextcloud) {
|
||||||
@ -1658,9 +1712,24 @@ class Bdd {
|
|||||||
/**
|
/**
|
||||||
* Number défunt
|
* Number défunt
|
||||||
*/
|
*/
|
||||||
public function numberDefunt($idNextcloud){
|
public function numberDefunt($idNextcloud, $isUserThanatoOnly = false){
|
||||||
$sql = "SELECT count(*) as c from ".$this->tableprefix."defunt;";
|
$defuntCount = 0;
|
||||||
return $this->execSQL($sql, array());
|
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->getThanatoByIdNextcloud($idNextcloud);
|
||||||
|
if($thanato != null){
|
||||||
|
$thanatoId = $thanato["id"];
|
||||||
|
$defuntsIdRelatedToThanato = $this->getDefuntIdsRelatedToThanato($thanatoId);
|
||||||
|
$defuntCount = count($defuntsIdRelatedToThanato);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $defuntCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user