Skip to content

Commit d43d9fa

Browse files
feat: gestione key in filelist upload
1 parent 2067bfa commit d43d9fa

6 files changed

Lines changed: 41 additions & 23 deletions

File tree

actions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
'id_module' => $id_module,
149149
'id_plugin' => $id_plugin,
150150
'id_record' => $id_record,
151+
'key' => filter('key') ?: null,
151152
]);
152153

153154
// Creazione file fisico
@@ -164,6 +165,7 @@
164165
'id_module' => $id_module,
165166
'id_plugin' => $id_plugin,
166167
'id_record' => $id_record,
168+
'key' => filter('key') ?: null,
167169
]);
168170

169171
if (!empty($name)) {

ajax.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
$category = get('id_category') ? Categoria::find(get('id_category'))->name : null;
7373
$upload_only = get('upload_only') === 'true' ? 'true' : 'false';
7474
$disable_edit = get('disable_edit') === 'true' ? 'true' : 'false';
75-
echo '{( "name": "filelist_and_upload", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "id_plugin": "'.$id_plugin.'", "category": "'.$category.'", "upload_only": "'.$upload_only.'", "disable_edit": "'.$disable_edit.'" )}';
75+
$key = get('key');
76+
echo '{( "name": "filelist_and_upload", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "id_plugin": "'.$id_plugin.'", "category": "'.$category.'", "upload_only": "'.$upload_only.'", "disable_edit": "'.$disable_edit.'", "key": "'.$key.'" )}';
7677

7778
break;
7879

assets/src/js/functions/allegati.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function initGestioneAllegati(gestione) {
4848
id_module: gestione.data('id_module'),
4949
id_plugin: gestione.data('id_plugin'),
5050
id_record: gestione.data('id_record'),
51-
id_category: gestione.data('id_category')
51+
id_category: gestione.data('id_category'),
52+
key: gestione.data('key')
5253
}).toString();
5354

