diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 37eec72..f8cde4b 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -52,7 +52,7 @@ class UserController extends Controller public function dashboard() { $user = Auth::user(); - $user->load('systems.addresses.zone.domain'); + $user->load('systems.addresses.zone.domain.echoareas'); return view('dashboard') ->with('user',$user); diff --git a/app/Models/Domain.php b/app/Models/Domain.php index f6fe153..30048f0 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Collection; +use MongoDB\BSON\UTCDateTime; use App\Traits\ScopeActive; @@ -14,6 +15,7 @@ class Domain extends Model { use HasFactory,ScopeActive; private const CACHE_TIME = 3600; + private const STATS_MONTHS = 6; /* SCOPES */ @@ -64,7 +66,10 @@ class Domain extends Model $key = sprintf('%s_%d','daily_area_stats',$this->id); return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() { - $where = ['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]; + $where = [ + 'echoarea_id'=>$this->echoareas->pluck('id')->toArray(), + 'datetime' => ['$gte',new UTCDateTime(Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())], + ]; $echostats = Echomail::countGroupBy(['datetime',['datetime'=>'%Y-%m-%d']],$where); @@ -83,7 +88,10 @@ class Domain extends Model $key = sprintf('%s_%d-%d','daily_echoarea_stats',$this->id,$o->id); return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) { - $where = ['echoarea_id'=>[$o->id]]; + $where = [ + 'echoarea_id'=>[$o->id], + 'datetime' => ['$gte',new UTCDateTime(Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())], + ]; $echostats = Echomail::countGroupBy(['datetime',['datetime'=>'%Y-%m-%d']],$where); @@ -103,6 +111,7 @@ class Domain extends Model return Cache::driver('redis')->remember($key,self::CACHE_TIME,function() use ($o) { $where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]); + $where->put('datetime',['$gte',new UTCDateTime(Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())]); if ($o) $where->put('fftn_id',$o->addresses()->pluck('id')); diff --git a/app/Traits/UseMongo.php b/app/Traits/UseMongo.php index 51c7e61..d2463ae 100644 --- a/app/Traits/UseMongo.php +++ b/app/Traits/UseMongo.php @@ -6,6 +6,7 @@ namespace App\Traits; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Arr; trait UseMongo { @@ -56,11 +57,21 @@ trait UseMongo if (! is_array($values)) throw new \Exception('Where values must be an array.'); - $where_condition[$key] = ['$in' => $values]; + switch ($x=Arr::get($values,0)) { + case '$gt': + case '$gte': + $where_condition[$key] = [ $x => Arr::get($values,1)]; + break; + + case '$in': + default: + $where_condition[$key] = ['$in' => $values]; + } + } $query->push([ - '$match' => $where_condition + '$match' => [ '$and'=> [$where_condition]] ]); } diff --git a/resources/views/about.blade.php b/resources/views/about.blade.php index d6be6cd..ce3b3fe 100644 --- a/resources/views/about.blade.php +++ b/resources/views/about.blade.php @@ -117,7 +117,7 @@ If you have more than 1 BBS, then the Clearing House can receive all your mail f } }, series: [ - @foreach (\App\Models\Domain::active()->public()->get() as $o) + @foreach (\App\Models\Domain::active()->public()->with(['echoareas'])->get() as $o) { name: '{{ $o->name }}', data: {!! $o->daily_area_stats() !!}, diff --git a/resources/views/echomail/view.blade.php b/resources/views/echomail/view.blade.php index d431369..db41e80 100644 --- a/resources/views/echomail/view.blade.php +++ b/resources/views/echomail/view.blade.php @@ -1,4 +1,7 @@ @extends('layouts.app') +@section('htmlheader_title') + Message View +@endsection @section('content')

Echomail