Merge remote-tracking branch 'origin/master' into track-address-reference-update

This commit is contained in:
2023-04-12 09:45:19 +02:00
273 changed files with 8869 additions and 3001 deletions

View File

@@ -66,22 +66,6 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
$manager->flush();
}
private function createAddress(): ObjectSet
{
$loader = new NativeLoader();
return $loader->loadData([
Address::class => [
'address1' => [
'name' => '<fr_FR:company()>',
'telephone' => $this->phoneNumberUtil->getExampleNumber('FR'),
'email' => '<email()>',
'comment' => '<fr_FR:realTextBetween(10, 500)>',
],
],
]);
}
private function getCenters(): Iterator
{
$references = array_map(

View File

@@ -23,6 +23,7 @@ use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumber;
use Symfony\Component\Serializer\Annotation\Context;
@@ -153,7 +154,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent",
* cascade={"persist"}, orphanRemoval=true)
*
* @var Collection|ThirdParty[]
* @var Collection<(int|string), ThirdParty>
* @Assert\Valid(traverse=true)
*/
private Collection $children;
@@ -400,7 +401,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* Get the children where active = true.
*/
public function getActiveChildren(): Collection
public function getActiveChildren(): ReadableCollection
{
return $this->children->filter(static fn (ThirdParty $tp) => $tp->getActive());
}

View File

@@ -23,6 +23,8 @@ use function in_array;
/**
* Lazy load third parties.
*
* @deprecated As the PickThirdPartyType is deprecated, this should not be in use
*/
class ThirdPartyChoiceLoader implements ChoiceLoaderInterface
{
@@ -57,10 +59,6 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface
$choices = [];
foreach ($values as $value) {
if (empty($value)) {
continue;
}
$party = $this->partyRepository->find($value);
if (false === in_array($this->center, $party->getCenters()->toArray(), true)) {

View File

@@ -29,6 +29,10 @@ use function array_merge;
use function count;
use function is_array;
/**
* @deprecated use the @link{PickThirdPartyDynamicType::class}
* @note do remove ThirdPartyChoiceLoader if this class is removed
*/
class PickThirdPartyType extends AbstractType
{
/**

View File

@@ -88,22 +88,12 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp
return ChoiceType::class;
}
public function reverseTransform($value)
private function reverseTransform($value)
{
if (null === $value) {
return null;
}
if (is_array($value)) {
$r = [];
foreach ($value as $v) {
$r[] = $this->transform($v);
}
return $r;
}
if ($value instanceof ThirdPartyCategory) {
return 'category:' . $value->getId();
}

View File

@@ -18,6 +18,7 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;
/**
@@ -27,12 +28,15 @@ class PickThirdpartyDynamicType extends AbstractType
{
private DenormalizerInterface $denormalizer;
private NormalizerInterface $normalizer;
private SerializerInterface $serializer;
public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer)
public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, NormalizerInterface $normalizer)
{
$this->denormalizer = $denormalizer;
$this->serializer = $serializer;
$this->normalizer = $normalizer;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@@ -45,6 +49,11 @@ class PickThirdpartyDynamicType extends AbstractType
$view->vars['multiple'] = $options['multiple'];
$view->vars['types'] = ['thirdparty'];
$view->vars['uniqid'] = uniqid('pick_user_dyn');
$view->vars['suggested'] = [];
foreach ($options['suggested'] as $tp) {
$view->vars['suggested'][] = $this->normalizer->normalize($tp, 'json', ['groups' => 'read']);
}
}
public function configureOptions(OptionsResolver $resolver)
@@ -52,7 +61,8 @@ class PickThirdpartyDynamicType extends AbstractType
$resolver
->setDefault('multiple', false)
->setAllowedTypes('multiple', ['bool'])
->setDefault('compound', false);
->setDefault('compound', false)
->setDefault('suggested', []);
}
public function getBlockPrefix()

View File

@@ -33,9 +33,8 @@ final class ThirdPartyRepository implements ObjectRepository
/**
* count amongst parties associated to $centers, with $terms parameters.
*
* @param type $terms
*/
public function countByMemberOfCenters(array $centers, $terms = []): int
public function countByMemberOfCenters(array $centers, array $terms = []): int
{
$qb = $this->buildQuery($centers, $terms);
$qb->select('COUNT(tp)');
@@ -181,7 +180,7 @@ final class ThirdPartyRepository implements ObjectRepository
if (array_key_exists('name', $terms) || array_key_exists('_default', $terms)) {
$term = $terms['name'] ?? $terms['_default'];
if (empty($term)) {
if (null === $term || '' === $term) {
return;
}
$qb->andWhere($qb->expr()->like('UNACCENT(LOWER(tp.name))', 'UNACCENT(LOWER(:name))'));

View File

@@ -15,6 +15,7 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Search\SearchInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -47,16 +48,20 @@ class ThirdPartySearch implements SearchInterface
*/
protected $tokenStorage;
private ThirdPartyRepository $thirdPartyRepository;
public function __construct(
EntityManagerInterface $em,
TokenStorageInterface $tokenStorage,
AuthorizationHelper $authorizationHelper,
PaginatorFactory $paginatorFactory
PaginatorFactory $paginatorFactory,
ThirdPartyRepository $thirdPartyRepository
) {
$this->em = $em;
$this->tokenStorage = $tokenStorage;
$this->authorizationHelper = $authorizationHelper;
$this->paginatorFactory = $paginatorFactory;
$this->thirdPartyRepository = $thirdPartyRepository;
}
public function getOrder(): int
@@ -74,7 +79,7 @@ class ThirdPartySearch implements SearchInterface
$centers = $this->authorizationHelper
->getReachableCenters(
$this->tokenStorage->getToken()->getUser(),
new Role(ThirdPartyVoter::SHOW)
ThirdPartyVoter::SHOW
);
$total = $this->count($centers, $terms);
$paginator = $this->paginatorFactory->create($total);
@@ -84,7 +89,7 @@ class ThirdPartySearch implements SearchInterface
if ('json' === $format) {
return [
'results' => $this->em->getRepository(ThirdParty::class)
'results' => $this->thirdPartyRepository
->findByMemberOfCenters(
$centers,
$start,
@@ -95,6 +100,8 @@ class ThirdPartySearch implements SearchInterface
'more' => $paginator->hasNextPage(),
];
}
// format "html"
throw new \UnexpectedValueException("format html not supported");
}
public function supports($domain, $format): bool
@@ -104,7 +111,7 @@ class ThirdPartySearch implements SearchInterface
protected function count($centers, $terms): int
{
return $this->em->getRepository(ThirdParty::class)
return $this->thirdPartyRepository
->countByMemberOfCenters($centers, $terms);
}
}

View File

@@ -15,6 +15,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -35,12 +36,12 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @param ThirdParty $thirdParty
* @param string|null $format
*/
public function normalize($thirdParty, $format = null, array $context = [])
{
if (!$thirdParty instanceof ThirdParty) {
throw new UnexpectedValueException();
}
return [
'type' => 'thirdparty',
'firstname' => $thirdParty->getFirstname(),

View File

@@ -12,12 +12,18 @@ declare(strict_types=1);
namespace Chill\ThirdPartyBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Templating\EngineInterface;
class ThirdPartyRender extends AbstractChillEntityRender
/**
* @implements ChillEntityRenderInterface<ThirdParty>
*/
class ThirdPartyRender implements ChillEntityRenderInterface
{
use BoxUtilsChillEntityRenderTrait;
protected EngineInterface $engine;
protected TranslatableStringHelper $translatableStringHelper;
@@ -30,9 +36,6 @@ class ThirdPartyRender extends AbstractChillEntityRender
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @param ThirdParty $entity
*/
public function renderBox($entity, array $options): string
{
$params = [
@@ -59,9 +62,6 @@ class ThirdPartyRender extends AbstractChillEntityRender
$this->getDefaultClosingBox();
}
/**
* @param ThirdParty $entity
*/
public function renderString($entity, array $options): string
{
if ($entity->getCivility() !== null) {

View File

@@ -1,10 +1,7 @@
services:
Chill\ThirdPartyBundle\Search\ThirdPartySearch:
arguments:
$em: '@Doctrine\ORM\EntityManagerInterface'
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
$paginatorFactory: '@Chill\MainBundle\Pagination\PaginatorFactory'
autowire: true
autoconfigure: true
tags:
- { name: 'chill.search', alias: '3party' }

View File

@@ -25,7 +25,7 @@ final class Version20230215175150 extends AbstractMigration implements Container
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_3party.third_party DROP profession');
// $this->addSql('ALTER TABLE chill_3party.third_party ADD profession_id INT DEFAULT NULL');
// $this->addSql('ALTER TABLE chill_3party.third_party ADD profession_id INT DEFAULT NULL');
}
public function getDescription(): string