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

Modification : du typage des annexes

parent 67cf2512
......@@ -211,5 +211,6 @@ INSERT INTO typages_organisations (typage_id, organisation_id)
FROM typages
LEFT OUTER JOIN organisations ON (1 = 1);
ALTER TABLE fichiers ADD COLUMN typage_id INTEGER DEFAULT NULL REFERENCES typages(id) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
......@@ -54,6 +54,8 @@ class FichesController extends AppController
'Service',
'Soustraitant',
'SoustraitantOrganisation',
'Typage',
'TypageOrganisation',
'TraitementRegistre',
'User',
'Valeur',
......@@ -102,6 +104,8 @@ class FichesController extends AppController
$accepted = ['application/pdf', 'application/vnd.oasis.opendocument.text'];
}
$typages = $this->_typages();
$json = [];
foreach ($this->request->params['form']['fichiers']['tmp_name'] as $key => $tmpFile) {
$dir = CHEMIN_PIECE_JOINT_TMP . $this->Session->read('Auth.User.id') . DS . $this->Session->read('Auth.User.uuid');
......@@ -118,9 +122,20 @@ class FichesController extends AppController
if (in_array($mime, $accepted) === true) {
move_uploaded_file($tmpFile, $path);
$selectType = '';
if (!empty($typages)) {
$selectType = '<div class="form-group"><label for="typage_2" class="col-md-4 control-label"></label><div class="col-md-8"><select name="data[Fichier][typage_2]" id="typage_2" class="typage form-control">'
. '<option value="">Séléctionnez un type pour le fichier</option>';
foreach ($typages as $key => $typage) {
$selectType = $selectType . '<option value="' . $key . '">' . $typage . '</option>';
}
$selectType = $selectType . '</select></div></div>';
}
$json[] = [
'filename' => $filename,
'path' => $path
'path' => $path,
'optionType' => $selectType,
];
}
}
......@@ -320,7 +335,8 @@ class FichesController extends AppController
$last,
$useAllExtensionFiles['Formulaire']['useallextensionfiles'],
$this->Session->read('Auth.User.uuid'),
$this->Session->read('Auth.User.id')
$this->Session->read('Auth.User.id'),
$data['Fichier']
);
}
}
......@@ -385,7 +401,9 @@ class FichesController extends AppController
// Récupère en BDD les normes. Renvoie les normes et les descriptions
$this->getNormes();
$this->set(compact('formulaire_id', 'formulaireOLD'));
$typages = $this->_typages();
$this->set(compact('formulaire_id', 'formulaireOLD', 'typages'));
}
/**
......@@ -704,7 +722,9 @@ class FichesController extends AppController
$this->request->data['Fiche']['realisation_pia'] = $fiche['Fiche']['realisation_pia'];
$this->request->data['Fiche']['depot_pia'] = $fiche['Fiche']['depot_pia'];
$this->set(compact('formulaireOLD'));
$typages = $this->_typages();
$this->set(compact('formulaireOLD', 'typages'));
$this->set('formulaire_id', $fiche['Fiche']['form_id']);
$this->view = 'add';
......@@ -2068,4 +2088,47 @@ class FichesController extends AppController
return null;
}
/**
* Récupere tous les types d'annexe associé à l'entité
*
* @return mixed
*
* @access protected
*
* @author Théo GUILLON <theo.guillon@libriciel.coop>
* @created 22/04/2020
* @version V1.2.0
*/
protected function _typages()
{
$query = [
'conditions' => [],
'fields' => [
'id',
'libelle'
],
'order' => [
'Typage.libelle ASC'
]
];
$subQuery = [
'alias' => 'typages_organisations',
'fields' => [
'typages_organisations.typage_id'
],
'conditions' => [
'typages_organisations.typage_id = Typage.id',
'typages_organisations.organisation_id' => $this->Session->read('Organisation.id')
]
];
$sql = $this->TypageOrganisation->sql($subQuery);
$query['conditions'][] = "Typage.id IN ( {$sql} )";
$typages = $this->Typage->find('list', $query);
return $typages;
}
}
......@@ -64,8 +64,6 @@ class TypagesController extends AppController {
$this->redirect(['action' => 'index']);
}
debug($this->request->data);
$success = true;
$this->TypageOrganisation->begin();
......
......@@ -526,4 +526,9 @@ msgstr "Avez-vous réalisé l'analyse d'impact (AIPD) ?"
msgid "fiche.champDepotPia"
msgstr "Avez-vous déposer dans l'onglet annexe l'analyse d'impact (AIPD) ?"
#######################
msgid "fiche.emptySelectTypeFile"
msgstr "Séléctionnez un type pour le fichier"
###############################################################################
......@@ -144,7 +144,7 @@ class Fichier extends AppModel {
* transaction (par défaut: false) ?
* @return boolean
*/
public function transfereSave($idFiche, $useAllExtensionFiles, $uuidDossier, $idUser, $transaction = false) {
public function transfereSave($idFiche, $useAllExtensionFiles, $uuidDossier, $idUser, $typages = [], $transaction = false) {
if (!empty($uuidDossier)){
$files = array_diff(scandir(CHEMIN_PIECE_JOINT_TMP . $idUser . DS . $uuidDossier), array('..', '.'));
......@@ -175,12 +175,21 @@ class Fichier extends AppModel {
$newPathFile = CHEMIN_PIECE_JOINT . $newNameFile;
$success = $success && rename($pathFileTMP, $newPathFile);
$typeFile = null;
if (!empty($typages)) {
$keyFind = 'typage_'.$key;
if (array_key_exists($keyFind, $typages)) {
$typeFile = $typages[$keyFind];
}
}
if ($success) {
$this->create([
'nom' => $file,
'url' => $newNameFile,
'fiche_id' => $idFiche
'fiche_id' => $idFiche,
'typage_id' => $typeFile,
]);
$success = $success && $this->save(null, ['atomic' => false]);
}
......
......@@ -55,14 +55,31 @@
?>
<tr id="rowFiche<?php echo $key; ?>">
<td class="col-md-1">
<td class="col-md-2">
<i class="fa fa-file-text-o fa-lg"><!----></i>
</td>
<td class="col-md-9 tdleft">
<td class="col-md-4 tdleft">
<?php echo $file ?>
</td>
<td class="col-md-4 tdleft">
<?php
if (!empty($typages)) {
echo $this->WebcilForm->input('Fichier.typage_' . $key, [
'id' => 'typage_' . $key,
'label' => [
'text' => ''
],
'options' => $typages,
'empty' => __d('fiche', 'fiche.emptySelectTypeFile'),
'required' => false,
'placeholder' => false
]);
}
?>
</td>
<td class="col-md-2">
<button type="button" class="btn btn-warning"
onclick="deleteFile('<?php echo $file ?>','<?php echo $key ?>')">
......@@ -107,12 +124,22 @@
foreach ($filesSave as $val) {
?>
<tr id="rowFichier<?php echo $val['Fichier']['id']; ?>">
<td class="col-md-1">
<td class="col-md-2">
<i class="fa fa-file-text-o fa-lg"><!----></i>
</td>
<td class="col-md-9 tdleft">
<td class="col-md-4 tdleft">
<?php echo $val['Fichier']['nom']; ?>
</td>
<td class="col-md-4 tdleft">
<?php
if (!empty($typages)) {
echo "Type d'annexe : " . $typages[$val['Fichier']['typage_id']];
}
?>
</td>
<td class="col-md-2 boutonsFile boutonsFile"<?php echo $val['Fichier']['id']; ?>>
<?php
echo $this->Html->link('<span class="fa fa-download fa-lg"><!----></span>', [
......@@ -131,7 +158,7 @@
<button type="button"
class="btn btn-default-danger btn-sm my-tooltip left5 btn-del-file"
onclick="deleteFileSave('<?php echo $val['Fichier']['id'] ?>','<?php echo $val['Fichier']['url'] ?>')">
<i class="fa fa-trash fa-lg"><!----></i>
<i class="fa fa-trash fa-lg"></i>
</button>
<?php
}
......@@ -208,8 +235,9 @@
var content = JSON.parse(data);
for (var key in content) {
var tr = $('<tr id="rowFiche' + key + '"><\/tr>')
.append('<td class="col-md-1"><i class="fa fa-file-text-o fa-lg"><!----><\/i><\/td>')
.append('<td class="col-md-9 tdleft">' + content[key].filename + '<\/td>')
.append('<td class="col-md-2"><i class="fa fa-file-text-o fa-lg"><!----><\/i><\/td>')
.append('<td class="col-md-4 tdleft">' + content[key].filename + '<\/td>')
.append('<td class="col-md-4 tdleft">'+ content[key].optionType +'<\/td>')
.append('<td class="col-md-2"><button type="button" class="btn btn-warning" onclick=\"deleteFile(\'' + content[key].filename + '\',\'' + key + '\')\"><i class="fa fa-times-circle"><!----><\/i> Annuler<\/button><\/td>')
$('#render').find('tbody').append(tr);
}
......@@ -225,6 +253,10 @@
}
});
});
$('.typage').on('change', function () {
console.log($(this));
});
});
function deleteFile(file, key) {
......
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