forked from mirror/Part-DB.Part-DB-server
Applied rector with PHP8.1 migration rules
This commit is contained in:
parent
dc6a67c2f0
commit
7ee01d9a05
303 changed files with 1228 additions and 3465 deletions
|
@ -55,13 +55,8 @@ use Symfony\Component\Serializer\Serializer;
|
|||
#[Route(path: '/typeahead')]
|
||||
class TypeaheadController extends AbstractController
|
||||
{
|
||||
protected AttachmentURLGenerator $urlGenerator;
|
||||
protected Packages $assets;
|
||||
|
||||
public function __construct(AttachmentURLGenerator $URLGenerator, Packages $assets)
|
||||
public function __construct(protected AttachmentURLGenerator $urlGenerator, protected Packages $assets)
|
||||
{
|
||||
$this->urlGenerator = $URLGenerator;
|
||||
$this->assets = $assets;
|
||||
}
|
||||
|
||||
#[Route(path: '/builtInResources/search', name: 'typeahead_builtInRessources')]
|
||||
|
@ -93,45 +88,26 @@ class TypeaheadController extends AbstractController
|
|||
|
||||
/**
|
||||
* This function map the parameter type to the class, so we can access its repository
|
||||
* @param string $type
|
||||
* @return class-string
|
||||
*/
|
||||
private function typeToParameterClass(string $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case 'category':
|
||||
return CategoryParameter::class;
|
||||
case 'part':
|
||||
return PartParameter::class;
|
||||
case 'device':
|
||||
return ProjectParameter::class;
|
||||
case 'footprint':
|
||||
return FootprintParameter::class;
|
||||
case 'manufacturer':
|
||||
return ManufacturerParameter::class;
|
||||
case 'storelocation':
|
||||
return StorelocationParameter::class;
|
||||
case 'supplier':
|
||||
return SupplierParameter::class;
|
||||
case 'attachment_type':
|
||||
return AttachmentTypeParameter::class;
|
||||
case 'group':
|
||||
return GroupParameter::class;
|
||||
case 'measurement_unit':
|
||||
return MeasurementUnitParameter::class;
|
||||
case 'currency':
|
||||
return Currency::class;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid parameter type: '.$type);
|
||||
}
|
||||
return match ($type) {
|
||||
'category' => CategoryParameter::class,
|
||||
'part' => PartParameter::class,
|
||||
'device' => ProjectParameter::class,
|
||||
'footprint' => FootprintParameter::class,
|
||||
'manufacturer' => ManufacturerParameter::class,
|
||||
'storelocation' => StorelocationParameter::class,
|
||||
'supplier' => SupplierParameter::class,
|
||||
'attachment_type' => AttachmentTypeParameter::class,
|
||||
'group' => GroupParameter::class,
|
||||
'measurement_unit' => MeasurementUnitParameter::class,
|
||||
'currency' => Currency::class,
|
||||
default => throw new \InvalidArgumentException('Invalid parameter type: '.$type),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @return JsonResponse
|
||||
*/
|
||||
#[Route(path: '/parts/search/{query}', name: 'typeahead_parts')]
|
||||
public function parts(EntityManagerInterface $entityManager, PartPreviewGenerator $previewGenerator,
|
||||
AttachmentURLGenerator $attachmentURLGenerator, string $query = ""): JsonResponse
|
||||
|
@ -146,7 +122,7 @@ class TypeaheadController extends AbstractController
|
|||
foreach ($parts as $part) {
|
||||
//Determine the picture to show:
|
||||
$preview_attachment = $previewGenerator->getTablePreviewAttachment($part);
|
||||
if($preview_attachment !== null) {
|
||||
if($preview_attachment instanceof \App\Entity\Attachments\Attachment) {
|
||||
$preview_url = $attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_sm');
|
||||
} else {
|
||||
$preview_url = '';
|
||||
|
@ -156,8 +132,8 @@ class TypeaheadController extends AbstractController
|
|||
$data[] = [
|
||||
'id' => $part->getID(),
|
||||
'name' => $part->getName(),
|
||||
'category' => $part->getCategory() ? $part->getCategory()->getName() : 'Unknown',
|
||||
'footprint' => $part->getFootprint() ? $part->getFootprint()->getName() : '',
|
||||
'category' => $part->getCategory() instanceof \App\Entity\Parts\Category ? $part->getCategory()->getName() : 'Unknown',
|
||||
'footprint' => $part->getFootprint() instanceof \App\Entity\Parts\Footprint ? $part->getFootprint()->getName() : '',
|
||||
'description' => mb_strimwidth($part->getDescription(), 0, 127, '...'),
|
||||
'image' => $preview_url,
|
||||
];
|
||||
|
@ -166,10 +142,6 @@ class TypeaheadController extends AbstractController
|
|||
return new JsonResponse($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @return JsonResponse
|
||||
*/
|
||||
#[Route(path: '/parameters/{type}/search/{query}', name: 'typeahead_parameters', requirements: ['type' => '.+'])]
|
||||
public function parameters(string $type, EntityManagerInterface $entityManager, string $query = ""): JsonResponse
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue