src/EventListener/TechnicalNoteListener.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\ActionLog;
  4. use App\Manager\TechnicalNoteManager;
  5. use App\Service\ActionLogService;
  6. use App\Service\ControlService;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. use Pimcore\Event\Model\DataObjectEvent;
  9. use Psr\Log\LoggerInterface;
  10. use Symfony\Contracts\HttpClient\HttpClientInterface;
  11. class TechnicalNoteListener
  12. {
  13.     private HttpClientInterface $client;
  14.     private TechnicalNoteManager $technicalNoteManager;
  15.     private LoggerInterface $logger;
  16.     private $shercoNetworkSync;
  17.     private ActionLogService $actionLogService;
  18.     private ControlService $controlService;
  19.     private $managerRegistry;
  20.     public function __construct($shercoNetworkSyncHttpClientInterface $clientTechnicalNoteManager $technicalNoteManager,
  21.                                 LoggerInterface $loggerActionLogService $actionLogServiceControlService $controlServiceManagerRegistry $managerRegistry)
  22.     {
  23.         $this->shercoNetworkSync $shercoNetworkSync;
  24.         $this->client $client;
  25.         $this->technicalNoteManager $technicalNoteManager;
  26.         $this->logger $logger;
  27.         $this->actionLogService $actionLogService;
  28.         $this->controlService $controlService;
  29.         $this->managerRegistry $managerRegistry;
  30.     }
  31.     public function onTechnicalNotePostAdd(DataObjectEvent $o)
  32.     {
  33.         $technicalNote $o->getObject();
  34.         if ($this->technicalNoteManager->objectIsTechnicalNote($technicalNote)) {
  35.             $type 'technicalNote';
  36.             if ($technicalNote->getType() != 'folder') {
  37.                 if ($technicalNote->get("o_className") == "TechnicalNote") {
  38.                     $statut $technicalNote->isPublished() ? 'valide' 'en-cours';
  39.                     $this->actionLogService->logActionTechnicalNote($o'add'$type$statut);
  40.                 }
  41.             }
  42.         }
  43.     }
  44.     public function onTechnicalNotePostUpdate(DataObjectEvent $o)
  45.     {
  46.         $technicalNote $o->getObject();
  47.         if ($technicalNote->getType() != 'folder') {
  48.             if ($technicalNote->get("o_className") == "TechnicalNote") {
  49.                 if ($technicalNote->isPublished()) {
  50.                     $this->actionLogService->logActionTechnicalNote($o'update''technicalNote'"valide");
  51.                 } else {
  52.                     $repository $this->managerRegistry->getRepository(ActionLog::class);
  53.                     $actionLog $repository->findOneBy(['objectId' => $technicalNote->getId(), 'status' => "valide"], ['date' => 'desc']);
  54.                     if (isset($actionLog) && $actionLog->getAction() != 'delete') {
  55.                         $this->actionLogService->logActionTechnicalNote($o'delete''technicalNote'"valide");
  56.                     } else {
  57.                         $this->actionLogService->logActionTechnicalNote($o'update''technicalNote'"en-cours");
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63.     public function onTechnicalNotePostDelete(DataObjectEvent $o)
  64.     {
  65.         $technicalNote $o->getObject();
  66.         if ($this->technicalNoteManager->objectIsTechnicalNote($technicalNote)) {
  67.             $type 'technicalNote';
  68.             if ($technicalNote->getType() != 'folder') {
  69.                 if ($technicalNote->get("o_className") == "TechnicalNote") {
  70.                     if ($technicalNote->isPublished()) {
  71.                         $repository $this->managerRegistry->getRepository(ActionLog::class);
  72.                         $actionLog $repository->findOneBy(['objectId' => $technicalNote->getId(), 'status' => "valide"], ['date' => 'desc']);
  73.                         if (isset($actionLog) && $actionLog->getAction() != 'delete') {
  74.                             $this->actionLogService->logActionTechnicalNote($o'delete'$type"valide");
  75.                         }
  76.                     } else {
  77.                         $this->actionLogService->logActionTechnicalNote($o'delete''technicalNote'"en-cours");
  78.                     }
  79.                 }
  80.             }
  81.         }
  82.     }
  83. }