/** * @param EmailCampaign $emailCampaign * @param object $entity * @return EmailCampaignStatistics */ public function getStatisticsRecord(EmailCampaign $emailCampaign, $entity) { $marketingList = $emailCampaign->getMarketingList(); $entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity); /** * Cache was added because there is a case: * - 2 email campaigns linked to one marketing list * - statistic can created using batches (marketing list item connector will be used) * and flush will be run once per N records creation * in this case same Marketing list entity will be received twice for one marketing list * and new MarketingListItem for same $marketingList and $entityId will be persisted twice. * * Marketing list name used as key for cache because Id can be empty and name is unique * */ if (empty($this->marketingListItemCache[$marketingList->getName()][$entityId])) { // Mark marketing list item as contacted $this->marketingListItemCache[$marketingList->getName()][$entityId] = $this->marketingListItemConnector->getMarketingListItem($marketingList, $entityId); } /** @var MarketingListItem $marketingListItem */ $marketingListItem = $this->marketingListItemCache[$marketingList->getName()][$entityId]; $manager = $this->doctrineHelper->getEntityManager($this->entityName); $statisticsRecord = null; if ($marketingListItem->getId() !== null) { $statisticsRecord = $manager->getRepository($this->entityName)->findOneBy(['emailCampaign' => $emailCampaign, 'marketingListItem' => $marketingListItem]); } if (!$statisticsRecord) { $statisticsRecord = new EmailCampaignStatistics(); $statisticsRecord->setEmailCampaign($emailCampaign)->setMarketingListItem($marketingListItem)->setOwner($emailCampaign->getOwner())->setOrganization($emailCampaign->getOrganization()); $manager->persist($statisticsRecord); } return $statisticsRecord; }
/** * {@inheritdoc} */ public function send(EmailCampaign $campaign, $entity, array $from, array $to) { $entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity); $marketingList = $campaign->getMarketingList(); /** @var EmailTemplate $template */ $template = $campaign->getTransportSettings()->getSettingsBag()->get('template'); list($subjectRendered, $templateRendered) = $this->emailRenderer->compileMessage($template, ['entity' => $entity]); $emailModel = new Email(); $emailModel->setType($template->getType())->setFrom($this->buildFullEmailAddress($from))->setEntityClass($marketingList->getEntity())->setEntityId($entityId)->setTo($to)->setSubject($subjectRendered)->setBody($templateRendered); $this->processor->process($emailModel); }
/** * @param EmailCampaign $emailCampaign * @param object $entity * @return EmailCampaignStatistics */ public function getStatisticsRecord(EmailCampaign $emailCampaign, $entity) { $marketingList = $emailCampaign->getMarketingList(); $entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity); // Mark marketing list item as contacted $marketingListItem = $this->marketingListItemConnector->getMarketingListItem($marketingList, $entityId); $manager = $this->doctrineHelper->getEntityManager($this->entityName); $statisticsRecord = null; if ($marketingListItem->getId() !== null) { $statisticsRecord = $manager->getRepository($this->entityName)->findOneBy(['emailCampaign' => $emailCampaign, 'marketingListItem' => $marketingListItem]); } if (!$statisticsRecord) { $statisticsRecord = new EmailCampaignStatistics(); $statisticsRecord->setEmailCampaign($emailCampaign)->setMarketingListItem($marketingListItem)->setOwner($emailCampaign->getOwner())->setOrganization($emailCampaign->getOrganization()); $manager->persist($statisticsRecord); } return $statisticsRecord; }
/** * @return \Iterator|null */ protected function getIterator() { return $this->marketingListProvider->getMarketingListEntitiesIterator($this->emailCampaign->getMarketingList()); }