-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'EsupPortail:main' into dev
- Loading branch information
Showing
6 changed files
with
187 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Filter; | ||
|
||
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter; | ||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Symfony\Component\Clock\ClockAwareTrait; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
class CampagneNonArchiveeFilter extends AbstractFilter | ||
{ | ||
|
||
use ClockAwareTrait; | ||
|
||
public const string PROPERTY = 'archivees'; | ||
|
||
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void | ||
{ | ||
if ($property !== self::PROPERTY || !is_string($value) || $value != 'false') { | ||
return; | ||
} | ||
|
||
$rootAlias = $queryBuilder->getRootAliases()[0]; | ||
$campagneAlias = $queryNameGenerator->generateJoinAlias('campagne'); | ||
|
||
$queryBuilder->join(sprintf('%s.campagne', $rootAlias), $campagneAlias) | ||
->andWhere(sprintf('%1$s.dateArchivage IS NULL or %1$s.dateArchivage >= :now', $campagneAlias)) | ||
->setParameter('now', $this->now()); | ||
} | ||
|
||
public function getDescription(string $resourceClass): array | ||
{ | ||
return [ | ||
'archivees' => [ | ||
'property' => "archivees", | ||
'type' => Type::BUILTIN_TYPE_BOOL, | ||
'required' => false, | ||
'is_collection' => false, | ||
'openapi' => [ | ||
'description' => "inclure les demandes des campagnes archivées?", | ||
'name' => 'archivees', | ||
'type' => 'boolean', | ||
], | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Filter; | ||
|
||
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter; | ||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use DateTime; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Exception; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
class TauxHoraireDateFilter extends AbstractFilter | ||
{ | ||
|
||
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void | ||
{ | ||
if ($property !== 'date') { | ||
return; | ||
} | ||
|
||
$rootAlias = $queryBuilder->getRootAliases()[0]; | ||
|
||
try { | ||
$date = new DateTime($value); | ||
} catch (Exception) { | ||
throw new HttpException(400, "date mal formée"); | ||
} | ||
|
||
$queryBuilder | ||
->andWhere(sprintf('%1$s.debut <= :date AND (%1$s.fin >= :date or %1$s.fin is null)', $rootAlias)) | ||
->setParameter('date', $date); | ||
|
||
} | ||
|
||
public function getDescription(string $resourceClass): array | ||
{ | ||
return [ | ||
'date' => [ | ||
'property' => 'date', | ||
'type' => Type::BUILTIN_TYPE_STRING, | ||
'required' => false, | ||
'openapi' => [ | ||
'description' => 'Taux horaire valide pour la date passée', | ||
'name' => 'profil', | ||
'type' => 'string', | ||
'format' => 'date' | ||
], | ||
], | ||
]; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/State/TauxHoraire/TauxHoraireCollectionProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\State\TauxHoraire; | ||
|
||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\State\ProviderInterface; | ||
use App\ApiResource\TauxHoraire; | ||
use App\State\TransformerService; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
class TauxHoraireCollectionProvider implements ProviderInterface | ||
{ | ||
public function __construct( | ||
#[Autowire(service: 'api_platform.doctrine.orm.state.collection_provider')] private readonly ProviderInterface $collectionProvider, | ||
private readonly TransformerService $transformerService | ||
) | ||
{ | ||
|
||
} | ||
|
||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null | ||
{ | ||
$data = $this->collectionProvider->provide($operation, $uriVariables, $context); | ||
|
||
return array_map(fn($taux) => $this->transformerService->transform($taux, TauxHoraire::class), iterator_to_array($data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters