![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/LeadBundle/EventListener/ |
<?php declare(strict_types=1); namespace Mautic\LeadBundle\EventListener; use Mautic\DynamicContentBundle\DynamicContentEvents; use Mautic\DynamicContentBundle\Event\ContactFiltersEvaluateEvent; use Mautic\LeadBundle\Entity\Lead; use Mautic\LeadBundle\Entity\LeadListRepository; use Mautic\LeadBundle\Segment\OperatorOptions; use Symfony\Component\EventDispatcher\EventSubscriberInterface; final class DynamicContentSubscriber implements EventSubscriberInterface { public function __construct(private LeadListRepository $segmentRepository) { } public static function getSubscribedEvents(): array { return [ DynamicContentEvents::ON_CONTACTS_FILTER_EVALUATE => ['onContactFilterEvaluate', 0], ]; } public function onContactFilterEvaluate(ContactFiltersEvaluateEvent $event): void { foreach ($event->getFilters() as $filter) { if ('leadlist' === $filter['type']) { // Segment membership evaluation. Check if contact/segment relationship is correct. $event->setIsMatched( $this->isContactSegmentRelationshipValid($event->getContact(), $filter['operator'], $filter['filter']) ); $event->setIsEvaluated(true); return; } } } /** * @param string $operator empty, !empty, in, !in * @param ?int[] $segmentIds */ private function isContactSegmentRelationshipValid(Lead $contact, string $operator, array $segmentIds = null): bool { $contactId = (int) $contact->getId(); return match ($operator) { OperatorOptions::EMPTY => $this->segmentRepository->isNotContactInAnySegment($contactId), OperatorOptions::NOT_EMPTY => $this->segmentRepository->isContactInAnySegment($contactId), OperatorOptions::IN => $this->segmentRepository->isContactInSegments($contactId, $segmentIds), OperatorOptions::NOT_IN => $this->segmentRepository->isNotContactInSegments($contactId, $segmentIds), default => throw new \InvalidArgumentException(sprintf("Unexpected operator '%s'", $operator)), }; } }