Commit 4fcdb3e5 authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Modification : enregistrement de multi-coresponsable

parent 5603fb1e
......@@ -280,5 +280,21 @@ modified
WHERE
fiches.coresponsableid IS NOT NULL ;
ALTER TABLE fiches DROP coresponsableid;
DELETE FROM valeurs WHERE champ_name IN (
'nomcoresponsable',
'prenomcoresponsable',
'fonctioncoresponsable',
'emailcoresponsable',
'telephonecoresponsable',
'raisonsocialestructure',
'siretstructure',
'apestructure',
'telephonestructure',
'faxstructure',
'adressestructure',
'emailstructure'
);
COMMIT;
......@@ -666,7 +666,6 @@ class FichesController extends AppController
'form_id',
'norme_id',
'coresponsable',
'coresponsableid',
'soustraitance',
'soustraitantid',
'obligation_pia',
......@@ -698,6 +697,9 @@ class FichesController extends AppController
]
]);
$responsables = $this->_responsables();
$this->set(compact('responsables'));
if ($formulaireOLD['Formulaire']['oldformulaire'] === true) {
// Reprise des données de la version v1.1.0 pour la coresponsabilité
$responsables = $this->_responsables();
......
......@@ -40,12 +40,12 @@ class Coresponsable extends AppModel {
'integer'
],
'formatSuffix' => '/_id$/',
'formatStripNotAlnum' => '/^(telephoneresponsable|telephonestructure|faxstructure|siretstructure)$/'
'formatStripNotAlnum' => '/^(telephonecoresponsable|telephonestructure|faxstructure|siretstructure)$/'
]
],
'LettercaseFormattable' => [
'upper_noaccents' => ['nomresponsable'],
'title' => ['prenomresponsable']
'upper_noaccents' => ['nomcoresponsable'],
'title' => ['prenomcoresponsable']
]
];
......@@ -72,13 +72,29 @@ class Coresponsable extends AppModel {
'message' => 'validation.numeroSIRETUniquementComposeChiffre'
],
],
'emailresponsable' => [
'emailcoresponsable' => [
[
'rule' => ['custom', REGEXP_EMAIL_FR],
'message' => 'validation.adresseMailNonValide'
]
],
];
/**
* belongsTo associations
*
* @var array
*
* @access public
* @created 18/06/2015
* @version V0.9.0
*/
public $belongsTo = [
'Fiche' => [
'className' => 'Fiche',
'foreignKey' => 'fiche_id'
]
];
/**
* hasMany associations
......@@ -89,20 +105,20 @@ class Coresponsable extends AppModel {
* @created 11/04/2018
* @version v1.0.0
*/
public $hasAndBelongsToMany = [
'Organisation' => [
'className' => 'Organisation',
'joinTable' => 'responsables_organisations',
'foreignKey' => 'responsable_id',
'associationForeignKey' => 'organisation_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'with' => 'ResponsableOrganisation'
]
];
// public $hasAndBelongsToMany = [
// 'Organisation' => [
// 'className' => 'Organisation',
// 'joinTable' => 'responsables_organisations',
// 'foreignKey' => 'responsable_id',
// 'associationForeignKey' => 'organisation_id',
// 'unique' => true,
// 'conditions' => '',
// 'fields' => '',
// 'order' => '',
// 'limit' => '',
// 'offset' => '',
// 'finderQuery' => '',
// 'with' => 'ResponsableOrganisation'
// ]
// ];
}
......@@ -457,7 +457,12 @@ class Fiche extends AppModel {
'className' => 'Fichier',
'foreignKey' => 'fiche_id',
'dependent' => true
]
],
'Coresponsable' => [
'className' => 'Coresponsable',
'foreignKey' => 'fiche_id',
'dependant' => true
],
];
/**
......
......@@ -480,6 +480,9 @@ class WebdpoFiche extends AppModel {
$Fiche->create($data['Fiche']);
$success = false !== $Fiche->save(null, ['atomic' => false]) && $success;
// Co-responsable
$success = false !== $this->coresponsableSave($Fiche->id, $data['Coresponsable'], $data['Fiche']['coresponsable']) && $success;
$newDataChamps = $this->checkDataConditons($data, $champs);
$data = Hash::extract($newDataChamps, 'data');
$champs = Hash::extract($newDataChamps, 'champs');
......@@ -645,27 +648,6 @@ class WebdpoFiche extends AppModel {
} else {
$data[$this->alias]['soustraitant'] = 'Oui';
}
if ($data['Fiche']['coresponsable'] == true) {
$data[$this->alias]['coresponsable'] = 'Oui';
} else {
$data[$this->alias]['coresponsable'] = 'Non';
unset(
$data[$this->alias]['nomcoresponsable'],
$data[$this->alias]['prenomcoresponsable'],
$data[$this->alias]['fonctioncoresponsable'],
$data[$this->alias]['emailcoresponsable'],
$data[$this->alias]['telephonecoresponsable'],
$data[$this->alias]['raisonsocialestructure'],
$data[$this->alias]['siretstructure'],
$data[$this->alias]['apestructure'],
$data[$this->alias]['telephonestructure'],
$data[$this->alias]['faxstructure'],
$data[$this->alias]['adressestructure'],
$data[$this->alias]['emailstructure']
);
}
} else {
// Suppression de la valeur de décrivant la prise de décision automatique si cela n'a pas été indiquer à Oui
if (isset($data[$this->alias]['decisionAutomatisee']) === false) {
......@@ -863,6 +845,48 @@ class WebdpoFiche extends AppModel {
return ($newDataChamps);
}
private function coresponsableSave ($fiche_id, $dataCoresponsable, $useCoresponsable)
{
$success = true;
if (empty($fiche_id)) {
$success = false;
}
if ($useCoresponsable == true && $success === true) {
$Responsable = ClassRegistry::init('Responsable');
$Coresponsable = ClassRegistry::init('Coresponsable');
foreach ($dataCoresponsable['coresponsables'] as $coresponsable_id) {
$responsable = $Responsable->find('first', [
'conditions' => [
'id' => $coresponsable_id
]
]);
$Coresponsable->create([
'fiche_id' => $fiche_id,
'responsable_id' => $responsable['Responsable']['id'],
'nomcoresponsable' => $responsable['Responsable']['nomresponsable'],
'prenomcoresponsable' => $responsable['Responsable']['prenomresponsable'],
'fonctioncoresponsable' => $responsable['Responsable']['fonctionresponsable'],
'emailcoresponsable' => $responsable['Responsable']['emailresponsable'],
'telephonecoresponsable' => $responsable['Responsable']['telephoneresponsable'],
'raisonsocialestructure' => $responsable['Responsable']['raisonsocialestructure'],
'siretstructure' => $responsable['Responsable']['siretstructure'],
'apestructure' => $responsable['Responsable']['apestructure'],
'telephonestructure' => $responsable['Responsable']['telephonestructure'],
'faxstructure' => $responsable['Responsable']['faxstructure'],
'adressestructure' => $responsable['Responsable']['adressestructure'],
'emailstructure' => $responsable['Responsable']['emailstructure']
]);
$success = false !== $Coresponsable->save(null, ['atomic' => false]) && $success;
}
}
return $success;
}
public function beforeValidate($options = array()) {
// $this->data = $this->cleanupData($this->data);
return parent::beforeValidate($options);
......
......@@ -19,7 +19,7 @@
<div class="row">
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('coresponsables', [
echo $this->WebcilForm->input('Coresponsable.coresponsables', [
'id' => 'coresponsables',
'label' => [
'text' => __d('fiche', 'fiche.champCoresponsableid')
......@@ -42,8 +42,6 @@
</div>
<!-- Fin onglet Co-responsable -->
<script type="text/javascript">
$(document).ready(function () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment