Skip to content

Commit 9fdf2b3

Browse files
authored
Merge branch 'EsupPortail:main' into dev
2 parents f7ac823 + 27bb963 commit 9fdf2b3

6 files changed

Lines changed: 187 additions & 39 deletions

File tree

backend/src/ApiResource/Demande.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
namespace App\ApiResource;
1414

15-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
1615
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
16+
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
1717
use ApiPlatform\Doctrine\Orm\State\Options;
1818
use ApiPlatform\Metadata\ApiFilter;
1919
use ApiPlatform\Metadata\ApiProperty;
@@ -23,6 +23,7 @@
2323
use ApiPlatform\Metadata\Patch;
2424
use ApiPlatform\Metadata\Post;
2525
use ApiPlatform\OpenApi\Model\Operation;
26+
use App\Filter\CampagneNonArchiveeFilter;
2627
use App\Filter\DemandeDisciplineSportiveFilter;
2728
use App\Filter\DemandeFormatFilter;
2829
use App\Filter\DerniereInscriptionSearchFilter;
@@ -39,43 +40,43 @@
3940
use Symfony\Component\Validator\Constraints as Assert;
4041

4142
#[ApiResource(
42-
operations : [
43+
operations: [
4344
new Get(
44-
uriTemplate : self::ITEM_URI,
45+
uriTemplate: self::ITEM_URI,
4546
uriVariables: ['id'],
46-
security : "is_granted('" . self::VOIR_DEMANDE . "', object)"
47+
security: "is_granted('" . self::VOIR_DEMANDE . "', object)"
4748
),
4849
new GetCollection(
4950
uriTemplate: self::COLLECTION_URI,
50-
forceEager : false
51+
forceEager: false
5152
),
5253
new GetCollection(
53-
uriTemplate : self::COLLECTION_UTILISATEUR_URI,
54+
uriTemplate: self::COLLECTION_UTILISATEUR_URI,
5455
uriVariables: ['uid'],
55-
security : "is_granted('ROLE_GESTIONNAIRE') or request.get('uid') == user.getUid()",
56-
forceEager : false,
57-
provider : DemandesUtilisateurProvider::class,
56+
security: "is_granted('ROLE_GESTIONNAIRE') or request.get('uid') == user.getUid()",
57+
forceEager: false,
58+
provider: DemandesUtilisateurProvider::class,
5859
),
5960
new Post(
60-
uriTemplate : self::COLLECTION_URI,
61-
denormalizationContext : ['groups' => [self::GROUP_IN]],
61+
uriTemplate: self::COLLECTION_URI,
62+
denormalizationContext: ['groups' => [self::GROUP_IN]],
6263
securityPostDenormalize: "is_granted('ROLE_GESTIONNAIRE') or object.demandeur.uid == user.getUid()",
63-
read : false,
64-
processor : PostDemandeProcessor::class,
64+
read: false,
65+
processor: PostDemandeProcessor::class,
6566
),
6667
new Patch(
67-
uriTemplate : self::ITEM_URI,
68-
uriVariables : ['id'],
69-
denormalizationContext : ['groups' => [self::GROUP_CHANGEMENT_ETAT]],
68+
uriTemplate: self::ITEM_URI,
69+
uriVariables: ['id'],
70+
denormalizationContext: ['groups' => [self::GROUP_CHANGEMENT_ETAT]],
7071
securityPostDenormalize: "is_granted('" . self::MAJ_DEMANDE . "', [previous_object, object])",
71-
processor : PatchDemandeProcessor::class
72+
processor: PatchDemandeProcessor::class
7273
),
7374
],
74-
normalizationContext : ['groups' => [self::GROUP_OUT]],
75+
normalizationContext: ['groups' => [self::GROUP_OUT]],
7576
denormalizationContext: ['groups' => [self::GROUP_IN]],
76-
openapi : new Operation(tags: ['Demandes']),
77-
provider : DemandeProvider::class,
78-
stateOptions : new Options(entityClass: \App\Entity\Demande::class),
77+
openapi: new Operation(tags: ['Demandes']),
78+
provider: DemandeProvider::class,
79+
stateOptions: new Options(entityClass: \App\Entity\Demande::class),
7980
)]
8081
#[ApiFilter(SearchFilter::class, properties: [
8182
'demandeur.nom' => 'ipartial',
@@ -118,6 +119,7 @@
118119
#[ApiFilter(DemandeDisciplineSportiveFilter::class)]
119120
#[ApiFilter(OrderFilter::class, properties: ['demandeur.nom', 'dateDepot'])]
120121
#[ApiFilter(DemandeFormatFilter::class)]
122+
#[ApiFilter(CampagneNonArchiveeFilter::class)]
121123
#[DemandeUniqueParCampagneConstraint]
122124
#[DemandeWorkflowConstraint]
123125
class Demande

