/** * @param Channel $channel */ protected function validateCustomerIdentity(Channel $channel) { $errorLabel = 'orocrm.channel.form.customer_identity_selected_not_correctly.label'; $fieldName = 'customerIdentity'; $entities = $channel->getEntities(); if (!in_array($channel->getCustomerIdentity(), $entities)) { $this->context->addViolationAt($fieldName, $errorLabel); } }
/** * @param Channel $entity * * @return bool */ public function isApplicable($entity) { if (!$entity instanceof Channel) { return false; } $customerIdentity = $entity->getCustomerIdentity(); if (empty($customerIdentity)) { return false; } return in_array($this->interface, class_implements($customerIdentity), true); }
/** * @param Channel $channel */ protected function updateLifetimeForAccounts(Channel $channel) { $lifetimeFields = $this->getLifetimeFieldsMap(); $customerIdentity = $channel->getCustomerIdentity(); if (!isset($lifetimeFields[$customerIdentity])) { return; } $lifetimeFieldName = $lifetimeFields[$customerIdentity]; $accountRepo = $this->em->getRepository('OroCRMAccountBundle:Account'); $accountIterator = new BufferedQueryResultIterator($accountRepo->createQueryBuilder('a')->select('a.id')); $accountIterator->setBufferSize(self::UPDATE_LIFETIME_READ_BATCH_SIZE); $accountIds = []; foreach ($accountIterator as $accountRow) { $accountIds[] = $accountRow['id']; if (count($accountIds) === self::UPDATE_LIFETIME_WRITE_BATCH_SIZE) { $this->updateLifetime($accountIds, $channel, $customerIdentity, $lifetimeFieldName); $accountIds = []; } } if (count($accountIds) > 0) { $this->updateLifetime($accountIds, $channel, $customerIdentity, $lifetimeFieldName); } }
/** * {@inheritdoc} */ public function supports(Channel $channel) { $entityFQCN = $channel->getCustomerIdentity(); return is_a($entityFQCN, 'OroCRM\\Bundle\\AnalyticsBundle\\Model\\RFMAwareInterface', true) && is_a($entityFQCN, 'OroCRM\\Bundle\\ChannelBundle\\Model\\CustomerIdentityInterface', true) && is_a($entityFQCN, $this->className, true); }
public function testPostSubmit() { $data = new Channel(); $data->setChannelType(self::TEST_CHANNEL_TYPE); $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $event = new FormEvent($form, $data); $this->subscriber->postSubmit($event); $this->assertEquals(self::TEST_CUSTOMER_IDENTITY, $data->getCustomerIdentity()); }
/** * @param Channel $channel * @param array $ids * @return \ArrayIterator|BufferedQueryResultIterator */ protected function getEntityIdsByChannel(Channel $channel, array $ids = []) { $entityFQCN = $channel->getCustomerIdentity(); $qb = $this->doctrineHelper->getEntityRepository($entityFQCN)->createQueryBuilder('e'); $metadata = $this->doctrineHelper->getEntityMetadataForClass($entityFQCN); $metrics = []; foreach ($this->providers as $provider) { if ($provider->supports($channel) && $metadata->hasField($provider->getType())) { $metrics[] = $provider->getType(); } } if (count($metrics) === 0) { return new \ArrayIterator(); } $idField = sprintf('e.%s', $this->doctrineHelper->getSingleEntityIdentifierFieldName($entityFQCN)); $qb->select(preg_filter('/^/', 'e.', $metrics))->addSelect($idField . ' as id')->where('e.dataChannel = :dataChannel')->orderBy($qb->expr()->asc($idField))->setParameter('dataChannel', $channel); if (count($ids) !== 0) { $qb->andWhere($qb->expr()->in($idField, ':ids'))->setParameter('ids', $ids); } return (new BufferedQueryResultIterator($qb))->setBufferSize(self::BATCH_SIZE); }
/** * @param Channel $channel * * @return bool */ protected function isApplicable(Channel $channel = null) { if (!$channel) { return false; } $customerIdentity = $channel->getCustomerIdentity(); if (!$customerIdentity) { return false; } return in_array($this->interface, class_implements($customerIdentity), true); }
/** * @param Channel $channel * @param array $ids * * @return BufferedQueryResultIterator|CustomerIdentity[] */ protected function getEntitiesByChannel(Channel $channel, array $ids = []) { $entityFQCN = $channel->getCustomerIdentity(); $qb = $this->getDoctrineHelper()->getEntityRepository($entityFQCN)->createQueryBuilder('e'); $qb->orderBy(sprintf('e.%s', $this->getDoctrineHelper()->getSingleEntityIdentifierFieldName($entityFQCN))); $qb->andWhere('e.dataChannel = :dataChannel'); $qb->setParameter('dataChannel', $channel); if ($ids) { $qb->andWhere($qb->expr()->in('e.id', ':ids')); $qb->setParameter('ids', $ids); } $iterator = new BufferedQueryResultIterator($qb); // !!! should be the same as flush batch, will not work otherwise because of detached entities after EM#clear() $iterator->setBufferSize(self::BATCH_SIZE); return $iterator; }