From b8dde0e1c47452433fc31ee05403f62607956194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr> Date: Fri, 12 Apr 2019 12:42:24 +0200 Subject: [PATCH] #20381 --- CHANGELOG.md | 1 + code/test1.php | 11 +++-- .../Form/Intervenant/DossierFieldset.php | 4 +- .../src/Application/Service/PaysService.php | 21 ++++++--- .../DepartementNaissanceValidator.php | 12 +++-- .../Validator/NumeroINSEEValidator.php | 44 ++++++++++++++++--- 6 files changed, 65 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca640f8276..b315803abc 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/code/test1.php b/code/test1.php index 8b6668b40d..cd8e8152ad 100755 --- a/code/test1.php +++ b/code/test1.php @@ -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 diff --git a/module/Application/src/Application/Form/Intervenant/DossierFieldset.php b/module/Application/src/Application/Form/Intervenant/DossierFieldset.php index b6929188b5..cce18f96a8 100755 --- a/module/Application/src/Application/Form/Intervenant/DossierFieldset.php +++ b/module/Application/src/Application/Form/Intervenant/DossierFieldset.php @@ -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' => [ diff --git a/module/Application/src/Application/Service/PaysService.php b/module/Application/src/Application/Service/PaysService.php index d7100f41ab..f2a99700de 100755 --- a/module/Application/src/Application/Service/PaysService.php +++ b/module/Application/src/Application/Service/PaysService.php @@ -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); } diff --git a/module/Application/src/Application/Validator/DepartementNaissanceValidator.php b/module/Application/src/Application/Validator/DepartementNaissanceValidator.php index 8105a33c86..74fbb140a6 100755 --- a/module/Application/src/Application/Validator/DepartementNaissanceValidator.php +++ b/module/Application/src/Application/Validator/DepartementNaissanceValidator.php @@ -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'; @@ -20,12 +22,8 @@ class DepartementNaissanceValidator extends AbstractValidator public function __construct($options = null) { 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) diff --git a/module/Application/src/Application/Validator/NumeroINSEEValidator.php b/module/Application/src/Application/Validator/NumeroINSEEValidator.php index 098ee2fdda..105db5e8c4 100755 --- a/module/Application/src/Application/Validator/NumeroINSEEValidator.php +++ b/module/Application/src/Application/Validator/NumeroINSEEValidator.php @@ -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."); @@ -167,14 +174,21 @@ class NumeroINSEEValidator extends NumeroINSEE return true; } - $paysNaissance = (int)$context['paysNaissance']; - $estNeEnFrance = $paysNaissance === $this->franceId; + $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. * -- GitLab