5455
let dragdrop = new Dropzone(dropzone_id, {
@@ -145,7 +146,8 @@ function ricaricaAllegati(gestione) {
145146
id_record: gestione.data('id_record'),
146147
id_category: gestione.data('id_category'),
147148
upload_only: gestione.data('upload_only') === true || gestione.data('upload_only') === 'true' ? 'true' : 'false',
148-
disable_edit: gestione.data('disable_edit') === true || gestione.data('disable_edit') === 'true' ? 'true' : 'false'
149+
disable_edit: gestione.data('disable_edit') === true || gestione.data('disable_edit') === 'true' ? 'true' : 'false',
150+
key: gestione.data('key')
149151
}).toString();
150152

151153
$(id).load(globals.rootdir + "/ajax.php?" + params, function () {
@@ -256,6 +258,7 @@ function rimuoviAllegato(button) {
256258
id_record: gestione.data('id_record'),
257259
id_allegato: allegato.id,
258260
filename: allegato.filename,
261+
key: gestione.data('key')
259262
}).toString();
260263

261264
// Richiesta AJAX

src/HTMLBuilder/Manager/FileManager.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FileManager implements ManagerInterface
3333
{
3434
/**
3535
* Gestione "filelist_and_upload".
36-
* Esempio: {( "name": "filelist_and_upload", "id_module": "2", "id_record": "1", "readonly": "false", "category": "", "upload_only": "false", "disable_edit": "false" )}.
36+
* Esempio: {( "name": "filelist_and_upload", "id_module": "2", "id_record": "1", "readonly": "false", "category": "", "upload_only": "false", "disable_edit": "false", "key": "table:1" )}.
3737
*
3838
* @param array $options
3939
*
@@ -52,11 +52,12 @@ public function manage($options)
5252
$options['disable_edit'] = ($options['disable_edit'] === true || $options['disable_edit'] === 'true' || $options['disable_edit'] === '1') ? true : false;
5353

5454
$options['id_plugin'] = !empty($options['id_plugin']) ? $options['id_plugin'] : null;
55+
$options['key'] = !empty($options['key']) ? $options['key'] : null;
5556

5657
$id_categoria = $options['category'] ? Categoria::where('name', $options['category'])->first()->id : null;
5758

5859
// ID del form
59-
$attachment_id = 'attachments_'.$options['id_module'].'_'.$options['id_plugin'].($id_categoria ? '_'.$id_categoria : '');
60+
$attachment_id = 'attachments_'.$options['id_module'].'_'.$options['id_plugin'].($id_categoria ? '_'.$id_categoria : '').($options['key'] ? '_'.md5($options['key']) : '');
6061

6162
if (ini_get('upload_max_filesize') < ini_get('post_max_size')) {
6263
$upload_max_filesize = ini_get('upload_max_filesize');
@@ -72,7 +73,7 @@ public function manage($options)
7273

7374
// Codice HTML
7475
$result = '
75-
<div class="gestione-allegati" id="'.$attachment_id.'" data-id_module="'.$options['id_module'].'" data-id_plugin="'.$options['id_plugin'].'" data-id_record="'.$options['id_record'].'" data-max_filesize="'.$upload_max_filesize.'" data-id_category="'.$id_categoria.'" data-upload_only="'.($options['upload_only'] ? 'true' : 'false').'" data-disable_edit="'.($options['disable_edit'] ? 'true' : 'false').'">';
76+
<div class="gestione-allegati" id="'.$attachment_id.'" data-id_module="'.$options['id_module'].'" data-id_plugin="'.$options['id_plugin'].'" data-id_record="'.$options['id_record'].'" data-max_filesize="'.$upload_max_filesize.'" data-id_category="'.$id_categoria.'" data-upload_only="'.($options['upload_only'] ? 'true' : 'false').'" data-disable_edit="'.($options['disable_edit'] ? 'true' : 'false').'" data-key="'.$options['key'].'" >';
7677

7778
if (!empty($options['showcard'])) {
7879
$result .= '
@@ -87,7 +88,14 @@ public function manage($options)
8788

8889
$count = 0;
8990

90-
$where = '`id_module` '.(!empty($options['id_module']) && empty($options['id_plugin']) ? '= '.prepare($options['id_module']) : 'IS NULL').' AND `id_plugin` '.(!empty($options['id_plugin']) ? '= '.prepare($options['id_plugin']) : 'IS NULL').' AND `key` IS NULL';
91+
$where = '`id_module` '.(!empty($options['id_module']) && empty($options['id_plugin']) ? '= '.prepare($options['id_module']) : 'IS NULL').' AND `id_plugin` '.(!empty($options['id_plugin']) ? '= '.prepare($options['id_plugin']) : 'IS NULL');
92+
93+
// Filtrare per key se specificata
94+
if (!empty($options['key'])) {
95+
$where .= ' AND `key` = '.prepare($options['key']);
96+
} else {
97+
$where .= ' AND (`key` IS NULL OR `key` = "")';
98+
}
9199

92100
// Limitare alle categorie specificate
93101
if (!empty($id_categoria)) {
@@ -281,39 +289,39 @@ public function manage($options)
281289
// Estraggo le righe spuntate
282290
function getSelectFiles() {
283291
let data=new Array();
284-
$(".files").find(".check_files:checked").each(function (){
292+
$("#'.$attachment_id.' .files").find(".check_files:checked").each(function (){
285293
data.push($(this).closest("tr").data("id"));
286294
});
287295
288296
return data;
289297
}
290298
291-
$(".check_files").on("change", function() {
299+
$("#'.$attachment_id.' .check_files").on("change", function() {
292300
let checked = 0;
293-
$(".check_files").each(function() {
301+
$("#'.$attachment_id.' .check_files").each(function() {
294302
if ($(this).is(":checked")) {
295303
checked = 1;
296304
}
297305
});
298306
299307
if (checked) {
300-
$("#zip_files").removeClass("disabled");
301-
$("#modifica_files").removeClass("disabled");
308+
$("#'.$attachment_id.' #zip_files").removeClass("disabled");
309+
$("#'.$attachment_id.' #modifica_files").removeClass("disabled");
302310
} else {
303-
$("#zip_files").addClass("disabled");
304-
$("#modifica_files").addClass("disabled");
311+
$("#'.$attachment_id.' #zip_files").addClass("disabled");
312+
$("#'.$attachment_id.' #modifica_files").addClass("disabled");
305313
}
306314
});
307315
308-
$("#check_all_files").click(function(){
316+
$("#'.$attachment_id.' #check_all_files").click(function(){
309317
if( $(this).is(":checked") ){
310-
$(".check_files").each(function(){
318+
$("#'.$attachment_id.' .check_files").each(function(){
311319
if( !$(this).is(":checked") ){
312320
$(this).trigger("click");
313321
}
314322
});
315323
}else{
316-
$(".check_files").each(function(){
324+
$("#'.$attachment_id.' .check_files").each(function(){
317325
if( $(this).is(":checked") ){
318326
$(this).trigger("click");
319327
}

src/Models/Upload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static function build($source = null, $data = null, $name = null, $catego
112112
$model->id_module = !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null;
113113
$model->id_plugin = !empty($data['id_plugin']) ? $data['id_plugin'] : null;
114114
$model->id_record = !empty($data['id_record']) ? $data['id_record'] : null;
115-
$model->key = isset($data['key']) ? $data['key'] : null;
115+
$model->key = !empty($data['key']) ? $data['key'] : null;
116116

117117
// Caricamento file con interfaccia di upload
118118

src/Uploads.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public static function get($data)
4040
{
4141
$database = database();
4242

43-
$uploads = $database->select('zz_files', '*', [], [
43+
$where = [
4444
'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null,
4545
'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null,
4646
'id_record' => $data['id_record'],
47-
'key' => NULL,
48-
]);
47+
'key' => $data['key'] ?: null,
48+
];
49+
50+
$uploads = $database->select('zz_files', '*', [], $where);
4951

5052
return $uploads;
5153
}
@@ -102,13 +104,15 @@ public static function delete($filename, $data)
102104
if (!empty($filename)) {
103105
$database = database();
104106

105-
$file = $database->selectOne('zz_files', '*', [
107+
$where = [
106108
'filename' => $filename,
107109
'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null,
108110
'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null,
109111
'id_record' => $data['id_record'],
110-
]);
112+
'key' => $data['key'] ?: null,
113+
];
111114

115+
$file = $database->selectOne('zz_files', '*', $where);
112116
if (!empty($file)) {
113117
$name = $file['name'];
114118

0 commit comments

Comments
 (0)