vendor/thelia/core/lib/Thelia/Action/FeatureAv.php line 32

Open in your IDE?
  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.      * @param $eventName
  27.      */
  28.     public function create(FeatureAvCreateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  29.     {
  30.         $feature = new FeatureAvModel();
  31.         $feature
  32.             ->setFeatureId($event->getFeatureId())
  33.             ->setLocale($event->getLocale())
  34.             ->setTitle($event->getTitle())
  35.             ->save()
  36.         ;
  37.         $event->setFeatureAv($feature);
  38.     }
  39.     /**
  40.      * Change a product feature.
  41.      *
  42.      * @param $eventName
  43.      */
  44.     public function update(FeatureAvUpdateEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  45.     {
  46.         if (null !== $feature FeatureAvQuery::create()->findPk($event->getFeatureAvId())) {
  47.             $feature
  48.                 ->setLocale($event->getLocale())
  49.                 ->setTitle($event->getTitle())
  50.                 ->setDescription($event->getDescription())
  51.                 ->setChapo($event->getChapo())
  52.                 ->setPostscriptum($event->getPostscriptum())
  53.                 ->save();
  54.             $event->setFeatureAv($feature);
  55.         }
  56.     }
  57.     /**
  58.      * Delete a product feature entry.
  59.      *
  60.      * @param $eventName
  61.      */
  62.     public function delete(FeatureAvDeleteEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  63.     {
  64.         if (null !== ($feature FeatureAvQuery::create()->findPk($event->getFeatureAvId()))) {
  65.             $feature
  66.                 ->delete()
  67.             ;
  68.             $event->setFeatureAv($feature);
  69.         }
  70.     }
  71.     /**
  72.      * Changes position, selecting absolute ou relative change.
  73.      *
  74.      * @param $eventName
  75.      */
  76.     public function updatePosition(UpdatePositionEvent $event$eventNameEventDispatcherInterface $dispatcher): void
  77.     {
  78.         $this->genericUpdatePosition(FeatureAvQuery::create(), $event$dispatcher);
  79.     }
  80.     /**
  81.      * {@inheritDoc}
  82.      */
  83.     public static function getSubscribedEvents()
  84.     {
  85.         return [
  86.             TheliaEvents::FEATURE_AV_CREATE => ['create'128],
  87.             TheliaEvents::FEATURE_AV_UPDATE => ['update'128],
  88.             TheliaEvents::FEATURE_AV_DELETE => ['delete'128],
  89.             TheliaEvents::FEATURE_AV_UPDATE_POSITION => ['updatePosition'128],
  90.         ];
  91.     }
  92. }