mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Use a own discriminator map for the Attachment API Platform discriminator
This commit is contained in:
parent
ce768764cc
commit
e3d2012809
1 changed files with 11 additions and 3 deletions
|
@ -57,7 +57,7 @@ use LogicException;
|
||||||
#[ORM\Entity(repositoryClass: AttachmentRepository::class)]
|
#[ORM\Entity(repositoryClass: AttachmentRepository::class)]
|
||||||
#[ORM\InheritanceType('SINGLE_TABLE')]
|
#[ORM\InheritanceType('SINGLE_TABLE')]
|
||||||
#[ORM\DiscriminatorColumn(name: 'class_name', type: 'string')]
|
#[ORM\DiscriminatorColumn(name: 'class_name', type: 'string')]
|
||||||
#[ORM\DiscriminatorMap(self::DISCRIMINATOR_MAP)]
|
#[ORM\DiscriminatorMap(self::ORM_DISCRIMINATOR_MAP)]
|
||||||
#[ORM\EntityListeners([AttachmentDeleteListener::class])]
|
#[ORM\EntityListeners([AttachmentDeleteListener::class])]
|
||||||
#[ORM\Table(name: '`attachments`')]
|
#[ORM\Table(name: '`attachments`')]
|
||||||
#[ORM\Index(name: 'attachments_idx_id_element_id_class_name', columns: ['id', 'element_id', 'class_name'])]
|
#[ORM\Index(name: 'attachments_idx_id_element_id_class_name', columns: ['id', 'element_id', 'class_name'])]
|
||||||
|
@ -85,16 +85,24 @@ use LogicException;
|
||||||
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)]
|
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)]
|
||||||
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
|
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
|
||||||
//This discriminator map is required for API platform to know which class to use for deserialization, when creating a new attachment.
|
//This discriminator map is required for API platform to know which class to use for deserialization, when creating a new attachment.
|
||||||
#[DiscriminatorMap(typeProperty: '_type', mapping: self::DISCRIMINATOR_MAP)]
|
#[DiscriminatorMap(typeProperty: '_type', mapping: self::API_DISCRIMINATOR_MAP)]
|
||||||
abstract class Attachment extends AbstractNamedDBElement
|
abstract class Attachment extends AbstractNamedDBElement
|
||||||
{
|
{
|
||||||
private const DISCRIMINATOR_MAP = ['PartDB\Part' => PartAttachment::class, 'Part' => PartAttachment::class,
|
private const ORM_DISCRIMINATOR_MAP = ['PartDB\Part' => PartAttachment::class, 'Part' => PartAttachment::class,
|
||||||
'PartDB\Device' => ProjectAttachment::class, 'Device' => ProjectAttachment::class, 'AttachmentType' => AttachmentTypeAttachment::class,
|
'PartDB\Device' => ProjectAttachment::class, 'Device' => ProjectAttachment::class, 'AttachmentType' => AttachmentTypeAttachment::class,
|
||||||
'Category' => CategoryAttachment::class, 'Footprint' => FootprintAttachment::class, 'Manufacturer' => ManufacturerAttachment::class,
|
'Category' => CategoryAttachment::class, 'Footprint' => FootprintAttachment::class, 'Manufacturer' => ManufacturerAttachment::class,
|
||||||
'Currency' => CurrencyAttachment::class, 'Group' => GroupAttachment::class, 'MeasurementUnit' => MeasurementUnitAttachment::class,
|
'Currency' => CurrencyAttachment::class, 'Group' => GroupAttachment::class, 'MeasurementUnit' => MeasurementUnitAttachment::class,
|
||||||
'Storelocation' => StorageLocationAttachment::class, 'Supplier' => SupplierAttachment::class,
|
'Storelocation' => StorageLocationAttachment::class, 'Supplier' => SupplierAttachment::class,
|
||||||
'User' => UserAttachment::class, 'LabelProfile' => LabelAttachment::class];
|
'User' => UserAttachment::class, 'LabelProfile' => LabelAttachment::class];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The discriminator map used for API platform. The key should be the same as the api platform short type (the @type JSONLD field).
|
||||||
|
*/
|
||||||
|
private const API_DISCRIMINATOR_MAP = ["Part" => PartAttachment::class, "Project" => ProjectAttachment::class, "AttachmentType" => AttachmentTypeAttachment::class,
|
||||||
|
"Category" => CategoryAttachment::class, "Footprint" => FootprintAttachment::class, "Manufacturer" => ManufacturerAttachment::class,
|
||||||
|
"Currency" => CurrencyAttachment::class, "Group" => GroupAttachment::class, "MeasurementUnit" => MeasurementUnitAttachment::class,
|
||||||
|
"StorageLocation" => StorageLocationAttachment::class, "Supplier" => SupplierAttachment::class, "User" => UserAttachment::class, "LabelProfile" => LabelAttachment::class];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of file extensions, that browsers can show directly as image.
|
* A list of file extensions, that browsers can show directly as image.
|
||||||
* Based on: https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
|
* Based on: https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue