/** * Get all recipients. * * @param int $limit Limit result to given count. * @param int $offset Skip certain count of recipients. * * @return RecipientInterface[] */ public function getRecipients($limit = null, $offset = null) { if (empty($this->set)) { $this->set = array(); $count = rand($this->minCount, $this->maxCount); for ($i = 0; $i < $count; $i++) { list($forename, $surname, $name, $domain) = $this->createName(); $recipient = new MutableRecipient($name . '@' . $domain); $recipient->set('forename', $forename); $recipient->set('surname', $surname); $this->set[] = $recipient; } } $set = $this->set; if ($offset > 0) { $set = array_slice($set, $offset); } if ($limit > 0 && $limit < count($set)) { $set = array_slice($set, 0, $limit); } return $set; }
/** * Get all recipients. * * @param int $limit Limit result to given count. * @param int $offset Skip certain count of recipients. * * @return RecipientInterface[] */ public function getRecipients($limit = null, $offset = null) { global $container; $recipients = $this->recipientSource->getRecipients($limit, $offset); if (count($recipients)) { /** @var Selector $selector */ $selector = $container['avisota.salutation.selector']; /** @var TagReplacementService $tagReplacer */ $tagReplacer = $container['avisota.message.tagReplacementEngine']; foreach ($recipients as $recipient) { if ($recipient->get('salutation')) { continue; } if (!$recipient instanceof MutableRecipient) { $recipient = new MutableRecipient($recipient->getEmail(), $recipient->getDetails()); } $salutation = $selector->selectSalutation($recipient, $this->group); if (!$salutation) { continue; } /** @var SynonymizerService $synonymizer */ $synonymizer = $container['avisota.recipient.synonymizer']; $pattern = $salutation->getSalutation(); $details = $synonymizer->expandDetailsWithSynonyms($recipient); $buffer = $tagReplacer->parse($pattern, $details); $recipient->set('salutation', $buffer); } } return $recipients; }
/** * @param RecipientInterface $recipient * @param Message|null $message * @SuppressWarnings(PHPMD.LongVariable) */ protected function addSalutationToRecipient(RecipientInterface $recipient, Message $message = null) { global $container; if ($recipient->get('salutation') || !$message) { return; } $salutationGroupId = $message->getCategory()->getSalutation(); if (!$salutationGroupId) { return; } $salutationGroupRepository = EntityHelper::getRepository('Avisota\\Contao:SalutationGroup'); $salutationGroup = $salutationGroupRepository->find($salutationGroupId); if (!$salutationGroup) { return; } /** @var Selector $selector */ $selector = $container['avisota.salutation.selector']; /** @var TagReplacementService $tagReplacer */ $tagReplacer = $container['avisota.message.tagReplacementEngine']; if (!$recipient instanceof MutableRecipient) { $recipient = new MutableRecipient($recipient->getEmail(), $recipient->getDetails()); } $salutation = $selector->selectSalutation($recipient, $salutationGroup); if (!$salutation) { return; } $pattern = $salutation->getSalutation(); $buffer = $tagReplacer->parse($pattern, $recipient->getDetails()); $recipient->set('salutation', $buffer); }