wip listener on moveCalendarobject to trash
This commit is contained in:
parent
6da74fa407
commit
d7a8e8167f
@ -5,7 +5,10 @@
|
|||||||
namespace OCA\Gestion\AppInfo;
|
namespace OCA\Gestion\AppInfo;
|
||||||
|
|
||||||
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
||||||
|
use OCA\DAV\Events\CalendarObjectDeletedEvent;
|
||||||
|
use OCA\DAV\Events\CalendarObjectMovedToTrashEvent;
|
||||||
use OCA\Gestion\Listener\CalendarObjectCreatedListener;
|
use OCA\Gestion\Listener\CalendarObjectCreatedListener;
|
||||||
|
use OCA\Gestion\Listener\CalendarObjectMovedToTrashListener;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
@ -21,6 +24,7 @@ class Application extends App implements IBootstrap {
|
|||||||
|
|
||||||
public function register(IRegistrationContext $context): void {
|
public function register(IRegistrationContext $context): void {
|
||||||
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class);
|
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class);
|
||||||
|
$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectMovedToTrashListener::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(IBootContext $context): void {
|
public function boot(IBootContext $context): void {
|
||||||
|
|||||||
13
gestion/lib/Constants/DevisMentionConstant.php
Normal file
13
gestion/lib/Constants/DevisMentionConstant.php
Normal 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é";
|
||||||
|
const MENTION = "mention";
|
||||||
|
const NEW = "Nouveau";
|
||||||
|
const CANCELED = "CANCELED";
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ use OCA\Gestion\Helpers\DateHelpers;
|
|||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use \Datetime;
|
use \Datetime;
|
||||||
|
use OCA\Gestion\Constants\DevisMentionConstant;
|
||||||
use OCA\Gestion\Constants\ProductConstant;
|
use OCA\Gestion\Constants\ProductConstant;
|
||||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@ -3022,5 +3023,31 @@ class Bdd {
|
|||||||
return $message;
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
58
gestion/lib/Listener/CalendarObjectMovedToTrashListener.php
Normal file
58
gestion/lib/Listener/CalendarObjectMovedToTrashListener.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -127,6 +127,16 @@ class GestionService {
|
|||||||
return $calendarStartDate;
|
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){
|
public function HandleCreatedCalendarObject(string $vCalendarString){
|
||||||
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
||||||
$clientId = $this->GetClientIdFromVCalendarString($vCalendarString);
|
$clientId = $this->GetClientIdFromVCalendarString($vCalendarString);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ export class Devis {
|
|||||||
* Devis object
|
* Devis object
|
||||||
* @param myresp instantiate devis object
|
* @param myresp instantiate devis object
|
||||||
*/
|
*/
|
||||||
|
|
||||||
constructor(myresp) {
|
constructor(myresp) {
|
||||||
this.id = myresp.id;
|
this.id = myresp.id;
|
||||||
this.user_id = myresp.user_id;
|
this.user_id = myresp.user_id;
|
||||||
@ -26,13 +27,23 @@ export class Devis {
|
|||||||
this.nomThanato = Devis.getDevisThanatoFullname(myresp);
|
this.nomThanato = Devis.getDevisThanatoFullname(myresp);
|
||||||
this.version = ((myresp.version == null || myresp.version.length === 0) ? '-' : myresp.version);
|
this.version = ((myresp.version == null || myresp.version.length === 0) ? '-' : myresp.version);
|
||||||
this.lieu = ((myresp.lieu == null || myresp.lieu.length === 0) ? '-' : myresp.lieu);
|
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.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.devisFullNumber = ((myresp.devis_full_number != null && myresp.mentions.devis_full_number != 0) ? myresp.devis_full_number : '-');
|
||||||
|
|
||||||
this.devisProduits = Devis.getDevisProduitsString(myresp);
|
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){
|
static getDevisThanatoFullname(myresp){
|
||||||
let thanatoPrenom = '';
|
let thanatoPrenom = '';
|
||||||
let thanatoNom = '';
|
let thanatoNom = '';
|
||||||
@ -51,6 +62,16 @@ export class Devis {
|
|||||||
return (thanatoFullName.length === 0) ? '-' : thanatoFullName;
|
return (thanatoFullName.length === 0) ? '-' : thanatoFullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getDevisMentionColumnColor(mention) {
|
||||||
|
if(mention === 'facturé'){
|
||||||
|
return 'green';
|
||||||
|
}
|
||||||
|
if(mention === 'CANCELED'){
|
||||||
|
return 'red';
|
||||||
|
}
|
||||||
|
return 'yellow';
|
||||||
|
}
|
||||||
|
|
||||||
static getDevisProduitsString(myresp){
|
static getDevisProduitsString(myresp){
|
||||||
let devisProduitsAsString = '';
|
let devisProduitsAsString = '';
|
||||||
if(myresp.produits != null && myresp.produits.length > 0){
|
if(myresp.produits != null && myresp.produits.length > 0){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user