<?php
namespace App\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Admin\Controller\Api\GetRevisionAttributeListAction;
use App\Application\Controller\Api\Attribute\DeleteAction;
use App\Domain\Entity\Behavior\Identifiable;
use App\Domain\Entity\Enumeration\AttributeCategory;
use App\Domain\Entity\Media\Picto;
use App\Domain\Entity\Translation\AttributeTranslation;
use DateTime;
use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
use Gedmo\Timestampable\Traits\Timestampable;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
/**
* Class Attribute
*
* @package App\Domain\Entity
*/
#[ApiResource(
operations: [
new Delete(controller: DeleteAction::class, security: "is_granted('ROLE_ADMIN')"),
new Get(),
new GetCollection(filters: [
'attribute.label_filter',
'attribute.search_filter',
'attribute.query_filter',
'attribute.order_filter',
'soft_delete_filter',
]),
new GetCollection(
uriTemplate: '/attributes/revisions/list',
controller: GetRevisionAttributeListAction::class,
security: "is_granted('ROLE_ADMIN')"
),
new Post(normalizationContext: ['groups' => 'translations'], security: "is_granted('ROLE_ADMIN')"),
new Put(normalizationContext: ['groups' => ['translations']], security: "is_granted('ROLE_ADMIN')"),
],
normalizationContext: ['groups' => ['attribute_read']],
denormalizationContext: ['groups' => ['attribute_write']],
filters: ['translation.groups']
)]
class Attribute extends AbstractTranslatable
{
use Identifiable;
use SoftDeleteable;
use Timestampable;
public const ATTRIBUTE_CATEGORY_BRAND = 'attribute_category_brand';
public const ATTRIBUTE_CATEGORY_LABEL = 'attribute_category_label';
public const ATTRIBUTE_CATEGORY_LANGUAGE = 'attribute_category_language';
public const ATTRIBUTE_CATEGORY_PAYMENT = 'attribute_category_payment';
public const ATTRIBUTE_CATEGORY_PLACE = 'attribute_category_place';
public const ATTRIBUTE_CATEGORY_PRICE = 'attribute_category_price';
public const ATTRIBUTE_CATEGORY_SERVICE = 'attribute_category_service';
public const ATTRIBUTE_CATEGORY_SOURCES = 'attribute_category_sources';
public const SERVICE_PARKING = 'parking';
public const SERVICE_PARKING_SERVICE = 'parking_service';
public const SERVICE_PARKING_ELECTRICITY = 'parking_electricity';
public const SERVICE_PARKING_WATER = 'parking_water';
public const SERVICE_PACKAGE_CAMPER_VAN = 'package_camper_van';
public const SERVICE_PACKAGE_CARAVAN = 'package_caravan';
public const SERVICE_SLEEP = 'sleep';
public function __construct(
public AttributeCategory $category,
public bool $favorite = false,
public ?Attribute $parent = null,
public ?Picto $picto = null,
public ?string $section = null,
public ?string $remoteId = null,
public ?DateTime $zhistUpdate = null,
public ?string $code = null,
) {
parent::__construct();
}
/**
* @return string|null
*/
public function getLabel(): ?string
{
return $this->getTranslationType()->getLabel();
}
/**
* @param string $label
*/
public function setLabel(string $label): void
{
$this->getTranslationType()->setLabel($label);
}
public function getTranslationType(?string $locale = null): AttributeTranslation
{
return $this->getTranslation($locale);
}
protected function createTranslation(): TranslationInterface
{
return new AttributeTranslation();
}
}