add mailto to reports
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
// src/Twig/AppExtension.php
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Entity\Clients;
|
||||
use App\Entity\Reports;
|
||||
use App\Helper\MonthHelper;
|
||||
use App\Services\AddReports;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
@@ -20,6 +24,7 @@ class AppExtension extends AbstractExtension
|
||||
return [
|
||||
new TwigFunction('enum', [$this, 'enumChecker']),
|
||||
new TwigFunction('is_route_active', [$this, 'getActualRoute']),
|
||||
new TwigFunction('getMailtoLink', [$this, 'getMailtoLink']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -41,4 +46,28 @@ class AppExtension extends AbstractExtension
|
||||
{
|
||||
return $value === $route ? 'active' : '';
|
||||
}
|
||||
|
||||
public function getMailtoLink(Reports $reports): string
|
||||
{
|
||||
$subject = rawurlencode("Sprawozdanie z wykonania układu");
|
||||
$dateBase = (clone $reports->getDateStart())->modify("-1 month");
|
||||
|
||||
$template = "email/report.html.twig";
|
||||
$dateStart = (clone $dateBase)->modify("-".(AddReports::NEXT_REPORT_MONTH-1)." months")->modify("first day of this month");
|
||||
if ($reports->getNumber() === 1){
|
||||
$template = "email/firstReport.html.twig";
|
||||
$dateStart = $reports->getClient()->getDateLegitimacy();
|
||||
}
|
||||
$view = sprintf(
|
||||
file_get_contents($_SERVER['PWD']."/templates/".$template),
|
||||
MonthHelper::takeDateFormatWithPolishMonths($dateStart),
|
||||
MonthHelper::takeDateFormatWithPolishMonths($dateBase->modify("last day of this month"))
|
||||
);
|
||||
$content = rawurlencode($view);
|
||||
|
||||
/** @var Clients $client */
|
||||
$client = $reports->getClient();
|
||||
|
||||
return "mailto:{$client->getStrEmail()}?subject=$subject&body=$content";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user