- Remove unused FeaturesController (empty stubs, no routes) - Remove ConvertSpatialFile CLI command (unused; service used in LayerManager) - Remove MigrateGeojsonToFeatures CLI command (one-shot migration, not referenced) - Remove .claude/worktrees/ (11 old agent worktrees from June) - Apply Laravel Pint formatting across 219 files (style only, no functional changes) Tests: 101 passing (319 assertions) API routes: unchanged (8 routes intact)
81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
class ProgressSnapshot extends Model
|
|
{
|
|
protected $fillable = [
|
|
'trackable_type',
|
|
'trackable_id',
|
|
'snapshot_date',
|
|
'progress',
|
|
'planned_start',
|
|
'planned_end',
|
|
'actual_start',
|
|
'actual_end',
|
|
'method',
|
|
'metadata',
|
|
];
|
|
|
|
protected $casts = [
|
|
'snapshot_date' => 'date',
|
|
'planned_start' => 'date',
|
|
'planned_end' => 'date',
|
|
'actual_start' => 'date',
|
|
'actual_end' => 'date',
|
|
'progress' => 'decimal:2',
|
|
'metadata' => 'array',
|
|
];
|
|
|
|
public function trackable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* Scope for a specific date range
|
|
*/
|
|
public function scopeDateRange($query, $from, $to)
|
|
{
|
|
return $query->whereBetween('snapshot_date', [$from, $to]);
|
|
}
|
|
|
|
/**
|
|
* Scope for specific trackable
|
|
*/
|
|
public function scopeForTrackable($query, $model, $id = null)
|
|
{
|
|
$query->where('trackable_type', $model);
|
|
if ($id) {
|
|
$query->where('trackable_id', $id);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Get latest snapshot for a trackable
|
|
*/
|
|
public static function latestFor($model, $id): ?self
|
|
{
|
|
return static::forTrackable($model, $id)
|
|
->latest('snapshot_date')
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Get progress trend (last N snapshots)
|
|
*/
|
|
public static function trendFor($model, $id, int $limit = 10): array
|
|
{
|
|
return static::forTrackable($model, $id)
|
|
->orderBy('snapshot_date')
|
|
->take($limit)
|
|
->get(['snapshot_date', 'progress', 'method'])
|
|
->toArray();
|
|
}
|
|
}
|