Skip to content
Snippets Groups Projects
Commit b8dde0e1 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

#20381

parent c8a940b4
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ dans le détail des services.
* Procédures d'installation et de mise à jour intégrées directement au projet dans Gitlab.
* Certains dossiers intervenants pouvaient être validés plusieurs fois.
Un mécanisme contrôle désormais que le dossier n'est pas déjà validé avant de valider à nouveau.
* Le contrôle de cohérence des données personnelles prend maintenant en compte le cas des français nés dans un ex-département français d'Algérie.
## Nouveautés
......
......@@ -7,10 +7,9 @@
* @var $sl \Zend\ServiceManager\ServiceLocatorInterface
*/
$command = 'unoconv -f pdf -o /app/test.pdf /app/test.odt';
//$command = 'systemctl list-units';
//$command = 'ls';
$sp = $sl->get(\Application\Service\PaysService::class);
exec($command, $output, $return);
var_dump($output);
var_dump($return);
\ No newline at end of file
$france = $sp->getIdByLibelle('Algérie');
var_dump($france);
\ No newline at end of file
......@@ -3,8 +3,6 @@
namespace Application\Form\Intervenant;
use Application\Entity\Db\Dossier as Dossier;
use Application\Entity\Db\Pays as PaysEntity;
use Application\Entity\Db\Pays;
use Application\Entity\Db\StatutIntervenant;
use Application\Form\AbstractFieldset;
use Application\Service\Traits\CiviliteServiceAwareTrait;
......@@ -370,7 +368,7 @@ class DossierFieldset extends AbstractFieldset
'departementNaissance' => [
'required' => $departementRequired,
'validators' => [
new DepartementNaissanceValidator(['france_id' => self::$franceId]),
new DepartementNaissanceValidator(),
],
],
'villeNaissance' => [
......
......@@ -5,12 +5,17 @@ namespace Application\Service;
use Application\Entity\Db\Pays;
use Application\Service\Traits\ParametresServiceAwareTrait;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Util;
/**
* Description of Pays
*/
class PaysService extends AbstractEntityService
{
CONST PAYS_FRANCE = 'france ';
CONST PAYS_ALGERIE = 'algerie';
use ParametresServiceAwareTrait;
......@@ -40,13 +45,19 @@ class PaysService extends AbstractEntityService
/**
* @return Pays
* @return int|null
*/
public function getFrance(): Pays
public function getIdByLibelle(string $libelle)
{
$franceId = $this->getServiceParametres()->get('pays_france');
$sql = 'SELECT id FROM pays WHERE ose_divers.str_reduce(libelle_court) = :pays';
$res = $this->getEntityManager()->getConnection()->fetchAll($sql, ['pays' => Util::reduce($libelle)]);
if (isset($res[0]['ID'])){
return (int)$res[0]['ID'];
}
return $this->get($franceId);
return null;
}
......@@ -58,7 +69,7 @@ class PaysService extends AbstractEntityService
*/
public function isFrance(Pays $pays): bool
{
return $pays == $this->getFrance();
return $pays->getId() == $this->getIdByLibelle(self::PAYS_FRANCE);
}
......
......@@ -2,11 +2,13 @@
namespace Application\Validator;
use LogicException;
use Application\Service\Traits\PaysServiceAwareTrait;
use Zend\Validator\AbstractValidator;
class DepartementNaissanceValidator extends AbstractValidator
{
use PaysServiceAwareTrait;
const MSG_NOT_REQUIRED = 'msgNotRequired';
const MSG_REQUIRED = 'msgRequired';
......@@ -21,11 +23,7 @@ class DepartementNaissanceValidator extends AbstractValidator
{
parent::__construct($options);
if (!isset($options['france_id'])) {
throw new LogicException("Paramètre 'france_id' introuvable.");
}
$this->franceId = $options['france_id'];
$this->franceId = $this->getServicePays()->getIdByLibelle($this->getServicePays()::PAYS_FRANCE);
}
public function isValid($value, $context = null)
......
......@@ -4,6 +4,7 @@ namespace Application\Validator;
use Application\Service\Traits\CiviliteServiceAwareTrait;
use Application\Service\Traits\DepartementServiceAwareTrait;
use Application\Service\Traits\PaysServiceAwareTrait;
use LogicException;
use UnicaenApp\Validator\NumeroINSEE;
......@@ -21,12 +22,21 @@ class NumeroINSEEValidator extends NumeroINSEE
{
use DepartementServiceAwareTrait;
use CiviliteServiceAwareTrait;
use PaysServiceAwareTrait;
const MSG_CIVILITE = 'msgCivilite';
const MSG_ANNEE = 'msgAnnee';
const MSG_MOIS = 'msgMois';
const MSG_DEPT = 'msgDepartement';
/**
* @var ?int
*/
protected $algerieId;
/**
* @var ?int
*/
protected $franceId;
......@@ -40,11 +50,8 @@ class NumeroINSEEValidator extends NumeroINSEE
self::MSG_DEPT => "Le numéro n'est pas cohérent avec le pays et l'éventuel département de naissance saisi",
]);
if (!isset($options['france_id'])) {
throw new LogicException("Paramètre 'france_id' introuvable.");
}
$this->franceId = (int)$options['france_id'];
$this->franceId = $this->getServicePays()->getIdByLibelle('FRANCE');
$this->algerieId = $this->getServicePays()->getIdByLibelle('ALGERIE');
if (!isset($options['serviceDepartement'])) {
throw new LogicException("Service Département non fourni.");
......@@ -169,12 +176,19 @@ class NumeroINSEEValidator extends NumeroINSEE
$paysNaissance = (int)$context['paysNaissance'];
$estNeEnFrance = $paysNaissance === $this->franceId;
$estNeEnAlgerie = $paysNaissance === $this->algerieId;
if ($estNeEnFrance) {
// on doit avoir un code département français valide
if (!$this->isValidDepartementFrance($value, $context)) {
return false;
}
}
if ($estNeEnAlgerie) {
// on doit avoir un code département français valide
if (!$this->isValidDepartementAlgerie($value, $context)) {
return false;
}
} else {
// on doit avoir un code pays étranger valide
if (!$this->isValidDepartementHorsFrance($value)) {
......@@ -280,6 +294,22 @@ class NumeroINSEEValidator extends NumeroINSEE
private function isValidDepartementAlgerie($value, $context)
{
$departement = substr($value, 5, 2);
if (is_numeric($departement)) {
$d = (int)$departement;
if (in_array($d, [91,92,93,94,99])) {
return '0' . (string)$departement;
}
}
return null;
}
/**
* Teste si un numéro INSEE possède le code département de naissance associé à un pays étranger.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment