diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index 85c7bc5..0a1d98a 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -67,7 +67,7 @@ class GestionService { } else{ //get from calendar object - $organizerName = $this->getOrganizerNameFromVCalendarString($vCalendarString); + $organizerName = $this->getPrincipalUsernameFromVCalendarString($vCalendarString); if($organizerName != null){ $thanatoIdFromDb = $this->gestionBdd->getFirstThanatoIdByName($organizerName); if($thanatoIdFromDb != null){ @@ -78,10 +78,10 @@ class GestionService { return $thanatoId; } - private function getOrganizerNameFromVCalendarString(string $vCalendarString){ + private function getPrincipalUsernameFromVCalendarString(string $vCalendarString){ $calendarUuid = VCalendarHelpers::GetValueFromKeyInVCalendarString("UID", $vCalendarString); - $organizerName = $this->gestionBdd->getCalendarOrganizerNameByCalendarObjectUuid($calendarUuid); - return $organizerName; + $principalUsername = $this->gestionBdd->getCalendarOrganizerNameByCalendarObjectUuid($calendarUuid); + return $principalUsername; } private function GetAttendeesNameFromVCalendarString(string $vCalendarString): array { @@ -132,8 +132,21 @@ class GestionService { $articlesId = $this->gestionBdd->getArticlesIdFromArticlesNameArray($articlesValue); $this->gestionBdd->insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articlesId); } - $organizerName = $this->getOrganizerNameFromVCalendarString($vCalendarString); - $this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$organizerName); + $userName = $this->GetThanatoNameFromVCalendarString($vCalendarString); + $this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName); + } + + private function GetThanatoNameFromVCalendarString($vCalendarString){ + $thanatoName = null; + $thanatoNames = $this->GetAttendeesNameFromVCalendarString($vCalendarString); + if(count($thanatoNames) > 0){ + $thanatoName = $thanatoNames[0]; + } + else{ + //get from calendar object + $thanatoName = $this->getPrincipalUsernameFromVCalendarString($vCalendarString); + } + return $thanatoName; } private function GetClientIdFromVCalendarString(string $vCalendarString){