<?php
namespace App\Containers\SettingSection\ListContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Containers\SettingSection\ListContainer\Data\Repositories\DepartmentRepository;
use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Департаменти
*/
#[ApiResource(
routePrefix: '/list',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/departments/{id}',
requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_EMPLOYEE')"
),
new Patch(
uriTemplate: '/departments/{id}',
requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Delete(
uriTemplate: '/departments/{id}',
requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/departments',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/departments',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_EMPLOYEE')"
),
],
shortName: 'List_Departments'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'name' => 'partial',
'code' => 'partial',
'source' => 'exact',
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'name',
'code',
])]
#[ORM\Entity(repositoryClass: DepartmentRepository::class)]
#[ORM\Table(name: '`list_departments`')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class DepartmentEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Название
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private string $name;
// Код: потрапляє в зовнішні OneLink-URL, тому унікальний і без перекладів
#[ORM\Column(type: Types::STRING, length: 255, nullable: false, unique: true)]
#[Groups(['read'])]
private string $code;
// Код ЕДРПОУ: передается в 1С как Kod агента
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $edrpou = null;
// Номер договора: передается в 1С как DocNum агента
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $docNum = null;
// KV: передается в 1С как KV агента
#[ORM\Column(type: Types::FLOAT, scale: 2, nullable: true)]
#[Groups(['read'])]
private ?float $kv = null;
// Полное название (для печатной формы)
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $fullName = null;
// Адрес (для печатной формы)
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $address = null;
// Электронная почта (для печатной формы)
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $email = null;
// Дополнительная информация (для печатной формы)
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $additionalInfo = null;
// Источник
#[ORM\ManyToOne(targetEntity: SourceEntity::class)]
#[ORM\JoinColumn(name: 'source_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
private SourceEntity $source;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $updatedAt;
/**
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
#[Gedmo\Locale]
private $locale;
public function getId(): ?int
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
return $this;
}
public function getCode()
{
return $this->code;
}
public function setCode(string $code)
{
$this->code = $code;
return $this;
}
public function getEdrpou()
{
return $this->edrpou;
}
public function setEdrpou(?string $edrpou)
{
$this->edrpou = $edrpou;
return $this;
}
public function getDocNum()
{
return $this->docNum;
}
public function setDocNum(?string $docNum)
{
$this->docNum = $docNum;
return $this;
}
public function getKv()
{
return $this->kv;
}
public function setKv(?float $kv)
{
$this->kv = $kv;
return $this;
}
public function getFullName()
{
return $this->fullName;
}
public function setFullName(?string $fullName)
{
$this->fullName = $fullName;
return $this;
}
public function getAddress()
{
return $this->address;
}
public function setAddress(?string $address)
{
$this->address = $address;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function setEmail(?string $email)
{
$this->email = $email;
return $this;
}
public function getAdditionalInfo()
{
return $this->additionalInfo;
}
public function setAdditionalInfo(?string $additionalInfo)
{
$this->additionalInfo = $additionalInfo;
return $this;
}
public function getSource()
{
return $this->source;
}
public function setSource(SourceEntity $source)
{
$this->source = $source;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}