From d7a8e8167fa4df49c1b73abd21c31f7640a3bf31 Mon Sep 17 00:00:00 2001 From: Tiavina Date: Tue, 14 Jan 2025 12:56:22 +0300 Subject: [PATCH] wip listener on moveCalendarobject to trash --- gestion/lib/AppInfo/Application.php | 4 ++ .../lib/Constants/DevisMentionConstant.php | 13 +++++ gestion/lib/Db/Bdd.php | 27 +++++++++ .../CalendarObjectMovedToTrashListener.php | 58 +++++++++++++++++++ gestion/lib/Service/GestionService.php | 10 ++++ gestion/src/js/objects/devis.mjs | 23 +++++++- 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 gestion/lib/Constants/DevisMentionConstant.php create mode 100644 gestion/lib/Listener/CalendarObjectMovedToTrashListener.php diff --git a/gestion/lib/AppInfo/Application.php b/gestion/lib/AppInfo/Application.php index 6ed5a6d..00772ab 100644 --- a/gestion/lib/AppInfo/Application.php +++ b/gestion/lib/AppInfo/Application.php @@ -5,7 +5,10 @@ namespace OCA\Gestion\AppInfo; use OCA\DAV\Events\CalendarObjectCreatedEvent; +use OCA\DAV\Events\CalendarObjectDeletedEvent; +use OCA\DAV\Events\CalendarObjectMovedToTrashEvent; use OCA\Gestion\Listener\CalendarObjectCreatedListener; +use OCA\Gestion\Listener\CalendarObjectMovedToTrashListener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; @@ -21,6 +24,7 @@ class Application extends App implements IBootstrap { public function register(IRegistrationContext $context): void { $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class); + $context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectMovedToTrashListener::class); } public function boot(IBootContext $context): void { diff --git a/gestion/lib/Constants/DevisMentionConstant.php b/gestion/lib/Constants/DevisMentionConstant.php new file mode 100644 index 0000000..6c0166a --- /dev/null +++ b/gestion/lib/Constants/DevisMentionConstant.php @@ -0,0 +1,13 @@ +comment); return $message; } + + public function getDevisByCalendarUuid($calendarUuid){ + if($calendarUuid === self::DEFAULT_CALENDAR_UUID_FOR_DEVIS){ + return null; + } + $sql = "SELECT + devis.id, + devis.id_thanato, + devis.id_defunt, + devis.num + FROM ".$this->tableprefix."devis as devis + WHERE devis.num = ? ;"; + + $devis = $this->execSQLNoJsonReturn($sql, array($calendarUuid)); + if(empty($devis)){ + return null; + } + return $devis[0]; + } + public function updateDevisMentionToCanceled($devisId){ + $sql= "UPDATE ".$this->tableprefix."devis as devis + SET devis.mentions = ? + WHERE devis.id = ?"; + + $this->execSQLNoData($sql,[DevisMentionConstant::CANCELED,$devisId]); + } } \ No newline at end of file diff --git a/gestion/lib/Listener/CalendarObjectMovedToTrashListener.php b/gestion/lib/Listener/CalendarObjectMovedToTrashListener.php new file mode 100644 index 0000000..734ed51 --- /dev/null +++ b/gestion/lib/Listener/CalendarObjectMovedToTrashListener.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\CalendarObjectMovedToTrashEvent; +use OCA\Gestion\Service\GestionService; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use Psr\Log\LoggerInterface; + +class CalendarObjectMovedToTrashListener 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 CalendarObjectMovedToTrashEvent)) { + return; + } + $calendarData = $event->getObjectData(); + $vCalendarString = $calendarData["calendardata"]; + $this->logger->debug($vCalendarString); + $this->gestionService->HandleCalendarObjectMovedToTrash($vCalendarString); + } + +} diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index 6686635..1db21c5 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -127,6 +127,16 @@ class GestionService { return $calendarStartDate; } + public function HandleCalendarObjectMovedToTrash(string $vCalendarString){ + $calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString); + $this->logger->debug($calendarUuid); + $devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid); + if($devis != null){ + $this->gestionBdd->updateDevisMentionToCanceled($devis['id']); + } + return true; + } + public function HandleCreatedCalendarObject(string $vCalendarString){ $calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString); $clientId = $this->GetClientIdFromVCalendarString($vCalendarString); diff --git a/gestion/src/js/objects/devis.mjs b/gestion/src/js/objects/devis.mjs index 758c00a..91d7ba9 100644 --- a/gestion/src/js/objects/devis.mjs +++ b/gestion/src/js/objects/devis.mjs @@ -8,6 +8,7 @@ export class Devis { * Devis object * @param myresp instantiate devis object */ + constructor(myresp) { this.id = myresp.id; this.user_id = myresp.user_id; @@ -26,13 +27,23 @@ export class Devis { this.nomThanato = Devis.getDevisThanatoFullname(myresp); this.version = ((myresp.version == null || myresp.version.length === 0) ? '-' : myresp.version); this.lieu = ((myresp.lieu == null || myresp.lieu.length === 0) ? '-' : myresp.lieu); - this.mentions = ((myresp.mentions == null || myresp.mentions.length === 0) ? '-' : myresp.mentions); + this.mentions = Devis.getDevisMentionFromApiResponse(myresp); this.baseUrl = generateUrl(`/apps/gestion/devis/${this.id}/show`); this.devisFullNumber = ((myresp.devis_full_number != null && myresp.mentions.devis_full_number != 0) ? myresp.devis_full_number : '-'); this.devisProduits = Devis.getDevisProduitsString(myresp); } + static getDevisMentionFromApiResponse(myresp){ + mention = "-"; + if(myresp.mentions != null && myresp.mentions.length > 0){ + mention = myresp.mentions; + if(mention === 'CANCELED'){ + mention = 'AnnulĂ©'; + } + } + } + static getDevisThanatoFullname(myresp){ let thanatoPrenom = ''; let thanatoNom = ''; @@ -51,6 +62,16 @@ export class Devis { return (thanatoFullName.length === 0) ? '-' : thanatoFullName; } + static getDevisMentionColumnColor(mention) { + if(mention === 'facturé'){ + return 'green'; + } + if(mention === 'CANCELED'){ + return 'red'; + } + return 'yellow'; + } + static getDevisProduitsString(myresp){ let devisProduitsAsString = ''; if(myresp.produits != null && myresp.produits.length > 0){