Start on user dashboard

This commit is contained in:
Deon George
2021-10-26 23:19:55 +11:00
parent 8c127ba5da
commit a0db589dc5
8 changed files with 309 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use App\Traits\ScopeActive;
@@ -49,4 +50,32 @@ class Domain extends Model
{
$this->attributes['homepage'] = base64_encode(gzcompress($value,9));
}
/* METHODS */
public function stats(System $o=NULL): Collection
{
if (! $this->echoareas->count())
return collect();
$where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]);
if ($o)
$where->put('fftn_id',$o->addresses()->pluck('id'));
$echostats = Echomail::countGroupBy('echoarea_id',$where->toArray());
return $this->echoareas->map(function($item) use ($echostats) {
$stats = $echostats->filter(function($x) use ($item) {
return $x->id->echoarea_id == $item->id;
});
$item->count = 0;
foreach ($stats as $o)
$item->count += $o->count;
return $item;
});
}
}