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

Ajout : sauvegarde en BDD des champs suplémentaire du formulaire pour la coresponsabilité

Ajout : reprise des données de la bdd
parent 98759050
......@@ -258,8 +258,6 @@ class FichesController extends AppController
$this->redirect($this->Referers->get());
}
debug($this->request->data);die;
$success = true;
$this->Fiche->begin();
......@@ -632,6 +630,8 @@ class FichesController extends AppController
$this->redirect($this->Referers->get());
}
debug($this->request->data);die;
$success = true;
$this->Fiche->begin();
......
......@@ -360,6 +360,7 @@ class WebdpoFiche extends AppModel {
// Co-responsable
$success = false !== $this->coresponsableSave($Fiche->id, $data['Coresponsable'], $data['Fiche']['coresponsable']) && $success;
$data = $this->cleanAndCheckDataCoresponsable($data, $champs);
// Soustraitance
$success = false !== $this->soustraitanceSave($Fiche->id, $data['Soustraitance'], $data['Fiche']['soustraitance']) && $success;
......@@ -512,6 +513,8 @@ class WebdpoFiche extends AppModel {
protected function cleanupData(array $data, array $formulaireChamps, bool $formulaireOLD, array $fieldsToDelete)
{
debug($data);
// @TODO faire cela au moment de la génération
// Ajout textuel de la coresponsabilité
if ($data['Fiche']['coresponsable'] == true) {
......@@ -808,6 +811,45 @@ class WebdpoFiche extends AppModel {
return $success;
}
private function cleanAndCheckDataCoresponsable($data, $champs)
{
if ($data['Fiche']['coresponsable'] == false) {
if (isset($data[$this->alias]['coresponsabilitefields'])) {
unset($data[$this->alias]['coresponsabilitefields']);
}
return $data;
}
$arrayCoresponsableFields = [];
foreach ($champs as $champ) {
if ($champ['Champ']['champ_coresponsable'] === true && $champ['Champ']['champ_soustraitant'] === false) {
$arrayCoresponsableFields[] = json_decode($champ['Champ']['details'], true);
}
}
$success = true;
// On vérifie que les champs suplémentaite du formualaire ne soient pas obligatoire
foreach ($data[$this->alias]['coresponsabilitefields'] as $responsable_id => $coresponsabilitefield) {
foreach ($arrayCoresponsableFields as $arrayCoresponsableField) {
if (empty($coresponsabilitefield[$arrayCoresponsableField['name']]) && $arrayCoresponsableField['obligatoire'] === true) {
//@TODO ERREUR champ obligatoire
// $this->alias->validationErrors['coresponsabilitefields'][$responsable_id][$arrayCoresponsableField['name']] = 'Champ obligatoire';
$success = false;
}
}
}
if ($success === false) {
return $data;
}
$data[$this->alias]['coresponsabilitefields'] = json_encode($data[$this->alias]['coresponsabilitefields'], true);
return $data;
}
private function soustraitanceSave ($fiche_id, $dataSoustraitance, $useSoustraitance)
{
$success = true;
......
......@@ -50,70 +50,6 @@
'value' => $coresponsable['Coresponsable']['id'],
'id' => false
]);
?>
<div id="card_coresponsable_<?php echo $coresponsable['Coresponsable']['responsable_id'];?>" class="row">
<div class="col-md-12">
<div class="panel panel-default ">
<div class="panel-body">
<div class="col-md-6">
<h4>
<?php echo $coresponsable['Coresponsable']['raisonsocialestructure'];?>
</h4>
<p>
<u>N° SIRET :</u>
<?php echo $coresponsable['Coresponsable']['siretstructure'];?>
</p>
<p>
<u>Code APE :</u>
<?php echo $coresponsable['Coresponsable']['apestructure'];?>
</p>
<p>
<u>Adresse :</u>
<?php echo $coresponsable['Coresponsable']['adressestructure'];?>
</p>
<?php
if (!empty($coresponsable['Coresponsable']['telephonestructure'])) {
?>
<p>
<u>Téléphone :</u>
<?php echo $coresponsable['Coresponsable']['telephonestructure'];?>
</p>
<?php
}
if (!empty($coresponsable['Coresponsable']['faxstructure'])) {
?>
<p>
<u>Fax :</u>
<?php echo $coresponsable['Coresponsable']['faxstructure'];?>
</p>
<?php
}
?>
</div>
<div class="col-md-6">
<h4>
<?php echo $coresponsable['Coresponsable']['prenomcoresponsable'] . ' ' . $coresponsable['Coresponsable']['nomcoresponsable'];?>
</h4>
<p>
<u>Fonction :</u>
<?php echo $coresponsable['Coresponsable']['fonctioncoresponsable'];?>
</p>
<p>
<u>Téléphone :</u>
<?php echo $coresponsable['Coresponsable']['telephonecoresponsable'];?>
</p>
<p>
<u>E-mail :</u>
<?php echo $coresponsable['Coresponsable']['emailcoresponsable'];?>
</p>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
......@@ -147,88 +83,15 @@
?>
let templateFieldsCoresponsable = <?php echo json_encode($templateFieldsCoresponsable);?>;
let coresponsablesRequestData = <?php echo json_encode($this->request->data['Coresponsable']['coresponsables']);?>;
$(coresponsablesRequestData).each(function (key, val) {
createCard(templateFieldsCoresponsable, infoCoresponsables, val);
});
$(eventSelect).on("select2:select", function (e) {
let idSelect = e.params.data.id;
let coresponsable = infoCoresponsables[idSelect];
let colLeft = '';
let fields = templateFieldsCoresponsable.replace(/data\[WebdpoFiche\]/g, 'data[WebdpoFiche]['+idSelect+']');
fields = fields.replace(/(for|id)="(<?php echo implode('|', $arrayFieldsId);?>)"/g, '$1="cr_'+idSelect+'_$2"');
let formCoreponsableFields = '';
if (fields) {
formCoreponsableFields = '<div id="form-container-coresponsable">';
formCoreponsableFields = formCoreponsableFields + fields;
formCoreponsableFields = formCoreponsableFields + '</div>';
}
if (coresponsable['adressestructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>Adresse :</u>' +
coresponsable['adressestructure'] +
'</p>';
}
if (coresponsable['telephonestructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>Téléphone :</u>' +
coresponsable['telephonestructure'] +
'</p>';
}
if (coresponsable['faxstructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>Fax :</u>' +
coresponsable['faxstructure'] +
'</p>';
}
if (coresponsable['emailstructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>E-mail :</u>' +
coresponsable['emailstructure'] +
'</p>';
}
let nomComplet = coresponsable['prenomresponsable'] + ' ' + coresponsable['nomresponsable'];
$('#coresponsableCards').append('<div id="card_coresponsable_'+idSelect+'" class="row">' +
'<div class="col-md-12">' +
' <div class="panel panel-default ">' +
' <div class="panel-body">' +
' <div class="col-md-6">' +
' <h4>' + coresponsable['raisonsocialestructure'] + '</h4>' +
' <p>' +
' <u>N° SIRET :</u>' +
coresponsable['siretstructure'] +
' </p>' +
' <p>' +
' <u>Code APE :</u>' +
coresponsable['apestructure'] +
' </p>' +
colLeft +
' </div>' +
' <div class="col-md-6">' +
' <h4>' + nomComplet + '</h4>' +
' <p>' +
' <u>Fonction :</u>' +
coresponsable['fonctionresponsable'] +
' </p>' +
' <p>' +
' <u>Téléphone :</u>' +
coresponsable['telephoneresponsable'] +
' </p>' +
' <p>' +
' <u>E-mail :</u>' +
coresponsable['emailresponsable'] +
' </p>' +
' </div>' +
formCoreponsableFields +
' </div>' +
' </div>' +
'</div>' +
'</div>');
createCard(templateFieldsCoresponsable, infoCoresponsables, idSelect);
});
$(eventSelect).on("select2:unselect", function (e) {
......@@ -243,4 +106,86 @@
});
function createCard(templateFieldsCoresponsable, infoCoresponsables, idSelect) {
let coresponsable = infoCoresponsables[idSelect];
let colLeft = '';
let fields = templateFieldsCoresponsable.replace(/data\[WebdpoFiche\]/g, 'data[WebdpoFiche][coresponsabilitefields]['+idSelect+']');
fields = fields.replace(/(for|id)="(<?php echo implode('|', $arrayFieldsId);?>)"/g, '$1="cr_'+idSelect+'_$2"');
let formCoreponsableFields = '';
if (fields) {
formCoreponsableFields = '<div id="form-container-coresponsable">';
formCoreponsableFields = formCoreponsableFields + fields;
formCoreponsableFields = formCoreponsableFields + '</div>';
}
if (coresponsable['adressestructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>Adresse :</u>' +
coresponsable['adressestructure'] +
'</p>';
}
if (coresponsable['telephonestructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>Téléphone :</u>' +
coresponsable['telephonestructure'] +
'</p>';
}
if (coresponsable['faxstructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>Fax :</u>' +
coresponsable['faxstructure'] +
'</p>';
}
if (coresponsable['emailstructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>E-mail :</u>' +
coresponsable['emailstructure'] +
'</p>';
}
let nomComplet = coresponsable['prenomresponsable'] + ' ' + coresponsable['nomresponsable'];
$('#coresponsableCards').append('<div id="card_coresponsable_'+idSelect+'" class="row">' +
'<div class="col-md-12">' +
' <div class="panel panel-default ">' +
' <div class="panel-body">' +
' <div class="col-md-6">' +
' <h4>' + coresponsable['raisonsocialestructure'] + '</h4>' +
' <p>' +
' <u>N° SIRET :</u>' +
coresponsable['siretstructure'] +
' </p>' +
' <p>' +
' <u>Code APE :</u>' +
coresponsable['apestructure'] +
' </p>' +
colLeft +
' </div>' +
' <div class="col-md-6">' +
' <h4>' + nomComplet + '</h4>' +
' <p>' +
' <u>Fonction :</u>' +
coresponsable['fonctionresponsable'] +
' </p>' +
' <p>' +
' <u>Téléphone :</u>' +
coresponsable['telephoneresponsable'] +
' </p>' +
' <p>' +
' <u>E-mail :</u>' +
coresponsable['emailresponsable'] +
' </p>' +
' </div>' +
formCoreponsableFields +
' </div>' +
' </div>' +
'</div>' +
'</div>');
}
</script>
\ No newline at end of file
<?php
echo $this->Html->script('jquery-mask-plugin/dist/jquery.mask.min.js');
debug($this->request->data);
if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErrors['WebdpoFiche'])) {
?>
<div class="alert alert-danger" role="alert">
......
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