core/lib/Thelia/Action/Message.php line 29

  1. <?php
  2. /*
  3.  * This file is part of the Thelia package.
  4.  * http://www.thelia.net
  5.  *
  6.  * (c) OpenStudio <info@thelia.net>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Thelia\Action;
  12. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Thelia\Core\Event\Message\MessageCreateEvent;
  15. use Thelia\Core\Event\Message\MessageDeleteEvent;
  16. use Thelia\Core\Event\Message\MessageUpdateEvent;
  17. use Thelia\Core\Event\TheliaEvents;
  18. use Thelia\Model\Message as MessageModel;
  19. use Thelia\Model\MessageQuery;
  20. class Message extends BaseAction implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * Create a new messageuration entry.
  24.      */
  25.     public function create(MessageCreateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  26.     {
  27.         $message = new MessageModel();
  28.         $message
  29.             ->setName($event->getMessageName())
  30.             ->setLocale($event->getLocale())
  31.             ->setTitle($event->getTitle())
  32.             ->setSecured($event->getSecured())
  33.             ->save()
  34.         ;
  35.         $event->setMessage($message);
  36.     }
  37.     /**
  38.      * Change a message.
  39.      */
  40.     public function modify(MessageUpdateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  41.     {
  42.         if (null !== $message MessageQuery::create()->findPk($event->getMessageId())) {
  43.             $message
  44.                 ->setName($event->getMessageName())
  45.                 ->setSecured($event->getSecured())
  46.                 ->setLocale($event->getLocale())
  47.                 ->setTitle($event->getTitle())
  48.                 ->setSubject($event->getSubject())
  49.                 ->setHtmlMessage($event->getHtmlMessage())
  50.                 ->setTextMessage($event->getTextMessage())
  51.                 ->setHtmlLayoutFileName($event->getHtmlLayoutFileName())
  52.                 ->setHtmlTemplateFileName($event->getHtmlTemplateFileName())
  53.                 ->setTextLayoutFileName($event->getTextLayoutFileName())
  54.                 ->setTextTemplateFileName($event->getTextTemplateFileName())
  55.                 ->save();
  56.             $event->setMessage($message);
  57.         }
  58.     }
  59.     /**
  60.      * Delete a messageuration entry.
  61.      */
  62.     public function delete(MessageDeleteEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  63.     {
  64.         if (null !== ($message MessageQuery::create()->findPk($event->getMessageId()))) {
  65.             $message
  66.                 ->delete()
  67.             ;
  68.             $event->setMessage($message);
  69.         }
  70.     }
  71.     /**
  72.      * {@inheritDoc}
  73.      */
  74.     public static function getSubscribedEvents()
  75.     {
  76.         return [
  77.             TheliaEvents::MESSAGE_CREATE => ['create'128],
  78.             TheliaEvents::MESSAGE_UPDATE => ['modify'128],
  79.             TheliaEvents::MESSAGE_DELETE => ['delete'128],
  80.         ];
  81.     }
  82. }