send message from cli through ovh if configured

This commit is contained in:
2022-06-13 21:39:29 +02:00
parent 616be5cc8a
commit 4c0fef4f44
19 changed files with 540 additions and 57 deletions

View File

@@ -0,0 +1,68 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
use DateInterval;
use Monolog\DateTimeImmutable;
use UnexpectedValueException;
/**
* * Lundi => Envoi des rdv du mardi et mercredi.
* * Mardi => Envoi des rdv du jeudi.
* * Mercredi => Envoi des rdv du vendredi
* * Jeudi => envoi des rdv du samedi et dimanche
* * Vendredi => Envoi des rdv du lundi.
*/
class DefaultRangeGenerator implements RangeGeneratorInterface
{
public function generateRange(\DateTimeImmutable $date): array
{
$onMidnight = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d') . ' 00:00:00');
switch ($dow = (int) $onMidnight->format('w')) {
case 6: // Saturday
case 0: // Sunday
return ['startDate' => null, 'endDate' => null];
case 1: // Monday
// send for Tuesday and Wednesday
$startDate = $onMidnight->add(new DateInterval('P1D'));
$endDate = $startDate->add(new DateInterval('P2D'));
break;
case 2: // tuesday
case 3: // wednesday
$startDate = $onMidnight->add(new DateInterval('P2D'));
$endDate = $startDate->add(new DateInterval('P1D'));
break;
case 4: // thursday
$startDate = $onMidnight->add(new DateInterval('P2D'));
$endDate = $startDate->add(new DateInterval('P2D'));
break;
case 5: // friday
$startDate = $onMidnight->add(new DateInterval('P3D'));
$endDate = $startDate->add(new DateInterval('P1D'));
break;
default:
throw new UnexpectedValueException('a day of a week should not have the value: ' . $dow);
}
return ['startDate' => $startDate, 'endDate' => $endDate];
}
}

View File

@@ -1,10 +1,17 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
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;
@@ -36,8 +43,8 @@ class DefaultShortMessageForCalendarBuilder implements ShortMessageForCalendarBu
}
$toUsers[] = new \Chill\MainBundle\Service\ShortMessage\ShortMessage(
$this->engine->render('@ChillCalendar/CalendarShortMessage/short_message.txt.twig', ['calendar' => $calendar]),
$person->getMobilenumber()
$this->engine->render('@ChillCalendar/CalendarShortMessage/short_message.txt.twig', ['calendar' => $calendar]),
$person->getMobilenumber()
);
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
use Chill\CalendarBundle\Repository\CalendarRepository;
use Symfony\Component\Messenger\MessageBusInterface;
class Generator
{
private CalendarRepository $calendarRepository;
private MessageBusInterface $messageBus;
private RangeGeneratorInterface $rangeGenerator;
public function generateShortMessages(): void
{
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
use DateTimeImmutable;
interface RangeGeneratorInterface
{
/**
* @return array<startDate: \DateTimeImmutable, endDate: \DateTimeImmutable>
*/
public function generateRange(DateTimeImmutable $date): array;
}

View File

@@ -1,14 +1,22 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Service\ShortMessageNotification;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\MainBundle\Service\Mailer\ShortMessage;
use Chill\MainBundle\Service\ShortMessage\ShortMessage;
interface ShortMessageForCalendarBuilderInterface
{
/**
* @param Calendar $calendar
* @return array|ShortMessage[]
*/
public function buildMessageForCalendar(Calendar $calendar): array;