[fix] Mosaic name was not set in db.

This commit is contained in:
guillaume91 2024-06-19 14:21:28 +02:00
parent ecc1a9a47b
commit 9e5eda0277
2 changed files with 7 additions and 1 deletions

View file

@ -4,6 +4,7 @@
use App\Jobs\ProjectMosiacGeneratorJob;
use App\Models\Project;
use App\Models\ProjectMosaic;
use Carbon\Carbon;
use Livewire\Component;
use Livewire\WithPagination;
@ -38,7 +39,7 @@ public function saveMosaic()
]);
$mosaic = $this->project->mosaics()->updateOrCreate([
'name' => sprintf('', $this->formData['end_date'], $this->formData['offset']),
'name' => ProjectMosaic::projectMosaicNameFormat(new Carbon($this->formData['end_date']),(int) $this->formData['offset']),
'offset' => $this->formData['offset'],
'end_date' => $this->formData['end_date'],
], [

View file

@ -32,6 +32,11 @@ public static function getFilenameByPeriod(Carbon $endDate,int $offset)
return sprintf('period_%s_%s.tif',(clone $endDate)->subdays($offset)->format('Y-m-d'),$endDate->format('Y-m-d'));
}
public static function projectMosaicNameFormat(Carbon $endDate,int $offset):string
{
return 'Period '.$endDate->copy()->subDays($offset)->toDateString().' - '.$endDate->toDateString();
}
public function project()
{
return $this->belongsTo(Project::class);