1
0
cms11/app/Services/BundleCreators/Creators/CollectibleBundleCreator.php

70 lines
1.7 KiB
PHP
Raw Normal View History

2024-04-17 11:41:10 +02:00
<?php
namespace App\Services\BundleCreators\Creators;
2024-04-17 11:41:10 +02:00
2024-04-18 00:43:53 +02:00
use App\Classes\Bundle;
use App\Services\BundleCreators\Creators\CollectibleCreators\LegoBundleCreator;
2024-04-17 11:41:10 +02:00
use Illuminate\Filesystem\FilesystemAdapter;
use function Laravel\Prompts\select;
class CollectibleBundleCreator extends BaseBundleCreator
{
public static $bundleCreators = [
LegoBundleCreator::class,
];
private static string $section = 'collections';
2024-04-17 11:41:10 +02:00
public function __construct(protected ?array $data, protected FilesystemAdapter $disk)
{
}
/**
* Return a boolean value indicating if the creator can actually make the
* bundle using known data.
*/
public function canCreateBundle(): bool
{
return !empty($this->data['brand']);
}
/**
* Return an array describing what kind of data the creator needs in
* addition to the one it already has
*/
public function formSpecs(): ?array
{
$specs = [];
if (empty($this->data['brand'])) {
$specs['brand'] = fn () => select('Product brand', $this->listBrands());
}
return $specs;
}
/**
* Return a boolean value indicating if this creator in particular can
* create bundles for specified section
*/
public static function handles(string $section, ?array $data = []): bool
{
return $section === static::$section;
}
2024-04-17 11:41:10 +02:00
private function listBrands()
{
2024-04-18 00:43:53 +02:00
$bundles = Bundle::findBundles($this->disk, static::$section);
$brands = [];
foreach ($bundles as $bundle) {
$brands[basename($bundle->getPath())] = $bundle->metadata()->get('title');
}
asort($brands, SORT_NATURAL);
2024-04-17 11:41:10 +02:00
return $brands;
}
}