diff --git a/gestion/lib/AppInfo/Application.php b/gestion/lib/AppInfo/Application.php index 6496c86..39551de 100644 --- a/gestion/lib/AppInfo/Application.php +++ b/gestion/lib/AppInfo/Application.php @@ -5,9 +5,11 @@ namespace OCA\Gestion\AppInfo; use OCA\DAV\Events\CalendarObjectCreatedEvent; +use OCA\DAV\Events\CalendarObjectMovedEvent; use OCA\DAV\Events\CalendarObjectMovedToTrashEvent; use OCA\DAV\Events\CalendarObjectUpdatedEvent; use OCA\Gestion\Listener\CalendarObjectCreatedListener; +use OCA\Gestion\Listener\CalendarObjectMovedListener; use OCA\Gestion\Listener\CalendarObjectMovedToTrashListener; use OCA\Gestion\Listener\CalendarObjectUpdatedListener; use OCP\AppFramework\App; @@ -27,6 +29,7 @@ class Application extends App implements IBootstrap { $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class); $context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectMovedToTrashListener::class); $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarObjectUpdatedListener::class); + $context->registerEventListener(CalendarObjectMovedEvent::class,CalendarObjectMovedListener::class); } public function boot(IBootContext $context): void { diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index bae498e..ccfbe3a 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -2487,16 +2487,21 @@ class Bdd { return ""; } + public function getCalendarPrincipalNameByCalendarId($calendarId){ + $calendar = $this->getCalendarById($calendarId); + if($calendar != null){ + $principalUri = $calendar["principaluri"]; + $organizerName = str_replace('principals/users/','',$principalUri); + $organizerName = trim($organizerName); + return $organizerName; + } + return null; + } + public function getCalendarOrganizerNameByCalendarObjectUuid(string $calendarObjectUuid){ $calendarObject = $this->getCalendarObjectByUuid($calendarObjectUuid); if($calendarObject != null){ - $calendar = $this->getCalendarById($calendarObject['calendarid']); - if($calendar != null){ - $principalUri = $calendar["principaluri"]; - $organizerName = str_replace('principals/users/','',$principalUri); - $organizerName = trim($organizerName); - return $organizerName; - } + return $this->getCalendarPrincipalNameByCalendarId($calendarObject['calendarid']); } return null; } @@ -3617,6 +3622,13 @@ class Bdd { } } + public function updateDevisThanato($devisId,$requestedThanatoId){ + $sql= "UPDATE ".$this->tableprefix."devis as devis + SET devis.id_thanato = ? + WHERE devis.id = ?"; + $this->execSQLNoData($sql,[$requestedThanatoId,$devisId]); + } + public function updateDevisClient($devisId,$requestedClientId,$currentClientId = null){ $clientIsUpdated = $currentClientId != $requestedClientId; if($clientIsUpdated){ diff --git a/gestion/lib/Listener/CalendarObjectMovedListener.php b/gestion/lib/Listener/CalendarObjectMovedListener.php new file mode 100644 index 0000000..ec6f6b6 --- /dev/null +++ b/gestion/lib/Listener/CalendarObjectMovedListener.php @@ -0,0 +1,58 @@ + + * + * @author 2022 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\Gestion\Listener; + +use OCA\DAV\Events\CalendarObjectMovedEvent; +use OCA\Gestion\Service\GestionService; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use Psr\Log\LoggerInterface; + +class CalendarObjectMovedListener implements IEventListener { + + /** @var LoggerInterface */ + private $logger; + + /** @var GestionService */ + private $gestionService; + + public function __construct( + LoggerInterface $logger,GestionService $gestionService) { + $this->logger = $logger; + $this->gestionService = $gestionService; + } + + public function handle(Event $event): void { + if (!($event instanceof CalendarObjectMovedEvent)) { + return; + } + $calendarData = $event->getObjectData(); + $targetCalendarId = $event->getTargetCalendarId(); + $vCalendarString = $calendarData["calendardata"]; + $this->gestionService->HandleCalendarObjectMoved($vCalendarString,$targetCalendarId); + } + +} diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index 94af5d4..d020884 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -221,6 +221,27 @@ class GestionService { return true; } + public function HandleCalendarObjectMoved(string $vCalendarString,$targetCalendarId){ + $calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString); + $isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString); + $isCalendarDevis = $isCalendarForLeave == false; + if($isCalendarDevis){ + $devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid); + if($devis != null){ + $userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId); + if($userPrincipalName != null){ + $thanatoId = $this->gestionBdd->getThanatoIdByUserUuid($userPrincipalName); + if($thanatoId != null){ + $thanatoHasBeenChanged = $thanatoId != $devis["id_thanato"]; + if($thanatoHasBeenChanged){ + $this->gestionBdd->updateDevisThanato($devis['id'],$thanatoId); + } + } + } + } + } + } + public function HandleCreatedCalendarObject(string $vCalendarString){ $isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString); if($isCalendarForLeave){