2024-04-17 11:41:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\BundleCreator\Creators;
|
|
|
|
|
2024-04-18 00:43:53 +02:00
|
|
|
use App\Classes\Bundle;
|
2024-04-17 11:41:10 +02:00
|
|
|
use Illuminate\Filesystem\FilesystemAdapter;
|
|
|
|
|
|
|
|
use function Laravel\Prompts\select;
|
|
|
|
use function Laravel\Prompts\text;
|
|
|
|
|
|
|
|
class CriticBundleCreator extends BaseBundleCreator
|
|
|
|
{
|
2024-04-18 00:43:53 +02:00
|
|
|
private static string $section = 'critiques';
|
|
|
|
|
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['kind'])
|
|
|
|
&& !empty($this->data['title'])
|
|
|
|
&& !empty($this->data['entityId']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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['kind'])) {
|
|
|
|
$specs['kind'] = fn () => select('Media kind', $this->listKinds());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->data['title'])) {
|
|
|
|
$specs['title'] = fn () => text('Work title', '', '', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->data['entityId'])) {
|
|
|
|
$specs['entityId'] = fn () => text('Entity ID', '', '', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $specs;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function listKinds()
|
|
|
|
{
|
2024-04-18 00:43:53 +02:00
|
|
|
$bundles = Bundle::findBundles($this->disk, static::$section);
|
|
|
|
$kinds = [];
|
|
|
|
|
|
|
|
foreach ($bundles as $bundle) {
|
|
|
|
$kinds[basename($bundle->getPath())] = $bundle->metadata()->get('title');
|
|
|
|
}
|
|
|
|
|
|
|
|
asort($kinds, SORT_NATURAL);
|
2024-04-17 11:41:10 +02:00
|
|
|
|
|
|
|
return $kinds;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
{
|
2024-04-18 00:43:53 +02:00
|
|
|
return $section === static::$section;
|
2024-04-17 11:41:10 +02:00
|
|
|
}
|
|
|
|
}
|