diff --git a/gestion/lib/Constants/VCalendarPropertyConstant.php b/gestion/lib/Constants/VCalendarPropertyConstant.php index 2b5ee8f..326106c 100644 --- a/gestion/lib/Constants/VCalendarPropertyConstant.php +++ b/gestion/lib/Constants/VCalendarPropertyConstant.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace OCA\Gestion\Constants; abstract class VCalendarPropertyConstant { - const PROPERTY_IS_LEAVE = "ISPRIVATE"; + const PROPERTY_IS_PRIVATE = "ISPRIVATE"; const ABSENCE_TYPE = "ABSENCETYPE"; const RETURN_TO_SIEGE = "RETURNTOSIEGE"; diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index f61e01e..e346c74 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -1296,9 +1296,9 @@ class Bdd { $this->insertTrajetdetails_byDevis($trajet->id, $devis, $idNextcloud); if($devis->return_to_siege){ - $hasDepartH2f = $this->check_has_depart_h2f($devis->date,$trajet->id); - if(!$hasDepartH2f) { - $this->insertTrajetDetails_h2f($trajet->id, $devis->date, $idNextcloud); + $hasDepartFromHome = $this->check_has_depart_from_home($devis->date,$trajet->id ,$idNextcloud); + if(!$hasDepartFromHome) { + $this->insertTrajetHome($devis->date,$trajet->id ,$idNextcloud); } $hasAlreadyReturnToSiege = $this->check_if_return_to_siege_already_exist( $devis->date , $trajet->id , $devis->devisid); @@ -1319,9 +1319,9 @@ class Bdd { return false; } } - public function check_has_depart_h2f($date,$trajetId) { + public function check_has_depart_from_home($date,$trajetId ,$idNextcloud) { $sql = "SELECT COUNT(*) AS LIGNE_COUNT FROM `".$this->tableprefix."ligne_trajet` WHERE id_trajet = ? AND date = ? AND source = ?;"; - $response = $this->execSQL($sql, array($trajetId,$date,'h2f')); + $response = $this->execSQL($sql, array($trajetId,$date,$idNextcloud)); $response = json_decode($response)[0]; if($response->LIGNE_COUNT > 0 ) { return true; @@ -1329,10 +1329,11 @@ class Bdd { return false; } } - public function insertTrajetGoHome($date,$trajetId , $idNextcloud) { - - - /** Ceci est un nouveau concept. Après tout ce temps, nous devons préciser la date d'application de la nouvelle demande. pour la go to thanatho */ + // Inserer une ligne de trajet from home or to home + public function insertTrajetHome($date,$trajetId , $idNextcloud) { + /** Ceci est un nouveau concept. Après tout ce temps, nous devons préciser la date de la nouvelle demande pour faire + * l'ajout d'un thanato depuis son domicile ver le siege . + */ $dateTime = new DateTime($date); $dateTimeForFunctionalityGoToHome = new DateTime('2025-04-07'); @@ -1351,7 +1352,8 @@ class Bdd { $lieuId = $responseLocation != null ? $responseLocation->id : 0; - $sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( `id_nextcloud`, + $sql = "INSERT INTO `".$this->tableprefix."ligne_trajet` ( + `id_nextcloud`, `date`, `id_devis`, `id_client`, @@ -1366,10 +1368,6 @@ class Bdd { $this->execSQLNoData($sql, array($idNextcloud,$date,0 ,0,$lieuId,$trajetId,$rang+1,$idNextcloud,$last)); } - - public function range_ligneTrajetV2($id_trajet, $idNextcloud) { - - } /** * ranger les lignes de trajet dans un trajet par date et par rang * inserer ligne siege au debut et fin de chaque journee s'il n'existe pas @@ -1379,14 +1377,14 @@ class Bdd { $datesLignes = []; $lastRangOfTrajetPossible = 200; if(sizeof($lignes)>0) { + //Groupe By date all lignes de trajet foreach ($lignes as $key => $ligne) { $datesLignes[$ligne->date][] = $ligne; } foreach($datesLignes as $date => $currentDateLignes){ $dateTime = new DateTime($date); - $dateTimeForFunctionalityGoToHome = new DateTime('2025-04-07'); - + $dateTimeForFunctionalityGoToHome = new DateTime('2025-04-07');//Don't edit this date, it's a date for the new functionality if ( $dateTime <= $dateTimeForFunctionalityGoToHome) { @@ -1407,25 +1405,20 @@ class Bdd { }else{ //Nouvelle fonctionnalité - - $resteH2f = 1 - (sizeof(array_filter($currentDateLignes, function($ligne) {return strcmp($ligne->source,'h2f')==0;}))); - if ($resteH2f > 0 ) { - $this->insertTrajetDetails_h2f($id_trajet, $date, $idNextcloud); + $maxCountLigneHome = 2; + + $resteHome = $maxCountLigneHome - (sizeof(array_filter($currentDateLignes, function($ligne ) use ($idNextcloud) {return strcmp($ligne->source, $idNextcloud)==0;}))); + while ($resteHome > 0 ) { + $this->insertTrajetHome($date ,$id_trajet,$idNextcloud); + $resteHome--; } - - $resteGoHome = 1 - (sizeof(array_filter($currentDateLignes, function($ligne ) use ($idNextcloud) {return strcmp($ligne->source, $idNextcloud)==0;}))); - if ($resteGoHome > 0 ) { - $this->insertTrajetGoHome($date ,$id_trajet,$idNextcloud); - } - - $h2fLinge = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date, 'h2f')); - $ligneGoHome = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date, $idNextcloud)); + $ligneHome = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date, $idNextcloud)); $ordered_lines = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date)); - - $this->update_ligneTrajet('ligne_trajet', 'rang', 0, $h2fLinge[0]->id, $idNextcloud); - - $this->update_ligneTrajet('ligne_trajet', 'rang', $lastRangOfTrajetPossible, $ligneGoHome[0]->id, $idNextcloud); + if (count($ligneHome) == $maxCountLigneHome) { + $this->update_ligneTrajet('ligne_trajet', 'rang', 0, $ligneHome[0]->id, $idNextcloud); + $this->update_ligneTrajet('ligne_trajet', 'rang', $lastRangOfTrajetPossible, $ligneHome[1]->id, $idNextcloud); + } } $ordered_lines = json_decode($this->getTrajetsDetailsByDateAndSource($id_trajet, $date)); @@ -1435,45 +1428,6 @@ class Bdd { } - - // on verifie si le nombre de ligne h2f correspond à 2*nb_jour (debut et fin de journee) - // $reste = (2*$nb_jour) - (sizeof(array_filter($lignes, function($ligne) {return strcmp($ligne->source,'h2f')==0;}))); - // while ($reste>0) { - // $this->insertTrajetDetails_h2f($id_trajet, $lignes[0]->date, $idNextcloud); - // $reste--; - // } - - // $current_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud)); - - // // ici le nombre de ligne h2f est egale au nb_jour*2 - // $array_siege = array(); - // $array_home = array(); - // foreach ($current_lines as $key => $ligne) { - // if(strcmp($ligne->source,'h2f') == 0) { - // array_push($array_siege, $ligne); - // }else{ - // if(strcmp($ligne->source, $idNextcloud ) == 0 ) { - // array_push($array_home, $ligne); - // } - // } - // } - - // $j=0; - // for ($i=0; $i < sizeof($dates); $i++) { - - // $this->update_ligneTrajet('ligne_trajet', 'rang', 0, $array_siege[$j]->id, $idNextcloud); - // $this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j]->id, $idNextcloud); - - // $this->update_ligneTrajet('ligne_trajet', 'rang', sizeof($current_lines)+1, $array_siege[$j+1]->id, $idNextcloud); - // $this->update_ligneTrajet('ligne_trajet', 'date', $dates[$i], $array_siege[$j+1]->id, $idNextcloud); - // $j+=2; - // } - - // $ordered_lines = json_decode($this->getTrajetsdetails_orderByDate($id_trajet, $idNextcloud)); - // foreach ($ordered_lines as $key => $line) { - // $this->update_ligneTrajet('ligne_trajet', 'rang', $key+1, $line->id, $idNextcloud); - // } - } } diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index 2e6da5b..065567e 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -212,7 +212,7 @@ class GestionService { } private function GetIsPivateFromVCalendarString(string $vCalendarString): bool{ - $isPrivateValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_LEAVE, $vCalendarString); + $isPrivateValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_PRIVATE, $vCalendarString); return $isPrivateValue === "1" ? true : false; }