core/lib/Thelia/Action/FeatureAv.php line 49

  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\Feature\FeatureAvCreateEvent;
  15. use Thelia\Core\Event\Feature\FeatureAvDeleteEvent;
  16. use Thelia\Core\Event\Feature\FeatureAvUpdateEvent;
  17. use Thelia\Core\Event\TheliaEvents;
  18. use Thelia\Core\Event\UpdatePositionEvent;
  19. use Thelia\Model\FeatureAv as FeatureAvModel;
  20. use Thelia\Model\FeatureAvQuery;
  21. class FeatureAv extends BaseAction implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * Create a new feature entry.
  25.      */
  26.     public function create(FeatureAvCreateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  27.     {
  28.         $feature = new FeatureAvModel();
  29.         $feature
  30.             ->setFeatureId($event->getFeatureId())
  31.             ->setLocale($event->getLocale())
  32.             ->setTitle($event->getTitle())
  33.             ->save()
  34.         ;
  35.         $event->setFeatureAv($feature);
  36.     }
  37.     /**
  38.      * Change a product feature.
  39.      */
  40.     public function update(FeatureAvUpdateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  41.     {
  42.         if (null !== $feature FeatureAvQuery::create()->findPk($event->getFeatureAvId())) {
  43.             $feature
  44.                 ->setLocale($event->getLocale())
  45.                 ->setTitle($event->getTitle())
  46.                 ->setDescription($event->getDescription())
  47.                 ->setChapo($event->getChapo())
  48.                 ->setPostscriptum($event->getPostscriptum())
  49.                 ->save();
  50.             $event->setFeatureAv($feature);
  51.         }
  52.     }
  53.     /**
  54.      * Delete a product feature entry.
  55.      */
  56.     public function delete(FeatureAvDeleteEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  57.     {
  58.         if (null !== ($feature FeatureAvQuery::create()->findPk($event->getFeatureAvId()))) {
  59.             $feature
  60.                 ->delete()
  61.             ;
  62.             $event->setFeatureAv($feature);
  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(FeatureAvQuery::create(), $event$dispatcher);
  71.     }
  72.     /**
  73.      * {@inheritDoc}
  74.      */
  75.     public static function getSubscribedEvents()
  76.     {
  77.         return [
  78.             TheliaEvents::FEATURE_AV_CREATE => ['create'128],
  79.             TheliaEvents::FEATURE_AV_UPDATE => ['update'128],
  80.             TheliaEvents::FEATURE_AV_DELETE => ['delete'128],
  81.             TheliaEvents::FEATURE_AV_UPDATE_POSITION => ['updatePosition'128],
  82.         ];
  83.     }
  84. }