Upgrade to Laravel 11, begining of enabling network join functionality, removed QueryCacheable
This commit is contained in:
@@ -12,11 +12,11 @@ use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Casts\CompressedString;
|
||||
use App\Traits\{QueryCacheableConfig,ScopeActive};
|
||||
use App\Traits\ScopeActive;
|
||||
|
||||
class Domain extends Model
|
||||
{
|
||||
use HasFactory,ScopeActive,QueryCacheableConfig;
|
||||
use HasFactory,ScopeActive;
|
||||
|
||||
private const CACHE_TIME = 3600;
|
||||
private const STATS_MONTHS = 6;
|
||||
@@ -62,6 +62,15 @@ class Domain extends Model
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getCanAcceptAppAttribute(): bool
|
||||
{
|
||||
return our_address($this)->count()
|
||||
&& $this->active
|
||||
&& $this->accept_app
|
||||
&& Auth::id()
|
||||
&& $this->userHasSystemsNotInNet(Auth::user())->count();
|
||||
}
|
||||
|
||||
public function getHomePageAttribute(?string $value): string
|
||||
{
|
||||
//0xFD2FB528
|
||||
@@ -78,8 +87,7 @@ class Domain extends Model
|
||||
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'")
|
||||
->elseRaw("'all'");
|
||||
|
||||
return Echoarea::cacheFor(self::CACHE_TIME)
|
||||
->select(['echoareas.id','name','description','active',DB::raw('count(echomails.id) AS count'),DB::raw('max(datetime) as last_message')])
|
||||
return Echoarea::select(['echoareas.id','name','description','active',DB::raw('count(echomails.id) AS count'),DB::raw('max(datetime) as last_message')])
|
||||
->selectRaw($case->toRaw().' AS stats')
|
||||
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'],NULL,NULL,'left outer')
|
||||
->where('domain_id',$this->id)
|
||||
@@ -124,4 +132,23 @@ class Domain extends Model
|
||||
{
|
||||
return our_address($this)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out which of the users systems are not in this domain
|
||||
*
|
||||
* @param User $o
|
||||
* @return Collection
|
||||
*/
|
||||
public function userHasSystemsNotInNet(User $o): Collection
|
||||
{
|
||||
$o->load('systems.akas.zone');
|
||||
|
||||
$result = collect();
|
||||
foreach ($o->systems->filter(function($item) { return $item->active; }) as $so) {
|
||||
if (! $so->akas->pluck('zone')->unique('domain_id')->pluck('domain_id')->contains($this->id))
|
||||
$result->push($so);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user