Skip to content

Commit

Permalink
Merge pull request #781 from owlchester/objects-filter-equipped
Browse files Browse the repository at this point in the history
Objects filter: Equipped
  • Loading branch information
ilestis authored Dec 7, 2023
2 parents 2801034 + 22accdc commit 809d447
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/Datagrids/Filters/ItemFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function build()
->add('type')
->add('price')
->add('size')
->add('is_equipped')
->add([
'field' => 'item_id',
'label' => __('crud.fields.parent'),
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use App\Models\Entity;
use App\Models\AttributeTemplate;
use App\Models\Bookmark;
use App\Models\Family;
use App\Models\MiscModel;
use App\Sanitizers\MiscSanitizer;
use App\Services\MultiEditingService;
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Front/HelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers\Front;

use App\Models\Family;
use App\Models\MiscModel;
use Exception;
use Illuminate\Support\Str;
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Concerns/HasFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public function scopeFilter(Builder $query, array $params = []): Builder
$this->filterTemplate($query, $value);
} elseif ($key == 'has_posts') {
$this->filterHasPosts($query, $value);
} elseif ($key == 'is_equipped') {
$this->filterIsEquipped($query, $value);
} elseif ($key == 'has_attributes') {
$this->filterHasAttributes($query, $value);
} elseif ($key == 'has_entity_files') {
Expand Down Expand Up @@ -350,6 +352,21 @@ protected function filterHasPosts(Builder $query, string $value = null): void
}
}

/**
* Filter on entities that are equipped
*/
protected function filterIsEquipped(Builder $query, string $value = null): void
{
$query
->leftJoin('inventories', 'inventories.item_id', 'items.id');

if ($value) {
$query->whereNotNull('inventories.id');
} else {
$query->whereNull('inventories.id');
}
}

/**
* Filter on entities with attributes
*/
Expand Down
1 change: 1 addition & 0 deletions app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public function filterableColumns(): array
'price',
'size',
'item_id',
'is_equipped',
];
}

Expand Down
1 change: 0 additions & 1 deletion app/Models/MiscModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Facades\Img;
use App\Facades\Mentions;
use App\Facades\Module;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\LastSync;
use App\Models\Concerns\Orderable;
use App\Models\Concerns\Paginatable;
Expand Down
1 change: 0 additions & 1 deletion app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Campaign/Import/Mappers/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ protected function relations(): self
'relation', 'visibility_id', 'attitude', 'is_pinned', 'colour', 'marketplace_uuid'
];
foreach ($this->data['entity']['relationships'] as $data) {
if (!ImportIdMapper::hasEntity( $data['target_id'])) {
if (!ImportIdMapper::hasEntity($data['target_id'])) {
continue;
}
$targetID = ImportIdMapper::getEntity($data['target_id']);
Expand Down
7 changes: 4 additions & 3 deletions lang/en/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
'title' => 'New Item',
],
'fields' => [
'character' => 'Creator',
'price' => 'Price',
'size' => 'Size',
'character' => 'Creator',
'price' => 'Price',
'size' => 'Size',
'is_equipped' => 'Equipped'
],
'helpers' => [
'nested_without' => 'Displaying all items that don\'t have a parent item. Click on a row to see the children items.',
Expand Down

0 comments on commit 809d447

Please sign in to comment.