mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-28 13:06:13 +00:00
final fix for appellation selector: define metier when appellation already exists
This commit is contained in:
parent
405aad7333
commit
436ef33dbc
@ -12,11 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\FranceTravailApiBundle\ApiHelper;
|
namespace Chill\FranceTravailApiBundle\ApiHelper;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\ClientException;
|
|
||||||
use GuzzleHttp\Psr7\Request;
|
|
||||||
use GuzzleHttp\Utils;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,19 +63,21 @@ class PartenaireRomeAppellation
|
|||||||
$bearer = $this->getBearer();
|
$bearer = $this->getBearer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->httpClient->request(
|
$response = $this->httpClient->request(
|
||||||
'GET', self::BASE . 'appellation/requete', [
|
'GET',
|
||||||
'headers' => [
|
self::BASE.'appellation/requete',
|
||||||
'Authorization' => 'Bearer '.$bearer,
|
[
|
||||||
'Accept' => 'application/json',
|
'headers' => [
|
||||||
],
|
'Authorization' => 'Bearer '.$bearer,
|
||||||
'query' => [
|
'Accept' => 'application/json',
|
||||||
'q' => $search
|
],
|
||||||
],
|
'query' => [
|
||||||
]
|
'q' => $search,
|
||||||
);
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return $response->toArray()['resultats'];
|
return $response->toArray()['resultats'];
|
||||||
} catch (HttpExceptionInterface $exception) {
|
} catch (HttpExceptionInterface $exception) {
|
||||||
throw $exception;
|
throw $exception;
|
||||||
}
|
}
|
||||||
@ -90,14 +88,14 @@ class PartenaireRomeAppellation
|
|||||||
$bearer = $this->getBearer();
|
$bearer = $this->getBearer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->httpClient->request('GET', sprintf(self::BASE . 'appellation/%s', $code), [
|
$response = $this->httpClient->request('GET', sprintf(self::BASE.'appellation/%s', $code), [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization' => 'Bearer '.$bearer,
|
'Authorization' => 'Bearer '.$bearer,
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
],
|
],
|
||||||
'query' => [
|
'query' => [
|
||||||
'champs' => 'code,libelle,metier(code,libelle)',
|
'champs' => 'code,libelle,metier(code,libelle)',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $response->toArray();
|
return $response->toArray();
|
||||||
|
@ -11,7 +11,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\JobBundle\Form\ChoiceLoader;
|
namespace Chill\JobBundle\Form\ChoiceLoader;
|
||||||
|
|
||||||
use App\App;
|
|
||||||
use Chill\FranceTravailApiBundle\ApiHelper\PartenaireRomeAppellation;
|
use Chill\FranceTravailApiBundle\ApiHelper\PartenaireRomeAppellation;
|
||||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||||
@ -87,6 +86,10 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
|
|||||||
$code = \substr($v, \strlen('original-'));
|
$code = \substr($v, \strlen('original-'));
|
||||||
$appellation = $this->appellationRepository->findOneBy(['code' => $code]);
|
$appellation = $this->appellationRepository->findOneBy(['code' => $code]);
|
||||||
|
|
||||||
|
if ($appellation) {
|
||||||
|
$metier = $appellation->getMetier();
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $appellation) {
|
if (null === $appellation) {
|
||||||
if (array_key_exists($v, $this->toBeCreated)) {
|
if (array_key_exists($v, $this->toBeCreated)) {
|
||||||
[$appellation, $metier] = $this->toBeCreated[$v];
|
[$appellation, $metier] = $this->toBeCreated[$v];
|
||||||
@ -101,12 +104,11 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
|
|||||||
if (null === $appellation && '' !== $code) {
|
if (null === $appellation && '' !== $code) {
|
||||||
$def = $this->apiAppellation->getAppellation($code);
|
$def = $this->apiAppellation->getAppellation($code);
|
||||||
|
|
||||||
$metier = $metier
|
$metier ??= $this->em->getRepository(Metier::class)
|
||||||
?? $this->em->getRepository(Metier::class)
|
->findOneBy(['code' => $def['metier']['code']])
|
||||||
->findOneBy(['code' => $def['metier']['code']])
|
?? (new Metier())
|
||||||
?? (new Metier())
|
->setCode($def['metier']['code'])
|
||||||
->setCode($def['metier']['code'])
|
->setLibelle($def['metier']['libelle']);
|
||||||
->setLibelle($def['metier']['libelle']);
|
|
||||||
|
|
||||||
$appellation = new Appellation();
|
$appellation = new Appellation();
|
||||||
|
|
||||||
@ -119,7 +121,7 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
|
|||||||
$errorsAppellation = $this->validator->validate($appellation);
|
$errorsAppellation = $this->validator->validate($appellation);
|
||||||
$errorsMetier = $this->validator->validate($metier);
|
$errorsMetier = $this->validator->validate($metier);
|
||||||
|
|
||||||
if ($errorsAppellation->count() === 0 && $errorsMetier->count() === 0) {
|
if (0 === $errorsAppellation->count() && 0 === $errorsMetier->count()) {
|
||||||
$this->toBeCreated[$v] = [$appellation, $metier];
|
$this->toBeCreated[$v] = [$appellation, $metier];
|
||||||
$this->em->persist($appellation);
|
$this->em->persist($appellation);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user