deactivate bookcases

This commit is contained in:
HolgerHatGarKeineNode
2023-02-16 21:21:45 +01:00
parent ab56630227
commit d90af476bc
7 changed files with 16 additions and 8 deletions

View File

@@ -32,7 +32,7 @@ class SyncOpenBooks extends Command
try { try {
foreach ($response->json()['cases'] as $case) { foreach ($response->json()['cases'] as $case) {
BookCase::withoutGlobalScopes()->updateOrCreate( BookCase::updateOrCreate(
[ [
'id' => $case['id'], 'id' => $case['id'],
], ],

View File

@@ -31,7 +31,7 @@ class BookCaseTable extends Component
'icon_size' => [42, 42], 'icon_size' => [42, 42],
]) ])
->toArray(), ->toArray(),
'bookCases' => BookCase::get(), 'bookCases' => BookCase::query()->active()->get(),
'countries' => Country::query() 'countries' => Country::query()
->select(['code', 'name']) ->select(['code', 'name'])
->get(), ->get(),

View File

@@ -13,11 +13,13 @@ class Heatmap extends Component
public function render() public function render()
{ {
$data = BookCase::query() $data = BookCase::query()
->active()
->whereHas('orangePills') ->whereHas('orangePills')
->get()->map(fn($bookCase) => [ ->get()
'lat' => $bookCase->latitude, ->map(fn($bookCase) => [
'lng' => $bookCase->longitude, 'lat' => $bookCase->latitude,
]); 'lng' => $bookCase->longitude,
]);
return view('livewire.book-case.heatmap', [ return view('livewire.book-case.heatmap', [
'heatmap_data' => $data->toArray(), 'heatmap_data' => $data->toArray(),

View File

@@ -17,6 +17,7 @@ class WorldMap extends Component
'mapData' => BookCase::query() 'mapData' => BookCase::query()
->select(['id', 'latitude', 'longitude']) ->select(['id', 'latitude', 'longitude'])
->withCount('orangePills') ->withCount('orangePills')
->active()
->get() ->get()
->map(fn($bookCase) => [ ->map(fn($bookCase) => [
'lat' => $bookCase->latitude, 'lat' => $bookCase->latitude,

View File

@@ -123,6 +123,7 @@ class BookCaseTable extends DataTableComponent
public function builder(): Builder public function builder(): Builder
{ {
return BookCase::query() return BookCase::query()
->active()
->with([ ->with([
'orangePills', 'orangePills',
]) ])

View File

@@ -113,7 +113,7 @@ class CityTable extends DataTableComponent
{ {
$city = City::query() $city = City::query()
->find($id); ->find($id);
$query = BookCase::radius($city->latitude, $city->longitude, 25); $query = BookCase::active()->radius($city->latitude, $city->longitude, 25);
$ids = $query->pluck('id'); $ids = $query->pluck('id');
if ($ids->isEmpty()) { if ($ids->isEmpty()) {
$this->notification() $this->notification()

View File

@@ -41,7 +41,6 @@ class BookCase extends Model implements HasMedia
protected static function booted() protected static function booted()
{ {
static::addGlobalScope(new ActiveBookCases);
static::creating(function ($model) { static::creating(function ($model) {
if (!$model->created_by) { if (!$model->created_by) {
$model->created_by = auth()->id(); $model->created_by = auth()->id();
@@ -49,6 +48,11 @@ class BookCase extends Model implements HasMedia
}); });
} }
public function scopeActive($query)
{
return $query->where('deactivated', false);
}
public function registerMediaConversions(Media $media = null): void public function registerMediaConversions(Media $media = null): void
{ {
$this $this