Commit 34c77f12 authored by tguillon's avatar tguillon
Browse files

Correction : règle de validation

Correction : bdd
Correction : jquery
Ajout : calcul de l'obligation d'un AIPD coté serveur
parent 62752bbf
...@@ -106,9 +106,9 @@ ALTER TABLE fiches ...@@ -106,9 +106,9 @@ ALTER TABLE fiches
DROP CONSTRAINT fiches_form_id_fkey, DROP CONSTRAINT fiches_form_id_fkey,
ADD CONSTRAINT fiches_form_id_fkey FOREIGN KEY (form_id) REFERENCES formulaires (id) ON DELETE CASCADE ON UPDATE CASCADE; ADD CONSTRAINT fiches_form_id_fkey FOREIGN KEY (form_id) REFERENCES formulaires (id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE fiches ADD COLUMN obligation_pia BOOL; ALTER TABLE fiches ADD COLUMN obligation_pia BOOL DEFAULT NULL;
ALTER TABLE fiches ADD COLUMN realisation_pia BOOL NOT NULL DEFAULT FALSE; ALTER TABLE fiches ADD COLUMN realisation_pia BOOL DEFAULT NULL;
ALTER TABLE fiches ADD COLUMN depot_pia BOOL NOT NULL DEFAULT FALSE; ALTER TABLE fiches ADD COLUMN depot_pia BOOL DEFAULT NULL;
-- --
-- on passe le champ concernant la soutraitance à true en fonction si la fiche à un soustraitant -- on passe le champ concernant la soutraitance à true en fonction si la fiche à un soustraitant
......
...@@ -269,6 +269,10 @@ class FichesController extends AppController ...@@ -269,6 +269,10 @@ class FichesController extends AppController
] ]
]); ]);
if ($formulaireOptions['Formulaire']['usepia'] == true) {
$data['Fiche']['obligation_pia'] = $this->deductValueFieldObligationPia($data);
}
$success = $this->WebdpoFiche->saveWithVirtualFields($data, $formulaireFields, $formulaireOptions, false, true); $success = $this->WebdpoFiche->saveWithVirtualFields($data, $formulaireFields, $formulaireOptions, false, true);
if ($success == true) { if ($success == true) {
...@@ -583,6 +587,20 @@ class FichesController extends AppController ...@@ -583,6 +587,20 @@ class FichesController extends AppController
] ]
]); ]);
$formulaireOptions = $this->Formulaire->find('first', [
'conditions' => [
'id' => $form_id['Fiche']['form_id']
],
'fields' => [
'usesousfinalite',
'usebaselegale',
'usedecisionautomatisee',
'usetransferthorsue',
'usedonneessensible',
'usepia'
]
]);
$formulaireOLD = $this->Formulaire->find('first', [ $formulaireOLD = $this->Formulaire->find('first', [
'conditions' => [ 'conditions' => [
'id' => $form_id['Fiche']['form_id'] 'id' => $form_id['Fiche']['form_id']
...@@ -592,7 +610,13 @@ class FichesController extends AppController ...@@ -592,7 +610,13 @@ class FichesController extends AppController
] ]
]); ]);
$success = $this->WebdpoFiche->saveWithVirtualFields($data, $formulaireFields, $formulaireOLD['Formulaire']['oldformulaire']); if ($formulaireOLD['Formulaire']['oldformulaire'] === false) {
if ($formulaireOptions['Formulaire']['usepia'] == true) {
$data['Fiche']['obligation_pia'] = $this->deductValueFieldObligationPia($data);
}
}
$success = $this->WebdpoFiche->saveWithVirtualFields($data, $formulaireFields, $formulaireOptions, $formulaireOLD['Formulaire']['oldformulaire']);
if ($success == true) { if ($success == true) {
$this->Fiche->commit(); $this->Fiche->commit();
...@@ -1977,4 +2001,61 @@ class FichesController extends AppController ...@@ -1977,4 +2001,61 @@ class FichesController extends AppController
} }
} }
private function deductValueFieldObligationPia($data)
{
foreach (Fiche::LISTING_FIELDS_TRAITEMENT_NO_REQUIRED_PIA as $listingFieldsPiaNoRequired) {
if (!empty($data['WebdpoFiche'][$listingFieldsPiaNoRequired])) {
if ($data['WebdpoFiche'][$listingFieldsPiaNoRequired] == 'Oui') {
return false;
}
} else {
return null;
}
}
foreach (Fiche::LISTING_FIELDS_TRAITEMENT_REQUIRED_PIA as $listingFieldsPiaRequired) {
if (!empty($data['WebdpoFiche'][$listingFieldsPiaRequired])) {
if ($data['WebdpoFiche'][$listingFieldsPiaRequired] == 'Oui') {
return true;
}
} else {
return null;
}
}
foreach (Fiche::LISTING_FIELDS_TRAITEMENT_REQUIRED_PIA as $listingFieldsPiaRequired) {
if (!empty($data['WebdpoFiche'][$listingFieldsPiaRequired])) {
if ($data['WebdpoFiche'][$listingFieldsPiaRequired] == 'Oui') {
return true;
}
} else {
return null;
}
}
if (empty($data['WebdpoFiche']['criteres'])) {
return null;
}
$countOptionsChecked = count($data['WebdpoFiche']['criteres']);
if ($countOptionsChecked >= 2) {
return true;
}
if (empty($data['WebdpoFiche']['traitement_considere_risque'])) {
return null;
}
if ($countOptionsChecked == 1) {
if ($data['WebdpoFiche']['traitement_considere_risque'] == 'Oui') {
return true;
}
if ($data['WebdpoFiche']['traitement_considere_risque'] == 'Non') {
return false;
}
}
return null;
}
} }
...@@ -287,6 +287,38 @@ class Fiche extends AppModel { ...@@ -287,6 +287,38 @@ class Fiche extends AppModel {
"Exclusion du bénéfice d’un droit/contrat" => "Exclusion du bénéfice d’un droit/contrat" "Exclusion du bénéfice d’un droit/contrat" => "Exclusion du bénéfice d’un droit/contrat"
]; ];
const LISTING_FIELDS_TRAITEMENT_NO_REQUIRED_PIA = [
'ressources_humaines',
'relation_fournisseurs',
'gestion_electoral',
'comites_entreprise',
'association',
'sante_prise_patient',
'avocats',
'greffiers',
'notaires',
'collectivites_affaires_scolaires',
'controles_acces',
'ethylotests'
];
const LISTING_FIELDS_TRAITEMENT_REQUIRED_PIA = [
'sante_medicosociaux',
'donnees_genetiques',
'profils_personnes_gestion_rh',
'surveiller_constante_employes',
'gestion_alertes_sociale_sanitaire',
'gestion_alertes_professionnelle',
'donnees_sante_registre',
'profilage_rupture_contrat',
'mutualises_manquements_rupture_contrat',
'profilage_donnees_externes',
'biometriques',
'gestion_logements_sociaux',
'accompagnement_social',
'localisation_large_echelle'
];
public $validate = [ public $validate = [
'organisation_id' => [ 'organisation_id' => [
'areUnique' => [ 'areUnique' => [
...@@ -302,16 +334,34 @@ class Fiche extends AppModel { ...@@ -302,16 +334,34 @@ class Fiche extends AppModel {
'message' => '... est déjà utilisée.' 'message' => '... est déjà utilisée.'
] ]
], ],
// 'realisation_pia' => [ // 'obligation_pia' => [
// 'notBlank' => [
// 'rule' => ['notBlank']
// ]
// ],
// 'depot_pia' => [
// 'checkNotBlankIf' => [ // 'checkNotBlankIf' => [
// 'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']] // 'rule' => ['checkNotBlankIf', 'usepia', true, [true]]
// ] // ]
// ], // ],
'realisation_pia' => [
'checkNotBlankIf' => [
'rule' => ['checkNotBlankIf', 'formulaireOLD', true, [false]]
],
],
'depot_pia' => [
'checkNotBlankIf' => [
'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']]
],
'checkBlankIf' => [
'rule' => ['checkBlankIf', 'realisation_pia', true, ['0']]
]
],
'coresponsable' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
'soustraitance' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
]; ];
/** /**
......
...@@ -70,33 +70,6 @@ class WebdpoFiche extends AppModel { ...@@ -70,33 +70,6 @@ class WebdpoFiche extends AppModel {
] ]
], ],
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// ------------------INFORMATION TRAITEMENT-----------------------------
'realisation_pia' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
'depot_pia' => [
'checkNotBlankIf' => [
'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']]
]
],
'coresponsable' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
'soustraitance' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
// 'obligation_pia' => [
// 'checkNotBlankIf' => [
// 'rule' => ['checkNotBlankIf', 'usepia', true, [true]]
// ]
// ],
// ---------------------------------------------------------------------
// 'declarantraisonsociale' => [ // 'declarantraisonsociale' => [
// 'notBlank' => [ // 'notBlank' => [
// 'rule' => ['notBlank'] // 'rule' => ['notBlank']
...@@ -499,6 +472,11 @@ class WebdpoFiche extends AppModel { ...@@ -499,6 +472,11 @@ class WebdpoFiche extends AppModel {
unset($data['Fiche']['soustraitant']); unset($data['Fiche']['soustraitant']);
// champ virtuel pour la régle de validation
$data['Fiche']['usepia'] = $formulaireOptions['Formulaire']['usepia'];
$data['Fiche']['formulaireOLD'] = $formulaireOLD;
// Sauvegarde BDD Fiches
$Fiche->create($data['Fiche']); $Fiche->create($data['Fiche']);
$success = false !== $Fiche->save(null, ['atomic' => false]) && $success; $success = false !== $Fiche->save(null, ['atomic' => false]) && $success;
...@@ -763,14 +741,16 @@ class WebdpoFiche extends AppModel { ...@@ -763,14 +741,16 @@ class WebdpoFiche extends AppModel {
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}"); $referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) { if (!empty($checks)) {
if(empty($referenceValue)) { if (empty($referenceValue)) {
$countOptionsChecked = 0; $countOptionsChecked = 0;
} else { } else {
$countOptionsChecked = count($referenceValue); $countOptionsChecked = count($referenceValue);
} }
if ($countOptionsChecked == $nbOptionsChecked) { if ($countOptionsChecked == $nbOptionsChecked) {
$success = Validation::notBlank($checks) && $success; foreach ($checks as $value) {
$success = Validation::notBlank($value) && $success;
}
} }
} }
...@@ -787,10 +767,16 @@ class WebdpoFiche extends AppModel { ...@@ -787,10 +767,16 @@ class WebdpoFiche extends AppModel {
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}"); $referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) { if (!empty($checks)) {
$countOptionsChecked = count($referenceValue); if (empty($referenceValue)) {
$countOptionsChecked = 0;
} else {
$countOptionsChecked = count($referenceValue);
}
if ($countOptionsChecked >= $nbOptionsChecked) { if ($countOptionsChecked >= $nbOptionsChecked) {
$success = Validation::blank($checks) && $success; foreach ($checks as $value) {
$success = Validation::blank($value) && $success;
}
} }
} }
......
...@@ -309,30 +309,62 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) { ...@@ -309,30 +309,62 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
</div> </div>
</div> </div>
<div class="col-md-12"> <?php
<span class='labelFormulaire'> if ($formulaireOLD['Formulaire']['oldformulaire'] === false) {
<?php if (isset($usePIA) && $usePIA['Formulaire']['usepia'] === true) {
echo __d('fiche', 'fiche.textInfoPia');
?> ?>
</span> <div class="col-md-12">
<div class="row row35"></div> <span class='labelFormulaire'>
</div> <?php
echo __d('fiche', 'fiche.textInfoPia');
?>
</span>
<div class="row row35"></div>
</div>
<?php <div class="row">
if($usePIA['Formulaire']['usepia'] === true) { <div class="col-md-6">
<?php
echo $this->WebcilForm->input('obligation_pia', [
'id' => 'obligation_pia',
// 'id' => 'obligation_pia_displayed',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'readonly' => true,
'disabled' => true,
'empty' => true,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
<div class="col-md-6"></div>
</div>
<?php
} else {
echo $this->WebcilForm->hidden('obligation_pia', [
'id' => 'obligation_pia',
'value' => null
]);
}
?> ?>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?php <?php
echo $this->WebcilForm->input('obligation_pia', [ echo $this->WebcilForm->input('realisation_pia', [
'id' => 'obligation_pia', 'id' => 'realisation_pia',
'options' => [ 'options' => [
true => 'Oui', true => 'Oui',
false => 'Non' false => 'Non'
], ],
'class' => 'transformSelect form-control', 'class' => 'transformSelect form-control',
'required' => true, 'required' => true,
'readonly' => true,
'empty' => $empty, 'empty' => $empty,
'placeholder' => false, 'placeholder' => false,
'data-placeholder' => ' ' 'data-placeholder' => ' '
...@@ -340,51 +372,26 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) { ...@@ -340,51 +372,26 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
?> ?>
</div> </div>
<div class="col-md-6"></div> <div class="col-md-6">
<?php
echo $this->WebcilForm->input('depot_pia', [
'id' => 'depot_pia',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'empty' => $empty,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
</div> </div>
<?php <?php
} else {
echo $this->WebcilForm->hidden('obligation_pia', ['value' => null]);
} }
?>
<div class="row">
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('realisation_pia', [
'id' => 'realisation_pia',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'empty' => $empty,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('depot_pia', [
'id' => 'depot_pia',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'empty' => $empty,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
</div>
<?php
$showCoresponsable = true; $showCoresponsable = true;
if ($formulaireOLD['Formulaire']['oldformulaire'] === true) { if ($formulaireOLD['Formulaire']['oldformulaire'] === true) {
if (empty($responsables)) { if (empty($responsables)) {
...@@ -510,11 +517,6 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) { ...@@ -510,11 +517,6 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
$("#descriptionNorme").val(str); $("#descriptionNorme").val(str);
}); });
var usePIA = <?php echo json_encode($usePIA['Formulaire']['usepia']); ?>;
if (usePIA == true) {
$('#obligation_pia').prop("disabled", true);
}
displayFieldDepotPIA($('#realisation_pia').val()); displayFieldDepotPIA($('#realisation_pia').val());
$('#realisation_pia').change(function () { $('#realisation_pia').change(function () {
var val = $(this).val(); var val = $(this).val();
...@@ -527,6 +529,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) { ...@@ -527,6 +529,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
if (val == true) { if (val == true) {
$('#depot_pia').parent().parent().show(); $('#depot_pia').parent().parent().show();
} else { } else {
$('#depot_pia').val('');
$('#depot_pia').parent().parent().hide(); $('#depot_pia').parent().parent().hide();
} }
} }
......
This diff is collapsed.
<?php <?php
echo $this->Html->script('jquery-mask-plugin/dist/jquery.mask.min.js'); echo $this->Html->script('jquery-mask-plugin/dist/jquery.mask.min.js');
debug($this->validationErrors);
if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErrors['WebdpoFiche'])) { if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErrors['WebdpoFiche'])) {
?> ?>
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
......
...@@ -145,7 +145,9 @@ $(document).ready(function () { ...@@ -145,7 +145,9 @@ $(document).ready(function () {
if ($(this).val() == 'Oui') { if ($(this).val() == 'Oui') {
// alert('PIA OBLIGATOIRE'); // alert('PIA OBLIGATOIRE');
$('#obligation_pia').val('1'); $('#obligation_pia').val('1');
} else { }
if ($(this).val() == 'Non') {
// alert('PIA NON OBLIGATOIRE'); // alert('PIA NON OBLIGATOIRE');
$('#obligation_pia').val('0'); $('#obligation_pia').val('0');
} }
...@@ -158,12 +160,14 @@ function displayFieldRisque() ...@@ -158,12 +160,14 @@ function displayFieldRisque()
if (nbChecked >= 2 ){ if (nbChecked >= 2 ){
$('#traitement_considere_risque').parent().parent().hide(); $('#traitement_considere_risque').parent().parent().hide();
$('#traitement_considere_risque').val('');
// alert("PIA OBLIGATOIRE"); // alert("PIA OBLIGATOIRE");
$('#obligation_pia').val('1'); $('#obligation_pia').val('1');
} else if (nbChecked == 1) { } else if (nbChecked == 1) {
$('#traitement_considere_risque').parent().parent().show(); $('#traitement_considere_risque').parent().parent().show();
} else if (nbChecked == 0) { } else if (nbChecked == 0) {
$('#traitement_considere_risque').parent().parent().hide(); $('#traitement_considere_risque').parent().parent().hide();
$('#traitement_considere_risque').val('');
} }
} }
...@@ -180,14 +184,21 @@ function displayFieldPiaListNotRequired(id, val) { ...@@ -180,14 +184,21 @@ function displayFieldPiaListNotRequired(id, val) {
if (!$('#'+id).parent().parent().next('div').length) { if (!$('#'+id).parent().parent().next('div').length) {
showListeObligatoire(); showListeObligatoire();
} }
} else { } else {
// if (val == 'Oui') {
$('#'+id).parent().parent().nextAll('div').hide(); $('#'+id).parent().parent().nextAll('div').hide();
$('#'+id).parent().parent().nextAll('div').children().children().prop('selectedIndex',0); $('#'+id).parent().parent().nextAll('div').children().children().prop('selectedIndex',0);