wip listener on moveCalendarobject to trash

This commit is contained in:
Tiavina 2025-01-14 12:56:22 +03:00
parent 6da74fa407
commit d7a8e8167f
6 changed files with 134 additions and 1 deletions

View File

@ -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 {

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace OCA\Gestion\Constants;
abstract class DevisMentionConstant
{
const DEFAULT_CALENDAR_UUID_FOR_DEVIS = "not-related";
const FACTURED = "factur&eacute;";
const MENTION = "mention";
const NEW = "Nouveau";
const CANCELED = "CANCELED";
}

View File

@ -5,6 +5,7 @@ use OCA\Gestion\Helpers\DateHelpers;
use OCP\IDBConnection;
use OCP\IL10N;
use \Datetime;
use OCA\Gestion\Constants\DevisMentionConstant;
use OCA\Gestion\Constants\ProductConstant;
use OCA\Gestion\Helpers\FileExportHelpers;
use Psr\Log\LoggerInterface;
@ -3021,6 +3022,32 @@ class Bdd {
$message .= ". COMMENTAIRES: ".html_entity_decode($devis->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]);
}
}

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/*
* @copyright 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@ -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);

View File

@ -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&eacute;'){
return 'green';
}
if(mention === 'CANCELED'){
return 'red';
}
return 'yellow';
}
static getDevisProduitsString(myresp){
let devisProduitsAsString = '';
if(myresp.produits != null && myresp.produits.length > 0){