Add filearea stats
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
@@ -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',
|
||||
];
|
||||
|
Reference in New Issue
Block a user