core/lib/Thelia/Action/AttributeAv.php line 48

  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\Attribute\AttributeAvCreateEvent;
  15. use Thelia\Core\Event\Attribute\AttributeAvDeleteEvent;
  16. use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent;
  17. use Thelia\Core\Event\TheliaEvents;
  18. use Thelia\Core\Event\UpdatePositionEvent;
  19. use Thelia\Model\AttributeAv as AttributeAvModel;
  20. use Thelia\Model\AttributeAvQuery;
  21. class AttributeAv extends BaseAction implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * Create a new attribute entry.
  25.      */
  26.     public function create(AttributeAvCreateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  27.     {
  28.         $attribute = new AttributeAvModel();
  29.         $attribute
  30.             ->setAttributeId($event->getAttributeId())
  31.             ->setLocale($event->getLocale())
  32.             ->setTitle($event->getTitle())
  33.             ->save()
  34.         ;
  35.         $event->setAttributeAv($attribute);
  36.     }
  37.     /**
  38.      * Change a product attribute.
  39.      */
  40.     public function update(AttributeAvUpdateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  41.     {
  42.         if (null !== $attribute AttributeAvQuery::create()->findPk($event->getAttributeAvId())) {
  43.             $attribute
  44.                 ->setLocale($event->getLocale())
  45.                 ->setTitle($event->getTitle())
  46.                 ->setDescription($event->getDescription())
  47.                 ->setChapo($event->getChapo())
  48.                 ->setPostscriptum($event->getPostscriptum())
  49.                 ->save();
  50.             $event->setAttributeAv($attribute);
  51.         }
  52.     }
  53.     /**
  54.      * Delete a product attribute entry.
  55.      */
  56.     public function delete(AttributeAvDeleteEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  57.     {
  58.         if (null !== ($attribute AttributeAvQuery::create()->findPk($event->getAttributeAvId()))) {
  59.             $attribute
  60.                 ->delete()
  61.             ;
  62.             $event->setAttributeAv($attribute);
  63.         }
  64.     }
  65.     /**
  66.      * Changes position, selecting absolute ou relative change.
  67.      */
  68.     public function updatePosition(UpdatePositionEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  69.     {
  70.         $this->genericUpdatePosition(AttributeAvQuery::create(), $event);
  71.     }
  72.     /**
  73.      * {@inheritdoc}
  74.      */
  75.     public static function getSubscribedEvents()
  76.     {
  77.         return [
  78.             TheliaEvents::ATTRIBUTE_AV_CREATE => ['create'128],
  79.             TheliaEvents::ATTRIBUTE_AV_UPDATE => ['update'128],
  80.             TheliaEvents::ATTRIBUTE_AV_DELETE => ['delete'128],
  81.             TheliaEvents::ATTRIBUTE_AV_UPDATE_POSITION => ['updatePosition'128],
  82.         ];
  83.     }
  84. }