Start on user dashboard
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
@@ -60,6 +60,13 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
protected $dates = ['last_on'];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function systems()
|
||||
{
|
||||
return $this->belongsToMany(System::class);
|
||||
}
|
||||
|
||||
/* GENERAL METHODS */
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user