Miglioramenti distribuiti

This commit is contained in:
Thomas Zilio 2018-09-04 10:03:02 +02:00
parent 377998d7ce
commit 9509355260
6 changed files with 81 additions and 15 deletions

View File

@ -69,6 +69,34 @@ if (!function_exists('str_contains')) {
}
}
if (!function_exists('str_to_lower')) {
/**
* Converts a string in the lower-case version.
*
* @param string $string
*
* @return bool
*/
function str_to_lower($string)
{
return S::create($string)->toLowerCase();
}
}
if (!function_exists('str_to_upper')) {
/**
* Converts a string in the upper-case version.
*
* @param string $string
*
* @return bool
*/
function str_to_upper($string)
{
return S::create($string)->toUpperCase();
}
}
if (!function_exists('random_string')) {
/**
* Generates a string of random characters.

View File

@ -123,8 +123,6 @@ return [
'names' => [
'Unità di misura',
'Unità misura',
'unità misura',
'unità di misura',
'Unit` di misura',
'um',
],
@ -132,18 +130,10 @@ return [
[
'field' => 'prezzo_acquisto',
'label' => 'Prezzo acquisto',
'names' => [
'Prezzo Acquisto',
'prezzo acquisto',
],
],
[
'field' => 'prezzo_vendita',
'label' => 'Prezzo vendita',
'names' => [
'Prezzo Vendita',
'prezzo vendita',
],
],
[
'field' => 'peso_lordo',
@ -158,7 +148,7 @@ return [
'label' => 'Volume (M3)',
'names' => [
'Volume (M3)',
'volume',
'Volume',
],
],
[
@ -168,7 +158,6 @@ return [
'Categoria',
'id_categoria',
'idcategoria',
'categoria',
],
],
[

View File

@ -8,7 +8,7 @@ include_once __DIR__.'/../../core.php';
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="id_record" value="<?php echo $id_record; ?>">
<div class="row">
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "<?php echo tr('Modulo'); ?>", "name": "module_id", "values": "query=SELECT id, name as text FROM zz_modules WHERE enabled = 1", "value": "$id_module$" ]}
</div>
@ -45,6 +45,43 @@ include_once __DIR__.'/../../core.php';
</div>
</form>
<!-- Campi extra -->
<div class="box box-info">
<div class="box-header">
<h3 class="box-title"><?php echo tr('Istruzioni per il campo _FIELD_', [
'_FIELD_' => tr('Contenuto'),
]); ?></h3>
</div>
<div class="box-body">
<p><?php echo tr('Le seguenti sequenze di testo vengono sostituite nel seguente modo'); ?>:</p>
<ul>
<?php
$list = [
'name' => tr('Nome'),
'html_name' => tr('Nome HTML'),
];
foreach ($list as $key => $value) {
echo '
<li>'.tr('_TEXT_ con il valore del campo "_FIELD_"', [
'_TEXT_' => '<code>|'.$key.'|</code>',
'_FIELD_' => $value,
]).'</li>';
}
echo '
<li>'.tr('_TEXT_ con il valore impostato per il record', [
'_TEXT_' => '<code>|value</code>',
]).'</li>';
?>
</ul>
</div>
</div>
<hr>
<a class="btn btn-danger ask" data-backto="record-list">
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
</a>

View File

@ -20,6 +20,9 @@ switch (post('op')) {
'headers' => $first_row,
]);
// Gestione automatica dei valori convertiti
$csv = Filter::parse($csv);
// Interpretazione dei dati
$data = [];
foreach ($csv as $row) {

View File

@ -65,7 +65,7 @@ if (empty($id_record)) {
// Individuazione delle corrispondenze
$selected = null;
foreach ($fields as $key => $value) {
if (in_array($rows[0][$column], $value['names'])) {
if (in_array(str_to_lower($rows[0][$column]), $value['names'])) {
$first_row = 1;
$selected = $key;
break;

View File

@ -77,11 +77,20 @@ class Import
// Impostazione automatica dei nomi "ufficiali" dei campi
foreach ($fields as $key => $value) {
if (!isset($value['names'])) {
$fields[$key]['names'] = [
$names = [
$value['field'],
$value['label'],
];
} else {
$names = $value['names'];
}
// Impostazione dei nomi in minuscolo
foreach ($names as $k => $v) {
$names[$k] = str_to_lower($v);
}
$fields[$key]['names'] = $names;
}
return $fields;