62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Events\ProjectMosaicStatus;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ProjectMosaic extends Model
|
|
{
|
|
use HasFactory;
|
|
use \App\Traits\HasStatus;
|
|
|
|
protected $casts = [
|
|
'end_date' => 'datetime',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'path',
|
|
'week',
|
|
'year',
|
|
'end_date',
|
|
'offset',
|
|
'status'
|
|
];
|
|
|
|
|
|
public static function getFilenameByPeriod(Carbon $endDate, int $offset)
|
|
{
|
|
return sprintf('week_%s_%s.tif', (clone $endDate)->subdays($offset)->week, $endDate->year);
|
|
}
|
|
|
|
public static function projectMosaicNameFormat(Carbon $endDate, int $offset): string
|
|
{
|
|
return sprintf('Week_%s_%s',
|
|
$endDate->clone()->subDays($offset)->week,
|
|
$endDate->clone()->subDays($offset)->year
|
|
);
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function getStartDateAttribute()
|
|
{
|
|
return $this->end_date->subDay($this->offset);
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
parent::booted();
|
|
static::updated(function (ProjectMosaic $projectMosaic) {
|
|
event(new ProjectMosaicStatus($projectMosaic));
|
|
});
|
|
}
|
|
|
|
}
|