bootstrap fake sms from cli

This commit is contained in:
2022-06-13 14:01:07 +02:00
parent 9e4fd6183e
commit 616be5cc8a
15 changed files with 417 additions and 2 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
use Chill\BudgetBundle\Templating\Twig;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\MainBundle\Service\Mailer\ShortMessage;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Templating\EngineInterface;
class DefaultShortMessageForCalendarBuilder implements ShortMessageForCalendarBuilderInterface
{
private ?array $config = null;
private EngineInterface $engine;
public function __construct(
ParameterBagInterface $parameterBag,
EngineInterface $engine
) {
$this->config = $parameterBag->get('chill_calendar.short_messages');
$this->engine = $engine;
}
public function buildMessageForCalendar(Calendar $calendar): array
{
if (null === $this->config || true !== $calendar->getSendSMS()) {
return [];
}
$toUsers = [];
foreach ($calendar->getPersons() as $person) {
if (false === $person->getAcceptSMS() || null === $person->getAcceptSMS() || null === $person->getMobilenumber()) {
continue;
}
$toUsers[] = new \Chill\MainBundle\Service\ShortMessage\ShortMessage(
$this->engine->render('@ChillCalendar/CalendarShortMessage/short_message.txt.twig', ['calendar' => $calendar]),
$person->getMobilenumber()
);
}
return $toUsers;
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\MainBundle\Service\Mailer\ShortMessage;
interface ShortMessageForCalendarBuilderInterface
{
/**
* @param Calendar $calendar
* @return array|ShortMessage[]
*/
public function buildMessageForCalendar(Calendar $calendar): array;
}