Cdp/Transverse/Log/EventListener/LogPiecesJointesEventSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace Cdp\Transverse\Log\EventListener;
  3. use Cdp\GroupeProjets\GroupeProjets\Entity\Fond\GroupeProjets;
  4. use Cdp\GroupeProjets\Outils\Entity\Fond\Actions;
  5. use Cdp\GroupeProjets\Outils\Entity\Fond\Outils;
  6. use Cdp\GroupeProjets\Outils\Entity\Fond\Prets;
  7. use Cdp\Transverse\Log\Entity\EntityHasWatchedLogInterface;
  8. use Cdp\Transverse\PiecesJointes\Event\PostUploadEvent;
  9. use Cdp\Transverse\PiecesJointes\Event\PreDeleteEvent;
  10. use Cdp\Transverse\PiecesJointes\Model\Document;
  11. use Cdp\Transverse\PiecesJointes\PiecesJointesEvents;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class LogPiecesJointesEventSubscriber extends AbstractLogEventSubscriber implements EventSubscriberInterface
  14. {
  15.     // ✗ - modification document outils / action / pret bancaire - ou GP -> ??? n'existe pas
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             PiecesJointesEvents::POST_UPLOAD => 'postUpload',
  20.             PiecesJointesEvents::PRE_DELETE => 'preDelete',
  21.         ];
  22.     }
  23.     public function postUpload(PostUploadEvent $event)
  24.     {
  25.         $document $event->getDocument();
  26.         $entity $document->getTarget();
  27.         if ($entity instanceof EntityHasWatchedLogInterface) {
  28.             $this->handleEntityDocumentInsertion($entity$document);
  29.         }
  30.     }
  31.     public function preDelete(PreDeleteEvent $event)
  32.     {
  33.         $document $event->getDocument();
  34.         $entity $document->getTarget();
  35.         if ($entity instanceof EntityHasWatchedLogInterface) {
  36.             $this->handleEntityDocumentDeletion($entity$document);
  37.         }
  38.     }
  39.     protected function handleEntityDocumentInsertion(EntityHasWatchedLogInterface $entityDocument $document)
  40.     {
  41.         // - ajout document outils / action / pret bancaire - ou GP
  42.         switch (true) {
  43.             case $entity instanceof GroupeProjets:
  44.                 $this->buildLog(
  45.                     sprintf("Document '%s' ajouté sur le projet '%s'"$document->getInfo()->getFilename(), $entity),
  46.                     [
  47.                         $entity,
  48.                     ]
  49.                 );
  50.                 break;
  51.             case $entity instanceof Outils:
  52.                 $this->buildLog(
  53.                     sprintf("Document '%s' ajouté sur l'outil '%s'"$document->getInfo()->getFilename(), $entity),
  54.                     [
  55.                         $entity,
  56.                         $entity->getGroupeProjet(),
  57.                     ]
  58.                 );
  59.                 break;
  60.             case $entity instanceof Actions:
  61.                 $this->buildLog(
  62.                     sprintf("Document '%s' ajouté sur l'action '%s'"$document->getInfo()->getFilename(), $entity),
  63.                     [
  64.                         $entity,
  65.                         $entity->getGroupeProjet(),
  66.                     ]
  67.                 );
  68.                 break;
  69.             case $entity instanceof Prets:
  70.                 $this->buildLog(
  71.                     sprintf("Document '%s' ajouté sur le Pret '%s'"$document->getInfo()->getFilename(), $entity),
  72.                     [
  73.                         $entity,
  74.                         $entity->getGroupeProjet(),
  75.                     ]
  76.                 );
  77.                 break;
  78.         }
  79.     }
  80.     protected function handleEntityDocumentDeletion(EntityHasWatchedLogInterface $entityDocument $document)
  81.     {
  82.         // - suppression document outils / action / pret bancaire - ou GP
  83.         switch (true) {
  84.             case $entity instanceof GroupeProjets:
  85.                 $this->buildLog(
  86.                     sprintf("Document '%s' supprimé sur le projet '%s'"$document->getInfo()->getFilename(), $entity),
  87.                     [
  88.                         $entity,
  89.                     ]
  90.                 );
  91.                 break;
  92.             case $entity instanceof Outils:
  93.                 $this->buildLog(
  94.                     sprintf("Document '%s' supprimé sur l'outil '%s'"$document->getInfo()->getFilename(), $entity),
  95.                     [
  96.                         $entity,
  97.                         $entity->getGroupeProjet(),
  98.                     ]
  99.                 );
  100.                 break;
  101.             case $entity instanceof Actions:
  102.                 $this->buildLog(
  103.                     sprintf("Document '%s' supprimé sur l'action '%s'"$document->getInfo()->getFilename(), $entity),
  104.                     [
  105.                         $entity,
  106.                         $entity->getGroupeProjet(),
  107.                     ]
  108.                 );
  109.                 break;
  110.             case $entity instanceof Prets:
  111.                 $this->buildLog(
  112.                     sprintf("Document '%s' supprimé sur le Pret '%s'"$document->getInfo()->getFilename(), $entity),
  113.                     [
  114.                         $entity,
  115.                         $entity->getGroupeProjet(),
  116.                     ]
  117.                 );
  118.                 break;
  119.         }
  120.     }
  121. }