backend/src/ApiResource/TauxHoraire.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,73 @@
1313
namespace App\ApiResource;
1414

1515
use ApiPlatform\Doctrine\Orm\State\Options;
16+
use ApiPlatform\Metadata\ApiFilter;
1617
use ApiPlatform\Metadata\ApiProperty;
1718
use ApiPlatform\Metadata\ApiResource;
1819
use ApiPlatform\Metadata\Delete;
1920
use ApiPlatform\Metadata\Get;
21+
use ApiPlatform\Metadata\GetCollection;
22+
use ApiPlatform\Metadata\Link;
2023
use ApiPlatform\Metadata\Patch;
2124
use ApiPlatform\Metadata\Post;
2225
use ApiPlatform\OpenApi\Model\Operation;
26+
use App\Filter\TauxHoraireDateFilter;
27+
use App\State\TauxHoraire\TauxHoraireCollectionProvider;
2328
use App\State\TauxHoraire\TauxHoraireProcessor;
2429
use App\State\TauxHoraire\TauxHoraireProvider;
2530
use DateTimeInterface;
2631
use Symfony\Component\Serializer\Annotation\Groups;
2732
use Symfony\Component\Validator\Constraints as Assert;
2833

2934
#[ApiResource(
30-
operations : [
35+
operations: [
36+
new GetCollection(
37+
uriTemplate: self::COLLECTION_URI,
38+
uriVariables: [
39+
'typeId' => new Link(fromProperty: 'id', toProperty: 'typeEvenement', fromClass: TypeEvenement::class,),
40+
],
41+
provider: TauxHoraireCollectionProvider::class,
42+
),
3143
new Get(
32-
uriTemplate : self::ITEM_URI,
44+
uriTemplate: self::ITEM_URI,
3345
uriVariables: [
3446
'typeId', 'id',
3547
],
3648
),
3749
new Post(
38-
uriTemplate : self::COLLECTION_URI,
50+
uriTemplate: self::COLLECTION_URI,
3951
uriVariables: [
4052
'typeId',
4153
],
42-
security : "is_granted('ROLE_ADMIN')",
43-
read : false,
54+
security: "is_granted('ROLE_ADMIN')",
55+
read: false,
4456
),
4557
new Patch(
46-
uriTemplate : self::ITEM_URI,
58+
uriTemplate: self::ITEM_URI,
4759
uriVariables: [
4860
'typeId', 'id',
4961
],
50-
security : "is_granted('ROLE_ADMIN')",
62+
security: "is_granted('ROLE_ADMIN')",
5163
),
5264
new Delete(
53-
uriTemplate : self::ITEM_URI,
65+
uriTemplate: self::ITEM_URI,
5466
uriVariables: [
5567
'typeId', 'id',
5668
],
57-
security : "is_granted('ROLE_ADMIN')",
69+
security: "is_granted('ROLE_ADMIN')",
5870
),
5971
],
6072

61-
normalizationContext : ['groups' => [self::GROUP_OUT]],
73+
normalizationContext: ['groups' => [self::GROUP_OUT]],
6274
denormalizationContext: ['groups' => [self::GROUP_IN]],
63-
openapi : new Operation(tags: ['Referentiel']),
64-
order : ['debut' => 'DESC '],
65-
security : "is_granted('ROLE_PLANIFICATEUR') or is_granted('ROLE_INTERVENANT')",
66-
provider : TauxHoraireProvider::class,
67-
processor : TauxHoraireProcessor::class,
68-
stateOptions : new Options(entityClass: \App\Entity\TauxHoraire::class)
75+
openapi: new Operation(tags: ['Referentiel']),
76+
order: ['debut' => 'DESC '],
77+
security: "is_granted('ROLE_PLANIFICATEUR') or is_granted('ROLE_INTERVENANT')",
78+
provider: TauxHoraireProvider::class,
79+
processor: TauxHoraireProcessor::class,
80+
stateOptions: new Options(entityClass: \App\Entity\TauxHoraire::class)
6981
)]
82+
#[ApiFilter(TauxHoraireDateFilter::class)]
7083
class TauxHoraire
7184
{
7285
public const string COLLECTION_URI = '/types_evenements/{typeId}/taux';
@@ -80,6 +93,7 @@ class TauxHoraire
8093

8194
//copie juste pour gérer facilement les IRI
8295
public int $typeId;
96+
public TypeEvenement $typeEvenement;
8397

8498
#[Assert\NotBlank]
8599
#[Assert\Length(max: 5)]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Filter;
4+
5+
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
6+
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
7+
use ApiPlatform\Metadata\Operation;
8+
use Doctrine\ORM\QueryBuilder;
9+
use Symfony\Component\Clock\ClockAwareTrait;
10+
use Symfony\Component\PropertyInfo\Type;
11+
12+
class CampagneNonArchiveeFilter extends AbstractFilter
13+
{
14+
15+
use ClockAwareTrait;
16+
17+
public const string PROPERTY = 'archivees';
18+
19+
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
20+
{
21+
if ($property !== self::PROPERTY || !is_string($value) || $value != 'false') {
22+
return;
23+
}
24+
25+
$rootAlias = $queryBuilder->getRootAliases()[0];
26+
$campagneAlias = $queryNameGenerator->generateJoinAlias('campagne');
27+
28+
$queryBuilder->join(sprintf('%s.campagne', $rootAlias), $campagneAlias)
29+
->andWhere(sprintf('%1$s.dateArchivage IS NULL or %1$s.dateArchivage >= :now', $campagneAlias))
30+
->setParameter('now', $this->now());
31+
}
32+
33+
public function getDescription(string $resourceClass): array
34+
{
35+
return [
36+
'archivees' => [
37+
'property' => "archivees",
38+
'type' => Type::BUILTIN_TYPE_BOOL,
39+
'required' => false,
40+
'is_collection' => false,
41+
'openapi' => [
42+
'description' => "inclure les demandes des campagnes archivées?",
43+
'name' => 'archivees',
44+
'type' => 'boolean',
45+
],
46+
]
47+
];
48+
}
49+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Filter;
4+
5+
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
6+
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
7+
use ApiPlatform\Metadata\Operation;
8+
use DateTime;
9+
use Doctrine\ORM\QueryBuilder;
10+
use Exception;
11+
use Symfony\Component\HttpKernel\Exception\HttpException;
12+
use Symfony\Component\PropertyInfo\Type;
13+
14+
class TauxHoraireDateFilter extends AbstractFilter
15+
{
16+
17+
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
18+
{
19+
if ($property !== 'date') {
20+
return;
21+
}
22+
23+
$rootAlias = $queryBuilder->getRootAliases()[0];
24+
25+
try {
26+
$date = new DateTime($value);
27+
} catch (Exception) {
28+
throw new HttpException(400, "date mal formée");
29+
}
30+
31+
$queryBuilder
32+
->andWhere(sprintf('%1$s.debut <= :date AND (%1$s.fin >= :date or %1$s.fin is null)', $rootAlias))
33+
->setParameter('date', $date);
34+
35+
}
36+
37+
public function getDescription(string $resourceClass): array
38+
{
39+
return [
40+
'date' => [
41+
'property' => 'date',
42+
'type' => Type::BUILTIN_TYPE_STRING,
43+
'required' => false,
44+
'openapi' => [
45+
'description' => 'Taux horaire valide pour la date passée',
46+
'name' => 'profil',
47+
'type' => 'string',
48+
'format' => 'date'
49+
],
50+
],
51+
];
52+
}
53+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\State\TauxHoraire;
4+
5+
use ApiPlatform\Metadata\Operation;
6+
use ApiPlatform\State\ProviderInterface;
7+
use App\ApiResource\TauxHoraire;
8+
use App\State\TransformerService;
9+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
10+
11+
class TauxHoraireCollectionProvider implements ProviderInterface
12+
{
13+
public function __construct(
14+
#[Autowire(service: 'api_platform.doctrine.orm.state.collection_provider')] private readonly ProviderInterface $collectionProvider,
15+
private readonly TransformerService $transformerService
16+
)
17+
{
18+
19+
}
20+
21+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
22+
{
23+
$data = $this->collectionProvider->provide($operation, $uriVariables, $context);
24+
25+
return array_map(fn($taux) => $this->transformerService->transform($taux, TauxHoraire::class), iterator_to_array($data));
26+
}
27+
}

backend/src/State/TauxHoraire/TauxHoraireProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ApiPlatform\Metadata\Link;
1616
use ApiPlatform\Metadata\Operation;
1717
use App\ApiResource\TauxHoraire;
18+
use App\ApiResource\TypeEvenement;
1819
use App\State\AbstractEntityProvider;
1920
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
2021

@@ -41,9 +42,9 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4142
->withUriVariables([$link]);
4243

4344
$taux = parent::provide(
44-
operation : $relevantOperation,
45+
operation: $relevantOperation,
4546
uriVariables: $relevantVariables,
46-
context : $context
47+
context: $context
4748
);
4849

4950
//devrait être une contrainte de validation
@@ -65,6 +66,8 @@ public function transform($entity): TauxHoraire
6566
$resource->typeId = $entity->getTypeEvenement()->getId();
6667
$resource->debut = $entity->getDebut();
6768
$resource->fin = $entity->getFin();
69+
$resource->typeEvenement = new TypeEvenement();
70+
$resource->typeEvenement->id = $resource->typeId;
6871
return $resource;
6972
}
7073
}

0 commit comments

Comments
 (0)