Spaces:
No application file
No application file
File size: 1,329 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<?php
namespace Mautic\LeadBundle\Twig\Helper;
use Mautic\LeadBundle\Entity\DoNotContact;
use Mautic\LeadBundle\Exception\UnknownDncReasonException;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Convert DNC reason ID to text.
*/
final class DncReasonHelper
{
public function __construct(
private TranslatorInterface $translator
) {
}
/**
* Convert DNC reason ID to text.
*
* @throws UnknownDncReasonException
*/
public function toText(int $reasonId): string
{
$reasonKey = match ($reasonId) {
DoNotContact::IS_CONTACTABLE => 'mautic.lead.event.donotcontact_contactable',
DoNotContact::UNSUBSCRIBED => 'mautic.lead.event.donotcontact_unsubscribed',
DoNotContact::BOUNCED => 'mautic.lead.event.donotcontact_bounced',
DoNotContact::MANUAL => 'mautic.lead.event.donotcontact_manual',
default => throw new UnknownDncReasonException(sprintf("Unknown DNC reason ID '%c'", $reasonId)),
};
return $this->translator->trans($reasonKey);
}
/**
* Returns the canonical name of this helper.
*
* @return string The canonical name
*/
public function getName(): string
{
return 'lead_dnc_reason';
}
}
|