Spaces:
No application file
No application file
File size: 3,222 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
<?php
namespace Mautic\ReportBundle\Scheduler\Model;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\CoreBundle\Helper\FileProperties;
use Mautic\ReportBundle\Entity\Report;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class MessageSchedule
{
public function __construct(
private TranslatorInterface $translator,
private FileProperties $fileProperties,
private CoreParametersHelper $coreParametersHelper,
private UrlGeneratorInterface $router
) {
}
/**
* @deprecated 2.15.2 to be removed in 3.0. Use getMessageForAttachedFile or getMessageForLinkedFile
*
* @param string $filePath
*
* @return string
*/
public function getMessage(Report $report, $filePath)
{
$link = $this->router->generate('mautic_report_view', ['objectId' => $report->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
if ($this->fileCouldBeSend($filePath)) {
$date = new \DateTime();
return $this->translator->trans(
'mautic.report.schedule.email.message',
['%report_name%' => $report->getName(), '%date%' => $date->format('Y-m-d'), '%link%' => $link]
);
}
return $this->translator->trans(
'mautic.report.schedule.email.message_file_not_attached',
['%report_name%' => $report->getName(), '%link%' => $link]
);
}
public function getMessageForAttachedFile(Report $report): string
{
$link = $this->router->generate('mautic_report_view', ['objectId' => $report->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
$date = new \DateTime();
return $this->translator->trans(
'mautic.report.schedule.email.message',
['%report_name%' => $report->getName(), '%date%' => $date->format('Y-m-d'), '%link%' => $link]
);
}
public function getMessageForLinkedFile(Report $report): string
{
$link = $this->router->generate('mautic_report_download', ['reportId' => $report->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
return $this->translator->trans(
'mautic.report.schedule.email.message_file_linked',
['%report_name%' => $report->getName(), '%link%' => $link]
);
}
/**
* @return string
*/
public function getSubject(Report $report)
{
$date = new \DateTime();
return $this->translator->trans(
'mautic.report.schedule.email.subject',
['%report_name%' => $report->getName(), '%date%' => $date->format('Y-m-d')]
);
}
/**
* @deprecated 2.16.0 use \Mautic\ReportBundle\Scheduler\Model\FileHandler::fileCanBeAttached instead. To be removed in 3.0.0.
*
* @param string $filePath
*
* @throws \Mautic\CoreBundle\Exception\FileInvalidException
*/
public function fileCouldBeSend($filePath): bool
{
$filesize = $this->fileProperties->getFileSize($filePath);
$maxFileSize = $this->coreParametersHelper->get('report_export_max_filesize_in_bytes');
return $filesize <= $maxFileSize;
}
}
|