Merge branch 'ticket/option-one-multi-person-entity-per-ticket' into 'ticket-app-master'

Add phone number parsing functionality

See merge request Chill-Projet/chill-bundles!848
This commit is contained in:
Julien Fastré 2025-07-04 13:36:55 +00:00
commit f26d9739c8
12 changed files with 232 additions and 6 deletions

View File

@ -0,0 +1,4 @@
chill_ticket:
ticket:
person_per_ticket: one # One of "one"; "many"

View File

@ -12,9 +12,11 @@ declare(strict_types=1);
namespace Chill\TicketBundle\Action\Ticket; namespace Chill\TicketBundle\Action\Ticket;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\TicketBundle\Validation\Validator\SetPersonCommandConstraint;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\GreaterThan; use Symfony\Component\Validator\Constraints\GreaterThan;
#[SetPersonCommandConstraint]
class SetPersonsCommand class SetPersonsCommand
{ {
public function __construct( public function __construct(

View File

@ -12,15 +12,21 @@ declare(strict_types=1);
namespace Chill\TicketBundle\Controller; namespace Chill\TicketBundle\Controller;
use Chill\TicketBundle\Entity\Ticket; use Chill\TicketBundle\Entity\Ticket;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Twig\Environment; use Twig\Environment;
class EditTicketController class EditTicketController
{ {
private string $personPerTicket;
public function __construct( public function __construct(
private readonly Environment $templating, private readonly Environment $templating,
) {} ParameterBagInterface $parameterBag,
) {
$this->personPerTicket = $parameterBag->get('chill_ticket')['ticket']['person_per_ticket'];
}
#[Route('/{_locale}/ticket/ticket/{id}/edit', name: 'chill_ticket_ticket_edit')] #[Route('/{_locale}/ticket/ticket/{id}/edit', name: 'chill_ticket_ticket_edit')]
public function __invoke( public function __invoke(
@ -31,6 +37,7 @@ class EditTicketController
'@ChillTicket/Ticket/edit.html.twig', '@ChillTicket/Ticket/edit.html.twig',
[ [
'ticket' => $ticket, 'ticket' => $ticket,
'personPerTicket' => $this->personPerTicket,
] ]
) )
); );

View File

@ -24,6 +24,11 @@ class ChillTicketExtension extends Extension implements PrependExtensionInterfac
{ {
public function load(array $configs, ContainerBuilder $container) public function load(array $configs, ContainerBuilder $container)
{ {
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('chill_ticket', $config);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yaml'); $loader->load('services.yaml');
} }

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\TicketBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('chill_ticket');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
/** @var ArrayNodeDefinition $ticketArray */
$ticketArray = $rootNode
->children()
->arrayNode('ticket')
->addDefaultsIfNotSet()
;
$ticketArray
->children()
->enumNode('person_per_ticket')
->values(['one', 'many'])
->defaultValue('many')
->end();
return $treeBuilder;
}
}

View File

@ -111,7 +111,6 @@ export type EmergencyStateEvent = TicketHistory<
>; >;
export type CallerStateEvent = TicketHistory<"set_caller", CallerState>; export type CallerStateEvent = TicketHistory<"set_caller", CallerState>;
// TODO : Remove add_person event from TicketHistoryLine
export type TicketHistoryLine = export type TicketHistoryLine =
| AddPersonEvent | AddPersonEvent
| CreateTicketEvent | CreateTicketEvent
@ -125,11 +124,7 @@ export type TicketHistoryLine =
interface BaseTicket<T extends "ticket_ticket:simple"|"ticket_ticket:extended" = "ticket_ticket:simple"> { interface BaseTicket<T extends "ticket_ticket:simple"|"ticket_ticket:extended" = "ticket_ticket:simple"> {
type_extended: T; type_extended: T;
}
export interface TicketSimple extends BaseTicket<"ticket_ticket:simple"> {
type: "ticket_ticket"; type: "ticket_ticket";
type_extended: "ticket_ticket:simple";
id: number; id: number;
externalRef: string; externalRef: string;
currentAddressees: UserGroupOrUser[]; currentAddressees: UserGroupOrUser[];
@ -140,6 +135,10 @@ export interface TicketSimple extends BaseTicket<"ticket_ticket:simple"> {
caller: Person | Thirdparty | null; caller: Person | Thirdparty | null;
} }
export interface TicketSimple extends BaseTicket<"ticket_ticket:simple"> {
type_extended: "ticket_ticket:simple";
}
export interface Ticket extends BaseTicket<"ticket_ticket:extended"> { export interface Ticket extends BaseTicket<"ticket_ticket:extended"> {
type_extended: "ticket_ticket:extended"; type_extended: "ticket_ticket:extended";
createdAt: DateTime | null; createdAt: DateTime | null;

View File

@ -9,6 +9,7 @@ import { store } from "./store";
declare global { declare global {
interface Window { interface Window {
initialTicket: string; initialTicket: string;
ticketPersonPerTicket: 'one'|'multi';
} }
} }

View File

@ -9,6 +9,7 @@
{{ parent() }} {{ parent() }}
<script type="text/javascript"> <script type="text/javascript">
window.initialTicket = "{{ ticket|serialize('json', {'groups': 'read'})|escape('js') }}"; window.initialTicket = "{{ ticket|serialize('json', {'groups': 'read'})|escape('js') }}";
window.ticketPersonPerTicket = "{{ personPerTicket|escape('js') }}";
</script> </script>
{{ encore_entry_script_tags('vue_ticket_app') }} {{ encore_entry_script_tags('vue_ticket_app') }}
{% endblock %} {% endblock %}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\TicketBundle\Validation\Validator;
use Symfony\Component\Validator\Constraint;
#[\Attribute]
class SetPersonCommandConstraint extends Constraint
{
public string $notMulti = 'ticket.set_persons.Only one person can be set.';
public function getTargets(): string
{
return Constraint::CLASS_CONSTRAINT;
}
}

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\TicketBundle\Validation\Validator;
use Chill\TicketBundle\Action\Ticket\SetPersonsCommand;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
class SetPersonCommandConstraintValidator extends ConstraintValidator
{
private bool $isMulti;
public function __construct(ParameterBagInterface $parameterBag)
{
$this->isMulti = 'multi' === $parameterBag->get('chill_ticket')['ticket']['person_per_ticket'];
}
public function validate($value, Constraint $constraint)
{
if (!$value instanceof SetPersonsCommand) {
throw new UnexpectedValueException($value, SetPersonsCommand::class);
}
if (!$constraint instanceof SetPersonCommandConstraint) {
throw new UnexpectedValueException($constraint, SetPersonCommandConstraint::class);
}
if (!$this->isMulti) {
if (1 < count($value->persons)) {
$this->context->buildViolation($constraint->notMulti)
->atPath('persons')
->addViolation();
}
}
}
}

View File

@ -23,5 +23,8 @@ services:
Chill\TicketBundle\Menu\: Chill\TicketBundle\Menu\:
resource: '../Menu/' resource: '../Menu/'
Chill\TicketBundle\Validation\:
resource: '../Validation/'
Chill\TicketBundle\DataFixtures\: Chill\TicketBundle\DataFixtures\:
resource: '../DataFixtures/' resource: '../DataFixtures/'

View File

@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Validation\Validator;
use Chill\PersonBundle\Entity\Person;
use Chill\TicketBundle\Action\Ticket\SetPersonsCommand;
use Chill\TicketBundle\Validation\Validator\SetPersonCommandConstraint;
use Chill\TicketBundle\Validation\Validator\SetPersonCommandConstraintValidator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @internal
*
* @coversNothing
*/
class SetPersonCommandConstraintValidatorTest extends ConstraintValidatorTestCase
{
private string $personPerTicket = 'many';
protected function createValidator()
{
return new SetPersonCommandConstraintValidator(
new ParameterBag(['chill_ticket' => ['ticket' => ['person_per_ticket' => $this->personPerTicket]]])
);
}
/**
* Helper method to set the configuration and recreate the validator.
*/
private function setPersonPerTicket(string $personPerTicket): void
{
$this->personPerTicket = $personPerTicket;
$this->validator = $this->createValidator();
$this->validator->initialize($this->context);
}
public function testValidatorWithManyPersonsPerTicket(): void
{
$this->setPersonPerTicket('multi');
$command = new SetPersonsCommand([new Person(), new Person()]);
$this->validator->validate($command, new SetPersonCommandConstraint());
$this->assertNoViolation();
}
public function testValidatorWithSinglePersonPerTicket(): void
{
$this->setPersonPerTicket('single');
$command = new SetPersonsCommand([new Person(), new Person()]);
$this->validator->validate($command, $command = new SetPersonCommandConstraint());
$this->buildViolation($command->notMulti)->atPath('property.path.persons')->assertRaised();
}
public function testValidatorWithSinglePersonPerTicketAndEmptyPersons(): void
{
$this->setPersonPerTicket('single');
$command = new SetPersonsCommand([]);
$this->validator->validate($command, new SetPersonCommandConstraint());
$this->assertNoViolation();
}
public function testValidatorWithSinglePersonPerTicketAndOnlyOnePerson(): void
{
$this->setPersonPerTicket('single');
$command = new SetPersonsCommand([new Person()]);
$this->validator->validate($command, new SetPersonCommandConstraint());
$this->assertNoViolation();
}
}