From 72bb3360f985329cb8466a6c6dd5570f49acc5be Mon Sep 17 00:00:00 2001 From: Tiavina Date: Thu, 19 Dec 2024 16:18:58 +0300 Subject: [PATCH] wip send client when creating calendar object --- calendar/lib/AppInfo/Application.php | 4 +- .../CalendarObjectCreatedListener.php | 59 +++++++++++++++++++ .../lib/Service/Calendar/CalendarService.php | 59 +++++++++++++++++++ calendar/src/mixins/EditorMixin.js | 27 ++++++++- calendar/src/models/calendarObject.js | 1 + calendar/src/models/event.js | 4 ++ calendar/src/models/rfcProps.js | 17 ++++++ calendar/src/store/calendarObjectInstance.js | 11 ++++ calendar/src/store/settings.js | 1 + calendar/src/views/Calendar.vue | 1 + calendar/src/views/EditSidebar.vue | 8 +++ calendar/src/views/EditSimple.vue | 8 +++ gestion/appinfo/routes.php | 1 + gestion/lib/Controller/PageController.php | 8 +++ gestion/lib/Db/Bdd.php | 19 ++++++ 15 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 calendar/lib/Listener/CalendarObjectCreatedListener.php create mode 100644 calendar/lib/Service/Calendar/CalendarService.php diff --git a/calendar/lib/AppInfo/Application.php b/calendar/lib/AppInfo/Application.php index a8d0e96..3f35365 100644 --- a/calendar/lib/AppInfo/Application.php +++ b/calendar/lib/AppInfo/Application.php @@ -28,11 +28,13 @@ use OCA\Calendar\Dashboard\CalendarWidget; use OCA\Calendar\Dashboard\CalendarWidgetV2; use OCA\Calendar\Events\BeforeAppointmentBookedEvent; use OCA\Calendar\Listener\AppointmentBookedListener; +use OCA\Calendar\Listener\CalendarObjectCreatedListener; use OCA\Calendar\Listener\CalendarReferenceListener; use OCA\Calendar\Listener\UserDeletedListener; use OCA\Calendar\Notification\Notifier; use OCA\Calendar\Profile\AppointmentsAction; use OCA\Calendar\Reference\ReferenceProvider; +use OCA\DAV\Events\CalendarObjectCreatedEvent; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -73,7 +75,7 @@ class Application extends App implements IBootstrap { $context->registerEventListener(BeforeAppointmentBookedEvent::class, AppointmentBookedListener::class); $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(RenderReferenceEvent::class, CalendarReferenceListener::class); - + $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class); $context->registerNotifierService(Notifier::class); } diff --git a/calendar/lib/Listener/CalendarObjectCreatedListener.php b/calendar/lib/Listener/CalendarObjectCreatedListener.php new file mode 100644 index 0000000..0365b1e --- /dev/null +++ b/calendar/lib/Listener/CalendarObjectCreatedListener.php @@ -0,0 +1,59 @@ + + * + * @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\Calendar\Listener; + +use OCA\Calendar\Service\Appointments\BookingService; +use OCA\Calendar\Service\Calendar\CalendarService; +use OCA\DAV\Events\CalendarObjectCreatedEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use Psr\Log\LoggerInterface; + +class CalendarObjectCreatedListener implements IEventListener { + + /** @var LoggerInterface */ + private $logger; + + /** @var \OCA\Calendar\Service\Calendar\CalendarService* */ + private $calendarService; + + public function __construct( + LoggerInterface $logger,CalendarService $calendarService) { + $this->logger = $logger; + $this->calendarService = $calendarService; + } + + public function handle(Event $event): void { + if (!($event instanceof CalendarObjectCreatedEvent)) { + return; + } + $calendarData = $event->getObjectData(); + $vCalendarString = $calendarData["calendardata"]; + $calendarSummary = $this->calendarService->GetCalendarSummaryFromVCalendarString($vCalendarString); + $this->calendarService->createDefuntFromCalendarSummary($calendarSummary); + } + +} diff --git a/calendar/lib/Service/Calendar/CalendarService.php b/calendar/lib/Service/Calendar/CalendarService.php new file mode 100644 index 0000000..a80f17e --- /dev/null +++ b/calendar/lib/Service/Calendar/CalendarService.php @@ -0,0 +1,59 @@ + + * + * @author Anna Larch + * @author Richard Steinmetz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 library. If not, see . + * + */ + +namespace OCA\Calendar\Service\Calendar; + +use OCA\Gestion\Db\Bdd; +use Psr\Log\LoggerInterface; + +class CalendarService { + /** @var Bdd */ + private $gestionMapper; + + /** @var LoggerInterface */ + private $logger; + + public function __construct( + Bdd $gestionMapper, + LoggerInterface $logger) { + $this->logger = $logger; + $this->gestionMapper = $gestionMapper; + } + + public function createDefuntFromCalendarSummary($calendarSummary): bool{ + return $this->gestionMapper->insertDefuntByName($calendarSummary); + } + + public function GetCalendarSummaryFromVCalendarString(string $vCalendarString): string + { + $summaryValue = "Nom du défunt"; + preg_match('/SUMMARY:(.*)\r\n/', $vCalendarString, $matches); + if (isset($matches[1])) { + $summaryValue = trim($matches[1]); + } + return $summaryValue; + } +} diff --git a/calendar/src/mixins/EditorMixin.js b/calendar/src/mixins/EditorMixin.js index 41d2d77..a558e93 100644 --- a/calendar/src/mixins/EditorMixin.js +++ b/calendar/src/mixins/EditorMixin.js @@ -99,6 +99,17 @@ export default { location() { return this.calendarObjectInstance?.location ?? null }, + + /** + * Returns the client or null if the event is still loading + * + * @return {string|null} + */ + client() { + return this.calendarObjectInstance?.client ?? null + }, + + /** * Returns the description or null if the event is still loading * @@ -322,7 +333,7 @@ export default { * Returns an object with properties from RFCs including * their displayName, a description, options, etc. * - * @return {{geo, color, timeTransparency, description, resources, location, categories, accessClass, priority, status, locations, articles}} + * @return {{geo, color, timeTransparency, description, resources, location, client, categories, accessClass, priority, status, locations, articles, clients}} */ rfcProps() { return getRFCProperties() @@ -476,6 +487,7 @@ export default { * @return {Promise} */ async save(thisAndAllFuture = false) { + console.log("MIDITRA ATO NY SAVE",this.calendarObject); if (!this.calendarObject) { logger.error('Calendar-object not found') return @@ -594,6 +606,19 @@ export default { location, }) }, + + /** + * Updates the client of the event + * + * @param {string} client New client + */ + updateClient(client) { + this.$store.commit('changeClient', { + calendarObjectInstance: this.calendarObjectInstance, + client, + }) + }, + /** * Updates the start date of this event * diff --git a/calendar/src/models/calendarObject.js b/calendar/src/models/calendarObject.js index da98350..84eb6af 100644 --- a/calendar/src/models/calendarObject.js +++ b/calendar/src/models/calendarObject.js @@ -106,6 +106,7 @@ const mapCDavObjectToCalendarObject = (dav, calendarId) => { * @return {object} */ const mapCalendarJsToCalendarObject = (calendarComponent, calendarId = null) => { + console.log("Ary ato mapCalendarJsToCalendarObject"); const vObjectIterator = calendarComponent.getVObjectIterator() const firstVObject = vObjectIterator.next().value if (!firstVObject) { diff --git a/calendar/src/models/event.js b/calendar/src/models/event.js index 693fb9b..c0e1a17 100644 --- a/calendar/src/models/event.js +++ b/calendar/src/models/event.js @@ -56,6 +56,8 @@ const getDefaultEventObject = (props = {}) => Object.assign({}, { canModifyAllDay: true, // Location that the event takes places in location: null, + //client of the event + client : null, // description of the event description: null, // Access class of the event (PUBLIC, PRIVATE, CONFIDENTIAL) @@ -102,6 +104,7 @@ const mapEventComponentToEventObject = (eventComponent) => { isAllDay: eventComponent.isAllDay(), canModifyAllDay: eventComponent.canModifyAllDay(), location: eventComponent.location, + client : eventComponent.client, description: eventComponent.description, accessClass: eventComponent.accessClass, status: eventComponent.status, @@ -199,6 +202,7 @@ const mapEventComponentToEventObject = (eventComponent) => { const copyCalendarObjectInstanceIntoEventComponent = (eventObject, eventComponent) => { eventComponent.title = eventObject.title eventComponent.location = eventObject.location + eventComponent.client = eventObject.client eventComponent.description = eventObject.description eventComponent.accessClass = eventObject.accessClass eventComponent.status = eventObject.status diff --git a/calendar/src/models/rfcProps.js b/calendar/src/models/rfcProps.js index 49e2e7b..3144cce 100644 --- a/calendar/src/models/rfcProps.js +++ b/calendar/src/models/rfcProps.js @@ -125,6 +125,23 @@ const getRFCProperties = () => { options: [], }, + clients: { + readableName: t('calendar', 'Clients'), + icon: 'Tag', + searchable: true, + multiple: false, + info: t('calendar', 'Client from Gestion'), + placeholder: t('calendar', 'Add client'), + tagPlaceholder: t('calendar', 'Add client'), + options: [], + }, + + client: { + readableName: t('calendar', 'client'), + placeholder: t('calendar', 'Add a client'), + icon: 'MapMarker', + }, + articles: { readableName: t('calendar', 'Articles'), icon: 'TextBoxOutline', diff --git a/calendar/src/store/calendarObjectInstance.js b/calendar/src/store/calendarObjectInstance.js index c04c305..76ef030 100644 --- a/calendar/src/store/calendarObjectInstance.js +++ b/calendar/src/store/calendarObjectInstance.js @@ -321,6 +321,12 @@ const mutations = { calendarObjectInstance.location = location }, + changeClient(state, { calendarObjectInstance, client }) { + console.log("CHANGE CLIENT STORE", client); + calendarObjectInstance.eventComponent.client = client + calendarObjectInstance.client = client + }, + /** * Change the description of an event * @@ -1656,6 +1662,10 @@ const actions = { async saveCalendarObjectInstance({ state, dispatch, commit }, { thisAndAllFuture, calendarId }) { const eventComponent = state.calendarObjectInstance.eventComponent const calendarObject = state.calendarObject + debugger + console.log("EVENNNNNNNTTT COMPONENTTTTT", eventComponent); + + console.log("CALEEEEENNNDDDARRRR OBJEEEEEEEECCCCC TTTTTTT",calendarObject); updateAlarms(eventComponent) updateTalkParticipants(eventComponent) @@ -1683,6 +1693,7 @@ const actions = { } if (calendarId !== state.calendarObject.calendarId) { + console.log("MIDITRA ATO AMIN NY MOVE CALENDAR"); await dispatch('moveCalendarObject', { calendarObject, newCalendarId: calendarId, diff --git a/calendar/src/store/settings.js b/calendar/src/store/settings.js index 2118116..35cdfc0 100644 --- a/calendar/src/store/settings.js +++ b/calendar/src/store/settings.js @@ -505,6 +505,7 @@ const actions = { 'SUMMARY', 'LOCATION', 'DESCRIPTION', + 'CLIENT' ]) }, } diff --git a/calendar/src/views/Calendar.vue b/calendar/src/views/Calendar.vue index 3ca309c..7476e72 100644 --- a/calendar/src/views/Calendar.vue +++ b/calendar/src/views/Calendar.vue @@ -31,6 +31,7 @@ + diff --git a/calendar/src/views/EditSidebar.vue b/calendar/src/views/EditSidebar.vue index f984234..3a23865 100644 --- a/calendar/src/views/EditSidebar.vue +++ b/calendar/src/views/EditSidebar.vue @@ -103,6 +103,14 @@ @update-end-timezone="updateEndTimezone" @toggle-all-day="toggleAllDay" /> + + + + 'page#ajaxGetLieux', 'url' => '/ajaxGetLieux', 'verb' => 'GET'], ['name' => 'page#ajaxGetArticles', 'url' => '/ajaxGetArticles', 'verb' => 'GET'], ['name' => 'page#ajaxGetProduits', 'url' => '/ajaxGetProduits', 'verb' => 'GET'], + ['name' => 'page#ajaxGetClientsName', 'url' => '/ajaxGetClientsName', 'verb' => 'GET'], ['name' => 'page#getLieux', 'url' => '/getLieux', 'verb' => 'PROPFIND'], ['name' => 'page#insertLieu', 'url' => '/lieu/insert', 'verb' => 'POST'], diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 9021862..32cf311 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -1257,6 +1257,14 @@ class PageController extends Controller { return $this->myDb->getLieux($this->idNextcloud); } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function ajaxGetClientsName() { + return $this->myDb->getClientsName(); + } + /** * @NoAdminRequired * @NoCSRFRequired diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 2b13364..8770c79 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -52,6 +52,13 @@ class Bdd { $sql = "SELECT * FROM ".$this->tableprefix."client;"; return $this->execSQL($sql, array()); } + + public function getClientsName(){ + $sql = "SELECT client.nom, client.prenom, client.id + FROM ".$this->tableprefix."client as client + ORDER BY client.id DESC"; + return $this->execSQL($sql, array()); + } public function getClient($id,$idNextcloud){ $sql = "SELECT * FROM ".$this->tableprefix."client WHERE id = ?"; @@ -653,6 +660,18 @@ class Bdd { return true; } + /** + * Insert Defunt + */ + public function insertDefuntByName($name) { + $sql = "INSERT INTO `".$this->tableprefix."defunt` ( + `id_nextcloud`, `nom`, `sexe`, `date_naissance`, `ref_pacemaker`, `date`, + `corpulence`, `observations_corps`, `observations_generales` + ) VALUES (?,?,?,?,?,NOW(),?,?,?);"; + $this->execSQLNoData($sql, array('admin',$name, 'm', '1973-11-11', 'Référence pacemaker', '', '', '')); + return true; + } + /** * Insert lieu */