diff --git a/app/Services/BundleCreator/Creators/CollectibleBundleCreator.php b/app/Services/BundleCreator/Creators/CollectibleBundleCreator.php index 80c5e3c..a034f1d 100644 --- a/app/Services/BundleCreator/Creators/CollectibleBundleCreator.php +++ b/app/Services/BundleCreator/Creators/CollectibleBundleCreator.php @@ -2,6 +2,7 @@ namespace App\Services\BundleCreator\Creators; +use App\Classes\Bundle; use App\Services\BundleCreator\Creators\CollectibleCreators\LegoBundleCreator; use Illuminate\Filesystem\FilesystemAdapter; @@ -9,6 +10,8 @@ class CollectibleBundleCreator extends BaseBundleCreator { + private static string $section = 'collections'; + public static $bundleCreators = [ LegoBundleCreator::class, ]; @@ -44,11 +47,14 @@ public function formSpecs(): ?array private function listBrands() { - $brands = [ - 'lego' => 'LEGO', - 'matchbox' => 'matchbox', - 'schleich' => 'Schleich', - ]; + $bundles = Bundle::findBundles($this->disk, static::$section); + $brands = []; + + foreach ($bundles as $bundle) { + $brands[basename($bundle->getPath())] = $bundle->metadata()->get('title'); + } + + asort($brands, SORT_NATURAL); return $brands; } @@ -59,6 +65,6 @@ private function listBrands() */ public static function handles(string $section, ?array $data = []): bool { - return $section === 'collections'; + return $section === static::$section; } } diff --git a/app/Services/BundleCreator/Creators/CriticBundleCreator.php b/app/Services/BundleCreator/Creators/CriticBundleCreator.php index dacff3c..151b2c6 100644 --- a/app/Services/BundleCreator/Creators/CriticBundleCreator.php +++ b/app/Services/BundleCreator/Creators/CriticBundleCreator.php @@ -2,6 +2,7 @@ namespace App\Services\BundleCreator\Creators; +use App\Classes\Bundle; use Illuminate\Filesystem\FilesystemAdapter; use function Laravel\Prompts\select; @@ -9,6 +10,8 @@ class CriticBundleCreator extends BaseBundleCreator { + private static string $section = 'critiques'; + public function __construct(protected ?array $data, protected FilesystemAdapter $disk) { // @@ -51,12 +54,14 @@ public function formSpecs(): ?array private function listKinds() { - $kinds = [ - 'Film' => 'films', - 'Série TV' => 'series', - 'Jeu vidéo' => 'jeux-video', - 'Livre' => 'livres', - ]; + $bundles = Bundle::findBundles($this->disk, static::$section); + $kinds = []; + + foreach ($bundles as $bundle) { + $kinds[basename($bundle->getPath())] = $bundle->metadata()->get('title'); + } + + asort($kinds, SORT_NATURAL); return $kinds; } @@ -67,6 +72,6 @@ private function listKinds() */ public static function handles(string $section, ?array $data = []): bool { - return $section === 'critiques'; + return $section === static::$section; } }