src/EventListener/EclateListener.php line 81

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\ActionLog;
  4. use App\Manager\EclateManager;
  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 EclateListener
  12. {
  13.     private HttpClientInterface $client;
  14.     private EclateManager $eclateManager;
  15.     private LoggerInterface $logger;
  16.     private $shercoNetworkSync;
  17.     private ActionLogService $actionLogService;
  18.     private ControlService $controlService;
  19.     private $managerRegistry;
  20.     public function __construct($shercoNetworkSyncHttpClientInterface $clientEclateManager $eclateManager,
  21.                                 LoggerInterface $loggerActionLogService $actionLogServiceControlService $controlServiceManagerRegistry $managerRegistry)
  22.     {
  23.         $this->shercoNetworkSync $shercoNetworkSync;
  24.         $this->client $client;
  25.         $this->eclateManager $eclateManager;
  26.         $this->logger $logger;
  27.         $this->actionLogService $actionLogService;
  28.         $this->controlService $controlService;
  29.         $this->managerRegistry $managerRegistry;
  30.     }
  31.     public function onEclatePostAdd(DataObjectEvent $o)
  32.     {
  33.         $eclate $o->getObject();
  34.         if ($this->eclateManager->objectIsEclate($eclate)) {
  35.             $type 'eclate';
  36.             if ($eclate->getType() != 'folder') {
  37.                 if ($eclate->get("o_className") == "Eclate") {
  38.                     $statut $eclate->isPublished() ? 'valide' 'en-cours';
  39.                     $this->actionLogService->logActionEclate($o'add'$type$statut);
  40.                 }
  41.             }
  42.         }
  43.     }
  44.     public function onEclatePostUpdate(DataObjectEvent $o)
  45.     {
  46.         $eclate $o->getObject();
  47.         if ($eclate->getType() != 'folder') {
  48.             if ($eclate->get("o_className") == "Eclate") {
  49.                 if ( $this->controlService->controlEclateReference($eclate)) {
  50.                     if ($eclate->isPublished()) {
  51.                         $this->actionLogService->logActionEclate($o'update''eclate'"valide");
  52.                     } else {
  53.                         $repository $this->managerRegistry->getRepository(ActionLog::class);
  54.                         $actionLog $repository->findOneBy(['objectId' => $eclate->getId(), 'status' => "valide"], ['date' => 'desc']);
  55.                         if (isset($actionLog) && $actionLog->getAction() != 'delete') {
  56.                             $this->actionLogService->logActionEclate($o'delete''eclate'"valide");
  57.                         } else {
  58.                             $this->actionLogService->logActionEclate($o'update''eclate'"en-cours");
  59.                         }
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.     }
  65.     public function onEclatePostDelete(DataObjectEvent $o)
  66.     {
  67.         $eclate $o->getObject();
  68.         if ($this->eclateManager->objectIsEclate($eclate)) {
  69.             $type 'eclate';
  70.             if ($eclate->getType() != 'folder') {
  71.                 if ($eclate->get("o_className") == "Eclate") {
  72.                     if ($eclate->isPublished()) {
  73.                         $repository $this->managerRegistry->getRepository(ActionLog::class);
  74.                         $actionLog $repository->findOneBy(['objectId' => $eclate->getId(), 'status' => "valide"], ['date' => 'desc']);
  75.                         if (isset($actionLog) && $actionLog->getAction() != 'delete') {
  76.                             $this->actionLogService->logActionEclate($o'delete'$type"valide");
  77.                         }
  78.                     } else {
  79.                         $this->actionLogService->logActionEclate($o'delete''eclate'"en-cours");
  80.                     }
  81.                 }
  82.             }
  83.         }
  84.     }
  85. }