Aggiunta immagine in import CSV articoli
This commit is contained in:
parent
9d5bc51326
commit
24fe32040e
|
@ -19,7 +19,10 @@
|
||||||
|
|
||||||
namespace Modules\Articoli\Import;
|
namespace Modules\Articoli\Import;
|
||||||
|
|
||||||
|
use Uploads;
|
||||||
|
use Modules;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Models\Upload;
|
||||||
use Importer\CSVImporter;
|
use Importer\CSVImporter;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
use Modules\Anagrafiche\Sede;
|
use Modules\Anagrafiche\Sede;
|
||||||
|
@ -43,6 +46,14 @@ class CSV extends CSVImporter
|
||||||
'label' => 'Codice',
|
'label' => 'Codice',
|
||||||
'primary_key' => true,
|
'primary_key' => true,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'field' => 'immagine',
|
||||||
|
'label' => 'Immagine',
|
||||||
|
'names' => [
|
||||||
|
'Immagine',
|
||||||
|
'Foto',
|
||||||
|
],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'field' => 'descrizione',
|
'field' => 'descrizione',
|
||||||
'label' => 'Descrizione',
|
'label' => 'Descrizione',
|
||||||
|
@ -210,6 +221,8 @@ class CSV extends CSVImporter
|
||||||
{
|
{
|
||||||
$database = database();
|
$database = database();
|
||||||
$primary_key = $this->getPrimaryKey();
|
$primary_key = $this->getPrimaryKey();
|
||||||
|
$url = $record['immagine'];
|
||||||
|
unset($record['immagine']);
|
||||||
|
|
||||||
// Fix per campi con contenuti derivati da query implicite
|
// Fix per campi con contenuti derivati da query implicite
|
||||||
if (!empty($record['id_fornitore'])) {
|
if (!empty($record['id_fornitore'])) {
|
||||||
|
@ -316,6 +329,34 @@ class CSV extends CSVImporter
|
||||||
$articolo->movimenta($qta_movimento, tr('Movimento da importazione'), new Carbon(), false, [
|
$articolo->movimenta($qta_movimento, tr('Movimento da importazione'), new Carbon(), false, [
|
||||||
'idsede' => $id_sede,
|
'idsede' => $id_sede,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
//Gestione immagine
|
||||||
|
if ( !empty($url) ) {
|
||||||
|
$file_content = file_get_contents($url);
|
||||||
|
|
||||||
|
if( !empty($file_content) ){
|
||||||
|
$name = "immagine_".$articolo->id.'.'.Upload::getExtensionFromMimeType($file_content);
|
||||||
|
|
||||||
|
$upload = Uploads::upload($file_content, [
|
||||||
|
'name' => 'Immagine',
|
||||||
|
'category' => 'Immagini',
|
||||||
|
'original_name' => $name,
|
||||||
|
'id_module' => Modules::get('Articoli')['id'],
|
||||||
|
'id_record' => $articolo->id,
|
||||||
|
], [
|
||||||
|
'thumbnails' => true,
|
||||||
|
]);
|
||||||
|
$filename = $upload->filename;
|
||||||
|
|
||||||
|
if (!empty($filename)) {
|
||||||
|
$database->update('mg_articoli', [
|
||||||
|
'immagine' => $filename,
|
||||||
|
], [
|
||||||
|
'id' => $articolo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getExample()
|
public static function getExample()
|
||||||
|
|
|
@ -38,6 +38,15 @@ class Upload extends Model
|
||||||
'htm' => 'text/html',
|
'htm' => 'text/html',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** @var array Elenco delle estensioni file per mime type */
|
||||||
|
protected static $extension_association = [
|
||||||
|
'image/gif' => 'gif',
|
||||||
|
'image/bmp' => 'bmp',
|
||||||
|
'image/jpg' => 'jpg',
|
||||||
|
'image/jpeg' => 'jpg',
|
||||||
|
'image/png' => 'png',
|
||||||
|
];
|
||||||
|
|
||||||
protected $table = 'zz_files';
|
protected $table = 'zz_files';
|
||||||
|
|
||||||
protected $file_info;
|
protected $file_info;
|
||||||
|
@ -211,6 +220,18 @@ class Upload extends Model
|
||||||
return in_array($this->extension, $list);
|
return in_array($this->extension, $list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getExtensionFromMimeType($file_content)
|
||||||
|
{
|
||||||
|
$finfo = finfo_open();
|
||||||
|
$mime_type = finfo_buffer($finfo, $file_content, FILEINFO_MIME_TYPE);
|
||||||
|
finfo_close($finfo);
|
||||||
|
|
||||||
|
return self::$extension_association[$mime_type];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue