/**
  * @param StaticSegment $value
  * @param UniqueStaticSegmentNameConstraint|Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     if ($value instanceof StaticSegment && !$value->getOriginId()) {
         $this->transport->init($value->getChannel()->getTransport());
         $segments = $this->transport->getListStaticSegments($value->getSubscribersList());
         foreach ($segments as $segment) {
             if ($segment['name'] == $value->getName()) {
                 $this->context->addViolationAt('name', $constraint->message);
                 break;
             }
         }
     }
 }
 /**
  * @param StaticSegment $staticSegment
  * @param QueryBuilder $qb
  * @return void
  */
 public function prepareMarketingListEntities(StaticSegment $staticSegment, QueryBuilder $qb)
 {
     if (!$this->memberClassName) {
         throw new \InvalidArgumentException('Member class name must be provided');
     }
     $marketingList = $staticSegment->getMarketingList();
     $contactInformationFields = $this->contactInformationFieldsProvider->getMarketingListTypedFields($marketingList, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL);
     $expr = $qb->expr()->orX();
     foreach ($contactInformationFields as $contactInformationField) {
         $contactInformationFieldExpr = $this->fieldHelper->getFieldExpr($marketingList->getEntity(), $qb, $contactInformationField);
         $qb->addSelect($contactInformationFieldExpr . ' AS ' . $contactInformationField);
         $expr->add($qb->expr()->eq($contactInformationFieldExpr, sprintf('%s.%s', self::MEMBER_ALIAS, self::MEMBER_EMAIL_FIELD)));
     }
     $organization = $staticSegment->getChannel()->getOrganization();
     $metadata = $this->ownershipMetadataProvider->getMetadata($marketingList->getEntity());
     if ($organization && ($fieldName = $metadata->getOrganizationFieldName())) {
         $aliases = $qb->getRootAliases();
         $qb->andWhere($qb->expr()->eq(sprintf('%s.%s', reset($aliases), $fieldName), ':organization'));
         $qb->setParameter('organization', $organization);
     }
     $qb->leftJoin($this->memberClassName, self::MEMBER_ALIAS, Join::WITH, $qb->expr()->andX($expr, $qb->expr()->eq(sprintf('%s.subscribersList', self::MEMBER_ALIAS), ':subscribersList')))->setParameter('subscribersList', $staticSegment->getSubscribersList()->getId());
 }