vendor/pimcore/customer-management-framework-bundle/src/ActionTrigger/Event/SegmentTracked.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Enterprise License (PEL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  14.  */
  15. namespace CustomerManagementFrameworkBundle\ActionTrigger\Event;
  16. use CustomerManagementFrameworkBundle\ActionTrigger\RuleEnvironmentInterface;
  17. use CustomerManagementFrameworkBundle\ActionTrigger\Trigger\TriggerDefinitionInterface;
  18. use CustomerManagementFrameworkBundle\Model\CustomerInterface;
  19. use CustomerManagementFrameworkBundle\Model\CustomerSegmentInterface;
  20. class SegmentTracked extends AbstractSingleCustomerEvent implements RuleEnvironmentAwareEventInterface
  21. {
  22.     const EVENT_NAME 'plugin.cmf.segment-tracked';
  23.     const STORAGE_KEY 'segment_tracked';
  24.     /**
  25.      * @var CustomerSegmentInterface
  26.      */
  27.     private $segment;
  28.     /**
  29.      * @var int
  30.      */
  31.     private $count;
  32.     public static function create(CustomerInterface $customerCustomerSegmentInterface $segmentint $count)
  33.     {
  34.         $event = new self($customer);
  35.         $event->segment $segment;
  36.         $event->count   $count;
  37.         return $event;
  38.     }
  39.     public function getSegment(): CustomerSegmentInterface
  40.     {
  41.         return $this->segment;
  42.     }
  43.     public function getCount(): int
  44.     {
  45.         return $this->count;
  46.     }
  47.     public function getName()
  48.     {
  49.         return self::EVENT_NAME;
  50.     }
  51.     public function appliesToTrigger(TriggerDefinitionInterface $trigger)
  52.     {
  53.         if ($trigger->getEventName() === $this->getName()) {
  54.             return true;
  55.         }
  56.         return false;
  57.     }
  58.     public function updateEnvironment(TriggerDefinitionInterface $triggerRuleEnvironmentInterface $environment)
  59.     {
  60.         $environment->set(self::STORAGE_KEY, [
  61.             'id'    => $this->segment->getId(),
  62.             'count' => $this->count
  63.         ]);
  64.     }
  65. }