added Schema validation step adapt code to new substructure code/libelle => keep libelle only added nom field to DB and data extraction added changelog.md
100 lines
2.2 KiB
PHP
100 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Contracts\Filesystem\Filesystem;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class XmlInco extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'id',
|
|
'no_art',
|
|
'prod_saison',
|
|
'allegations',
|
|
'conseil_prepa',
|
|
'astuces',
|
|
'descriptif',
|
|
'arg_vente',
|
|
'nb_portion',
|
|
'typ_portion',
|
|
'pds_moy_theo',
|
|
'lib_conso',
|
|
'lst_ing',
|
|
'lib_allergene',
|
|
'nutritional_values',
|
|
'picture',
|
|
];
|
|
|
|
protected $casts = [
|
|
'picture' => 'array',
|
|
'nutritional_values' => 'array',
|
|
];
|
|
|
|
/**
|
|
* The Laravel disk name
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $disk = 'inco';
|
|
|
|
protected $imagesPath = 'images';
|
|
|
|
/**
|
|
* The files to ignore
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $ignoreFiles = [
|
|
'.gitignore', '.gitkeep'
|
|
];
|
|
|
|
/**
|
|
* retrieve a collection of medias
|
|
*/
|
|
public function getMediasAttribute() {
|
|
/** @var Filesystem */
|
|
$disk = $this->getDisk();
|
|
$files = $disk->files($this->imagesPath);
|
|
|
|
$collFiles = new Collection();
|
|
// /** @var File */
|
|
foreach ($files as $file) {
|
|
$pi = \pathinfo($file, \PATHINFO_BASENAME);
|
|
if (in_array($pi, $this->ignoreFiles)) {
|
|
continue;
|
|
}
|
|
if (!in_array($pi, array($this->id))) {
|
|
continue;
|
|
}
|
|
$image = base64_encode($disk->get($file));
|
|
$element = array(
|
|
"filename" => $pi,
|
|
"imgdata" => $image
|
|
);
|
|
$collFiles->add($element);
|
|
}
|
|
return $collFiles;
|
|
}
|
|
|
|
/**
|
|
* Get the concerned disk
|
|
*
|
|
* @return Filesystem
|
|
*/
|
|
protected function getDisk(): Filesystem
|
|
{
|
|
return Storage::disk($this->disk);
|
|
}
|
|
|
|
public function getNiceStringAttribute()
|
|
{
|
|
return sprintf('%s - %s', $this->id, $this->descriptif);
|
|
}
|
|
}
|