diff --git a/app/Models/Domain.php b/app/Models/Domain.php index 4fff481..20ba0f4 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -124,6 +124,25 @@ class Domain extends Model }); } + public function filearea_stats() + { + $dt = Carbon::now()->startOfday(); + $case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'") + ->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'") + ->elseRaw("'all'"); + + return Filearea::select(['fileareas.id','fileareas.name','description','active',DB::raw('count(files.id) AS count'),DB::raw('min(datetime) as first_file'),DB::raw('max(datetime) as last_file')]) + ->selectRaw($case->toRaw().' AS stats') + ->join('files',['files.filearea_id'=>'fileareas.id'],NULL,NULL,'left outer') + ->where('domain_id',$this->id) + ->groupBy('fileareas.id') + ->groupBy('fileareas.name') + ->groupBy('stats') + ->orderBy('fileareas.name') + ->orderBy('last_file','DESC') + ->get(); + } + /** * Determine if this zone is managed by this host * diff --git a/app/Models/Filearea.php b/app/Models/Filearea.php index 1736a1d..68bac9d 100644 --- a/app/Models/Filearea.php +++ b/app/Models/Filearea.php @@ -11,6 +11,11 @@ class Filearea extends Model { use SoftDeletes,ScopeActive,AreaSecurity; + protected $casts = [ + 'first_file' => 'datetime:Y-m-d H:i:s', + 'last_file' => 'datetime:Y-m-d H:i:s', + ]; + protected $fillable = [ 'name', ]; diff --git a/resources/views/domain/view.blade.php b/resources/views/domain/view.blade.php index db1fbc0..814c8c2 100644 --- a/resources/views/domain/view.blade.php +++ b/resources/views/domain/view.blade.php @@ -58,10 +58,10 @@
@foreach ($o->echoarea_stats()->groupBy('id') as $oo)This network provides the following File areas:
-+ | Files | +|||||||||
---|---|---|---|---|---|---|---|---|---|---|
Filearea | Description | -Last File Sent | +First File | +Last File | +Area Active | +Week | +Month | +Total | ||
{{ $oo->name }} | -{{ $oo->description }} | -- | +{{ $x->name }} | +{{ $x->description }} | +{{ ($xx=$oo->min('first_file')) ? $xx->format('Y-m-d H:i') : '-' }} | +{{ $x->last_file ? $x->last_file->format('Y-m-d H:i') : '-' }} | +{{ $x->active ? 'Active' : 'Archive' }} | +{{ number_format($oo->where('stats','week')->pop()?->count) }} | +{{ number_format($oo->where('stats','month')->pop()?->count) }} | +{{ number_format($oo->sum('count')) }} |