mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Merge remote-tracking branch 'origin/calendar/synchro-msgraph' into calendar/finalization
This commit is contained in:
@@ -18,6 +18,7 @@ use Chill\MainBundle\DependencyInjection\CompilerPass\GroupingCenterCompilerPass
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\MenuCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\NotificationCounterCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\SearchableServicesCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\ShortMessageCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\TimelineCompilerClass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\WidgetsCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass;
|
||||
@@ -70,5 +71,6 @@ class ChillMainBundle extends Bundle
|
||||
$container->addCompilerPass(new ACLFlagsCompilerPass());
|
||||
$container->addCompilerPass(new GroupingCenterCompilerPass());
|
||||
$container->addCompilerPass(new CRUDControllerCompilerPass());
|
||||
$container->addCompilerPass(new ShortMessageCompilerPass());
|
||||
}
|
||||
}
|
||||
|
@@ -196,8 +196,11 @@ class ChillMainExtension extends Extension implements
|
||||
$loader->load('services/search.yaml');
|
||||
$loader->load('services/serializer.yaml');
|
||||
$loader->load('services/mailer.yaml');
|
||||
$loader->load('services/short_message.yaml');
|
||||
|
||||
$this->configureCruds($container, $config['cruds'], $config['apis'], $loader);
|
||||
$container->setParameter('chill_main.short_messages', $config['short_messages']);
|
||||
//$this->configureSms($config['short_messages'], $container, $loader);
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
@@ -313,6 +316,13 @@ class ChillMainExtension extends Extension implements
|
||||
// Note: the controller are loaded inside compiler pass
|
||||
}
|
||||
|
||||
protected function configureSms(array $config, ContainerBuilder $container, Loader\YamlFileLoader $loader): void
|
||||
{
|
||||
$dsn = parse_url($config['dsn']);
|
||||
|
||||
dump($dsn);
|
||||
}
|
||||
|
||||
protected function prependCruds(ContainerBuilder $container)
|
||||
{
|
||||
$container->prependExtensionConfig('chill_main', [
|
||||
|
@@ -0,0 +1,87 @@
|
||||
<?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\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Chill\MainBundle\Service\ShortMessage\NullShortMessageSender;
|
||||
use Chill\MainBundle\Service\ShortMessage\ShortMessageTransporter;
|
||||
use Chill\MainBundle\Service\ShortMessageOvh\OvhShortMessageSender;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use function array_key_exists;
|
||||
|
||||
class ShortMessageCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$config = $container->resolveEnvPlaceholders($container->getParameter('chill_main.short_messages', null), true);
|
||||
// weird fix for special characters
|
||||
$config['dsn'] = str_replace(['%%'], ['%'], $config['dsn']);
|
||||
$dsn = parse_url($config['dsn']);
|
||||
parse_str($dsn['query'] ?? '', $dsn['queries']);
|
||||
|
||||
if ('null' === $dsn['scheme'] || false === $config['enabled']) {
|
||||
$defaultTransporter = new Reference(NullShortMessageSender::class);
|
||||
} elseif ('ovh' === $dsn['scheme']) {
|
||||
if (!class_exists('\Ovh\Api')) {
|
||||
throw new RuntimeException('Class \\Ovh\\Api not found');
|
||||
}
|
||||
|
||||
foreach (['user', 'host', 'pass'] as $component) {
|
||||
if (!array_key_exists($component, $dsn)) {
|
||||
throw new RuntimeException(sprintf('The component %s does not exist in dsn. Please provide a dsn ' .
|
||||
'like ovh://applicationKey:applicationSecret@endpoint?consumerKey=xxxx&sender=yyyy&service_name=zzzz', $component));
|
||||
}
|
||||
|
||||
$container->setParameter('chill_main.short_messages.ovh_config_' . $component, $dsn[$component]);
|
||||
}
|
||||
|
||||
foreach (['consumer_key', 'sender', 'service_name'] as $param) {
|
||||
if (!array_key_exists($param, $dsn['queries'])) {
|
||||
throw new RuntimeException(sprintf('The parameter %s does not exist in dsn. Please provide a dsn ' .
|
||||
'like ovh://applicationKey:applicationSecret@endpoint?consumerKey=xxxx&sender=yyyy&service_name=zzzz', $param));
|
||||
}
|
||||
$container->setParameter('chill_main.short_messages.ovh_config_' . $param, $dsn['queries'][$param]);
|
||||
}
|
||||
|
||||
$ovh = new Definition();
|
||||
$ovh
|
||||
->setClass('\Ovh\Api')
|
||||
->setArgument(0, $dsn['user'])
|
||||
->setArgument(1, $dsn['pass'])
|
||||
->setArgument(2, $dsn['host'])
|
||||
->setArgument(3, $dsn['queries']['consumer_key']);
|
||||
$container->setDefinition('Ovh\Api', $ovh);
|
||||
|
||||
$ovhSender = new Definition();
|
||||
$ovhSender
|
||||
->setClass(OvhShortMessageSender::class)
|
||||
->setArgument(0, new Reference('Ovh\Api'))
|
||||
->setArgument(1, $dsn['queries']['service_name'])
|
||||
->setArgument(2, $dsn['queries']['sender'])
|
||||
->setArgument(3, new Reference(LoggerInterface::class))
|
||||
->setArgument(4, new Reference(PhoneNumberUtil::class));
|
||||
$container->setDefinition(OvhShortMessageSender::class, $ovhSender);
|
||||
|
||||
$defaultTransporter = new Reference(OvhShortMessageSender::class);
|
||||
} else {
|
||||
throw new RuntimeException(sprintf('Cannot find a sender for this dsn: %s', $config['dsn']));
|
||||
}
|
||||
|
||||
$container->getDefinition(ShortMessageTransporter::class)
|
||||
->setArgument(0, $defaultTransporter);
|
||||
}
|
||||
}
|
@@ -102,6 +102,14 @@ class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('short_messages')
|
||||
->canBeEnabled()
|
||||
->children()
|
||||
->scalarNode('dsn')->cannotBeEmpty()->defaultValue('null://null')
|
||||
->info('the dsn for sending short message. Example: ovh://applicationKey:secret@endpoint')
|
||||
->end()
|
||||
->end()
|
||||
->end() // end for 'short_messages'
|
||||
->arrayNode('acl')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
|
@@ -359,10 +359,17 @@ class User implements AdvancedUserInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function setAttributeByDomain(string $domain, string $key, $value): self
|
||||
{
|
||||
$this->attributes[$domain][$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the attributes with existing attributes.
|
||||
*
|
||||
* Only the key provided will be created or updated.
|
||||
* Only the key provided will be created or updated. For a two-level array, use @see{User::setAttributeByDomain}
|
||||
*/
|
||||
public function setAttributes(array $attributes): self
|
||||
{
|
||||
|
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Form\Type\Listing;
|
||||
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
@@ -70,10 +71,38 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$builder->add($checkboxesBuilder);
|
||||
}
|
||||
|
||||
if (0 < count($helper->getDateRanges())) {
|
||||
$dateRangesBuilder = $builder->create('dateRanges', null, ['compound' => true]);
|
||||
|
||||
foreach ($helper->getDateRanges() as $name => $opts) {
|
||||
$rangeBuilder = $dateRangesBuilder->create($name, null, [
|
||||
'compound' => true,
|
||||
'label' => $opts['label'] ?? $name,
|
||||
]);
|
||||
|
||||
$rangeBuilder->add(
|
||||
'from',
|
||||
ChillDateType::class,
|
||||
['input' => 'datetime_immutable', 'required' => false]
|
||||
);
|
||||
$rangeBuilder->add(
|
||||
'to',
|
||||
ChillDateType::class,
|
||||
['input' => 'datetime_immutable', 'required' => false]
|
||||
);
|
||||
|
||||
$dateRangesBuilder->add($rangeBuilder);
|
||||
}
|
||||
|
||||
$builder->add($dateRangesBuilder);
|
||||
}
|
||||
|
||||
foreach ($this->requestStack->getCurrentRequest()->query->getIterator() as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'q':
|
||||
case 'checkboxes' . $key:
|
||||
case $key . '_from':
|
||||
case $key . '_to':
|
||||
break;
|
||||
|
||||
case 'page':
|
||||
|
@@ -15,14 +15,14 @@ use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
use function count;
|
||||
|
||||
final class UserRepository implements ObjectRepository
|
||||
final class UserRepository implements UserRepositoryInterface
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
@@ -144,11 +144,15 @@ final class UserRepository implements ObjectRepository
|
||||
return $this->repository->findOneBy($criteria, $orderBy);
|
||||
}
|
||||
|
||||
public function findOneByUsernameOrEmail(string $pattern)
|
||||
public function findOneByUsernameOrEmail(string $pattern): ?User
|
||||
{
|
||||
$qb = $this->queryByUsernameOrEmail($pattern);
|
||||
$qb = $this->queryByUsernameOrEmail($pattern)->select('u');
|
||||
|
||||
return $qb->getQuery()->getSingleResult();
|
||||
try {
|
||||
return $qb->getQuery()->getSingleResult();
|
||||
} catch (NoResultException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +210,7 @@ final class UserRepository implements ObjectRepository
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
public function getClassName(): string
|
||||
{
|
||||
return User::class;
|
||||
}
|
||||
|
@@ -0,0 +1,73 @@
|
||||
<?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\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
interface UserRepositoryInterface extends ObjectRepository
|
||||
{
|
||||
public function countBy(array $criteria): int;
|
||||
|
||||
public function countByActive(): int;
|
||||
|
||||
public function countByNotHavingAttribute(string $key): int;
|
||||
|
||||
public function countByUsernameOrEmail(string $pattern): int;
|
||||
|
||||
public function find($id, $lockMode = null, $lockVersion = null): ?User;
|
||||
|
||||
/**
|
||||
* @return User[]
|
||||
*/
|
||||
public function findAll(): array;
|
||||
|
||||
/**
|
||||
* @param mixed|null $limit
|
||||
* @param mixed|null $offset
|
||||
*
|
||||
* @return User[]
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;
|
||||
|
||||
/**
|
||||
* @return array|User[]
|
||||
*/
|
||||
public function findByActive(?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
|
||||
|
||||
/**
|
||||
* Find users which does not have a key on attribute column.
|
||||
*
|
||||
* @return array|User[]
|
||||
*/
|
||||
public function findByNotHavingAttribute(string $key, ?int $limit = null, ?int $offset = null): array;
|
||||
|
||||
public function findByUsernameOrEmail(string $pattern, ?array $orderBy = [], ?int $limit = null, ?int $offset = null): array;
|
||||
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?User;
|
||||
|
||||
public function findOneByUsernameOrEmail(string $pattern): ?User;
|
||||
|
||||
/**
|
||||
* Get the users having a specific flags.
|
||||
*
|
||||
* If provided, only the users amongst "filtered users" are searched. This
|
||||
* allows to make a first search amongst users based on role and center
|
||||
* and, then filter those users having some flags.
|
||||
*
|
||||
* @param \Chill\MainBundle\Entity\User[] $amongstUsers
|
||||
* @param mixed $flag
|
||||
*/
|
||||
public function findUsersHavingFlags($flag, array $amongstUsers = []): array;
|
||||
|
||||
public function getClassName(): string;
|
||||
}
|
@@ -1,6 +1,3 @@
|
||||
// import bootstrap variables
|
||||
@import 'bootstrap/scss/variables';
|
||||
|
||||
// Variables
|
||||
//
|
||||
// Variables should follow the `$component-state-property-size` formula for
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<ul :class="listClasses" v-if="picked.length">
|
||||
<ul :class="listClasses" v-if="picked.length && displayPicked">
|
||||
<li v-for="p in picked" @click="removeEntity(p)" :key="p.type+p.id">
|
||||
<span class="chill_denomination">{{ p.text }}</span>
|
||||
</li>
|
||||
@@ -44,6 +44,11 @@ export default {
|
||||
removableIfSet: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
displayPicked: {
|
||||
// display picked entities.
|
||||
type: Boolean,
|
||||
default: true,
|
||||
}
|
||||
},
|
||||
emits: ['addNewEntity', 'removeEntity'],
|
||||
|
@@ -17,6 +17,11 @@ export default {
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: false
|
||||
},
|
||||
hoursOnly: {
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
hour12: false,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -10,6 +10,28 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if form.dateRanges is defined %}
|
||||
{% if form.dateRanges|length > 0 %}
|
||||
{% for dateRangeName, _o in form.dateRanges %}
|
||||
<div class="row gx-2">
|
||||
<div class="col-md-5">
|
||||
{{ form_label(form.dateRanges[dateRangeName])}}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">{{ 'chill_calendar.From'|trans }}</span>
|
||||
{{ form_widget(form.dateRanges[dateRangeName]['from']) }}
|
||||
<span class="input-group-text">{{ 'chill_calendar.To'|trans }}</span>
|
||||
{{ form_widget(form.dateRanges[dateRangeName]['to']) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<button type="submit" class="btn btn-misc"><i class="fa fa-filter"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if form.checkboxes is defined %}
|
||||
{% if form.checkboxes|length > 0 %}
|
||||
{% for checkbox_name, options in form.checkboxes %}
|
||||
|
@@ -0,0 +1,19 @@
|
||||
<?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\MainBundle\Service\ShortMessage;
|
||||
|
||||
class NullShortMessageSender implements ShortMessageSenderInterface
|
||||
{
|
||||
public function send(ShortMessage $shortMessage): void
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?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\MainBundle\Service\ShortMessage;
|
||||
|
||||
use libphonenumber\PhoneNumber;
|
||||
|
||||
class ShortMessage
|
||||
{
|
||||
public const PRIORITY_LOW = 'low';
|
||||
|
||||
public const PRIORITY_MEDIUM = 'medium';
|
||||
|
||||
private string $content;
|
||||
|
||||
private PhoneNumber $phoneNumber;
|
||||
|
||||
private string $priority = 'low';
|
||||
|
||||
public function __construct(string $content, PhoneNumber $phoneNumber, string $priority = 'low')
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->phoneNumber = $phoneNumber;
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function getPhoneNumber(): PhoneNumber
|
||||
{
|
||||
return $this->phoneNumber;
|
||||
}
|
||||
|
||||
public function getPriority(): string
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
public function setContent(string $content): self
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPhoneNumber(PhoneNumber $phoneNumber): self
|
||||
{
|
||||
$this->phoneNumber = $phoneNumber;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPriority(string $priority): self
|
||||
{
|
||||
$this->priority = $priority;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?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\MainBundle\Service\ShortMessage;
|
||||
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
/**
|
||||
* @AsMessageHandler
|
||||
*/
|
||||
class ShortMessageHandler implements MessageHandlerInterface
|
||||
{
|
||||
private ShortMessageTransporterInterface $messageTransporter;
|
||||
|
||||
public function __construct(ShortMessageTransporterInterface $messageTransporter)
|
||||
{
|
||||
$this->messageTransporter = $messageTransporter;
|
||||
}
|
||||
|
||||
public function __invoke(ShortMessage $message): void
|
||||
{
|
||||
$this->messageTransporter->send($message);
|
||||
}
|
||||
}
|
@@ -0,0 +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\MainBundle\Service\ShortMessage;
|
||||
|
||||
interface ShortMessageSenderInterface
|
||||
{
|
||||
public function send(ShortMessage $shortMessage): void;
|
||||
}
|
@@ -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\MainBundle\Service\ShortMessage;
|
||||
|
||||
class ShortMessageTransporter implements ShortMessageTransporterInterface
|
||||
{
|
||||
private ShortMessageSenderInterface $sender;
|
||||
|
||||
public function __construct(
|
||||
ShortMessageSenderInterface $sender // hint: must remain at place 0 for DI
|
||||
) {
|
||||
$this->sender = $sender;
|
||||
}
|
||||
|
||||
public function send(ShortMessage $shortMessage): void
|
||||
{
|
||||
$this->sender->send($shortMessage);
|
||||
}
|
||||
}
|
@@ -0,0 +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\MainBundle\Service\ShortMessage;
|
||||
|
||||
interface ShortMessageTransporterInterface
|
||||
{
|
||||
public function send(ShortMessage $shortMessage);
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
<?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\MainBundle\Service\ShortMessageOvh;
|
||||
|
||||
use Chill\MainBundle\Service\ShortMessage\ShortMessage;
|
||||
use Chill\MainBundle\Service\ShortMessage\ShortMessageSenderInterface;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Ovh\Api;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class OvhShortMessageSender implements ShortMessageSenderInterface
|
||||
{
|
||||
private Api $api;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private PhoneNumberUtil $phoneNumberUtil;
|
||||
|
||||
private string $sender;
|
||||
|
||||
private string $serviceName;
|
||||
|
||||
public function __construct(
|
||||
Api $api, // for DI, must remains as first argument
|
||||
string $serviceName, // for di, must remains as second argument
|
||||
string $sender, // for DI, must remains as third argument
|
||||
LoggerInterface $logger,
|
||||
PhoneNumberUtil $phoneNumberUtil
|
||||
) {
|
||||
$this->api = $api;
|
||||
$this->serviceName = $serviceName;
|
||||
$this->sender = $sender;
|
||||
$this->logger = $logger;
|
||||
$this->phoneNumberUtil = $phoneNumberUtil;
|
||||
}
|
||||
|
||||
public function send(ShortMessage $shortMessage): void
|
||||
{
|
||||
$receiver = $this->phoneNumberUtil->format($shortMessage->getPhoneNumber(), PhoneNumberFormat::E164);
|
||||
|
||||
$response = $this->api->post(
|
||||
strtr('/sms/{serviceName}/jobs', ['{serviceName}' => $this->serviceName]),
|
||||
[
|
||||
'message' => $shortMessage->getContent(),
|
||||
'receivers' => [$receiver],
|
||||
'sender' => $this->sender,
|
||||
'noStopClause' => true,
|
||||
'coding' => '7bit',
|
||||
'charset' => 'UTF-8',
|
||||
'priority' => $shortMessage->getPriority(),
|
||||
]
|
||||
);
|
||||
|
||||
$improved = array_merge([
|
||||
'validReceiversI' => implode(',', $response['validReceivers']),
|
||||
'idsI' => implode(',', $response['ids']),
|
||||
], $response);
|
||||
|
||||
$this->logger->warning('[sms] a sms was sent', $improved);
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
use Chill\MainBundle\Form\Type\Listing\FilterOrderType;
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
@@ -23,6 +24,8 @@ class FilterOrderHelper
|
||||
{
|
||||
private array $checkboxes = [];
|
||||
|
||||
private array $dateRanges = [];
|
||||
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private ?string $formName = 'f';
|
||||
@@ -60,6 +63,13 @@ class FilterOrderHelper
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addDateRange(string $name, string $label, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null): self
|
||||
{
|
||||
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function buildForm(): FormInterface
|
||||
{
|
||||
return $this->formFactory
|
||||
@@ -81,6 +91,19 @@ class FilterOrderHelper
|
||||
return $this->checkboxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<'to': DateTimeImmutable, 'from': DateTimeImmutable>
|
||||
*/
|
||||
public function getDateRangeData(string $name): array
|
||||
{
|
||||
return $this->getFormData()['dateRanges'][$name];
|
||||
}
|
||||
|
||||
public function getDateRanges(): array
|
||||
{
|
||||
return $this->dateRanges;
|
||||
}
|
||||
|
||||
public function getQueryString(): ?string
|
||||
{
|
||||
return $this->getFormData()['q'];
|
||||
@@ -110,6 +133,11 @@ class FilterOrderHelper
|
||||
$r['checkboxes'][$name] = $c['default'];
|
||||
}
|
||||
|
||||
foreach ($this->dateRanges as $name => $defaults) {
|
||||
$r['dateRanges'][$name]['from'] = $defaults['from'];
|
||||
$r['dateRanges'][$name]['to'] = $defaults['to'];
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
@@ -18,6 +19,8 @@ class FilterOrderHelperBuilder
|
||||
{
|
||||
private array $checkboxes = [];
|
||||
|
||||
private array $dateRanges = [];
|
||||
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
@@ -39,6 +42,13 @@ class FilterOrderHelperBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addDateRange(string $name, string $label, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null): self
|
||||
{
|
||||
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSearchBox(?array $fields = [], ?array $options = []): self
|
||||
{
|
||||
$this->searchBoxFields = $fields;
|
||||
@@ -65,6 +75,16 @@ class FilterOrderHelperBuilder
|
||||
$helper->addCheckbox($name, $choices, $default, $trans);
|
||||
}
|
||||
|
||||
foreach (
|
||||
$this->dateRanges as $name => [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'label' => $label,
|
||||
]
|
||||
) {
|
||||
$helper->addDateRange($name, $label, $from, $to);
|
||||
}
|
||||
|
||||
return $helper;
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ services:
|
||||
tags:
|
||||
- { name: 'doctrine.event_subscriber' }
|
||||
|
||||
|
||||
# workflow related
|
||||
Chill\MainBundle\Workflow\:
|
||||
resource: '../Workflow/'
|
||||
|
@@ -0,0 +1,5 @@
|
||||
services:
|
||||
Chill\MainBundle\Service\ShortMessage\:
|
||||
resource: '../Service/ShortMessage'
|
||||
autowire: true
|
||||
autoconfigure: true
|
Reference in New Issue
Block a user