Skip to content

Commit

Permalink
Allowed values
Browse files Browse the repository at this point in the history
- Allowed values corrected for game item type, the winner needs to be an assigned category, not one of all categories
  • Loading branch information
deanblackborough committed Jun 20, 2022
1 parent aaa484b commit f0107e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/ItemView.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ private function optionsGameShow(
$allowed_values = new GameAllowedValue(
$this->viewable_resource_types,
$resource_type_id,
$resource_id
$resource_id,
$item_id
);

return (new \App\HttpOptionResponse\Item\Game($this->permissions((int) $resource_type_id)))
Expand Down
18 changes: 11 additions & 7 deletions app/ItemType/Game/AllowedValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
namespace App\ItemType\Game;

use App\HttpRequest\Hash;
use App\Models\Category;
use App\Models\ItemCategory;
use JetBrains\PhpStorm\ArrayShape;

class AllowedValue
{
protected Hash $hash;
protected int $resource_type_id;
protected ?int $resource_id;
protected ?int $item_id;
protected array $viewable_resource_types;

public function __construct(
array $viewable_resource_types,
int $resource_type_id,
?int $resource_id = null
?int $resource_id = null,
?int $item_id = null
)
{
$this->hash = new Hash();

$this->resource_type_id = $resource_type_id;
$this->resource_id = $resource_id;
$this->item_id = $item_id;
$this->viewable_resource_types = $viewable_resource_types;
}

Expand Down Expand Up @@ -72,22 +75,23 @@ private function assignAllowedValuesForWinner(): array
{
$allowed_values = [];

$winners = (new Category())->paginatedCollection(
$winners = (new ItemCategory())->paginatedCollection(
$this->resource_type_id,
$this->viewable_resource_types,
$this->resource_id,
$this->item_id,
0,
100
);

foreach ($winners as $winner) {
$winner_id = $this->hash->encode('category', $winner['category_id']);
$winner_id = $this->hash->encode('category', $winner['item_category_category_id']);

$allowed_values[$winner_id] = [
'uri' => route('category.show', ['resource_type_id' => $this->resource_type_id, 'category_id' => $winner_id], false),
'value' => $winner_id,
'name' => $winner['category_name'],
'name' => $winner['item_category_category_name'],
'description' => trans('item-type-game/allowed-values.description-prefix-winner_id') .
$winner['category_name'] .
$winner['item_category_category_name'] .
trans('item-type-game/allowed-values.description-suffix-winner_id')
];
}
Expand Down

0 comments on commit f0107e4

Please sign in to comment.