src/Containers/SettingSection/ListContainer/Entities/DepartmentEntity.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Containers\SettingSection\ListContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Doctrine\DBAL\Types\Types;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use App\Containers\SettingSection\ListContainer\Data\Repositories\DepartmentRepository;
  19. use App\Containers\SettingSection\IndexContainer\Entities\TranslationEntity;
  20. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  21. /**
  22.  * Департаменти
  23. */
  24. #[ApiResource(
  25.     routePrefix: '/list',
  26.     normalizationContext: ['groups' => 'read'],
  27.     operations: [
  28.         new Get(
  29.             uriTemplate: '/departments/{id}',
  30.             requirements: ['id' => '\d+'],
  31.             security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_EMPLOYEE')"
  32.         ),
  33.         new Patch(
  34.             uriTemplate: '/departments/{id}',
  35.             requirements: ['id' => '\d+'],
  36.             security: "is_granted('ROLE_ADMIN')"
  37.         ),
  38.         new Delete(
  39.             uriTemplate: '/departments/{id}',
  40.             requirements: ['id' => '\d+'],
  41.             security: "is_granted('ROLE_ADMIN')"
  42.         ),
  43.         new Post(
  44.             uriTemplate: '/departments',
  45.             security: "is_granted('ROLE_ADMIN')"
  46.         ),
  47.         new GetCollection(
  48.             uriTemplate: '/departments',
  49.             security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_EMPLOYEE')"
  50.         ),
  51.     ],
  52.     shortName: 'List_Departments'
  53. )]
  54. #[ApiFilter(SearchFilter::class, properties: [
  55.     'id' => 'exact',
  56.     'name' => 'partial',
  57.     'code' => 'partial',
  58.     'source' => 'exact',
  59. ])]
  60. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  61. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  62. #[ApiFilter(OrderFilter::class)]
  63. #[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
  64.     'name',
  65.     'code',
  66. ])]
  67. #[ORM\Entity(repositoryClass: DepartmentRepository::class)]
  68. #[ORM\Table(name: '`list_departments`')]
  69. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  70. class DepartmentEntity
  71. {
  72.     #[ORM\Id]
  73.     #[ORM\GeneratedValue]
  74.     #[ORM\Column(type: Types::INTEGER)]
  75.     #[Groups(['read'])]
  76.     private ?int $id = null;
  77.     // Название
  78.     #[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
  79.     #[Gedmo\Translatable]
  80.     #[Groups(['read'])]
  81.     private string $name;
  82.     // Код: потрапляє в зовнішні OneLink-URL, тому унікальний і без перекладів
  83.     #[ORM\Column(type: Types::STRING, length: 255, nullable: false, unique: true)]
  84.     #[Groups(['read'])]
  85.     private string $code;
  86.     // Код ЕДРПОУ: передается в 1С как Kod агента
  87.     #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
  88.     #[Groups(['read'])]
  89.     private ?string $edrpou = null;
  90.     // Номер договора: передается в 1С как DocNum агента
  91.     #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
  92.     #[Groups(['read'])]
  93.     private ?string $docNum = null;
  94.     // KV: передается в 1С как KV агента
  95.     #[ORM\Column(type: Types::FLOAT, scale: 2, nullable: true)]
  96.     #[Groups(['read'])]
  97.     private ?float $kv = null;
  98.     // Полное название (для печатной формы)
  99.     #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
  100.     #[Gedmo\Translatable]
  101.     #[Groups(['read'])]
  102.     private ?string $fullName = null;
  103.     // Адрес (для печатной формы)
  104.     #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
  105.     #[Gedmo\Translatable]
  106.     #[Groups(['read'])]
  107.     private ?string $address = null;
  108.     // Электронная почта (для печатной формы)
  109.     #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
  110.     #[Groups(['read'])]
  111.     private ?string $email = null;
  112.     // Дополнительная информация (для печатной формы)
  113.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  114.     #[Gedmo\Translatable]
  115.     #[Groups(['read'])]
  116.     private ?string $additionalInfo = null;
  117.     // Источник
  118.     #[ORM\ManyToOne(targetEntity: SourceEntity::class)]
  119.     #[ORM\JoinColumn(name: 'source_id', referencedColumnName: 'id', nullable: false)]
  120.     #[Groups(['read'])]
  121.     private SourceEntity $source;
  122.     #[Gedmo\Timestampable(on: 'create')]
  123.     #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  124.     protected $createdAt;
  125.     #[Gedmo\Timestampable(on: 'update')]
  126.     #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  127.     protected $updatedAt;
  128.     /**
  129.      * Used locale to override Translation listener`s locale
  130.      * this is not a mapped field of entity metadata, just a simple property
  131.      */
  132.     #[Gedmo\Locale]
  133.     private $locale;
  134.     public function getId(): ?int
  135.     {
  136.         return $this->id;
  137.     }
  138.     public function getName()
  139.     {
  140.         return $this->name;
  141.     }
  142.     public function setName(string $name)
  143.     {
  144.         $this->name = $name;
  145.         return $this;
  146.     }
  147.     public function getCode()
  148.     {
  149.         return $this->code;
  150.     }
  151.     public function setCode(string $code)
  152.     {
  153.         $this->code = $code;
  154.         return $this;
  155.     }
  156.     public function getEdrpou()
  157.     {
  158.         return $this->edrpou;
  159.     }
  160.     public function setEdrpou(?string $edrpou)
  161.     {
  162.         $this->edrpou = $edrpou;
  163.         return $this;
  164.     }
  165.     public function getDocNum()
  166.     {
  167.         return $this->docNum;
  168.     }
  169.     public function setDocNum(?string $docNum)
  170.     {
  171.         $this->docNum = $docNum;
  172.         return $this;
  173.     }
  174.     public function getKv()
  175.     {
  176.         return $this->kv;
  177.     }
  178.     public function setKv(?float $kv)
  179.     {
  180.         $this->kv = $kv;
  181.         return $this;
  182.     }
  183.     public function getFullName()
  184.     {
  185.         return $this->fullName;
  186.     }
  187.     public function setFullName(?string $fullName)
  188.     {
  189.         $this->fullName = $fullName;
  190.         return $this;
  191.     }
  192.     public function getAddress()
  193.     {
  194.         return $this->address;
  195.     }
  196.     public function setAddress(?string $address)
  197.     {
  198.         $this->address = $address;
  199.         return $this;
  200.     }
  201.     public function getEmail()
  202.     {
  203.         return $this->email;
  204.     }
  205.     public function setEmail(?string $email)
  206.     {
  207.         $this->email = $email;
  208.         return $this;
  209.     }
  210.     public function getAdditionalInfo()
  211.     {
  212.         return $this->additionalInfo;
  213.     }
  214.     public function setAdditionalInfo(?string $additionalInfo)
  215.     {
  216.         $this->additionalInfo = $additionalInfo;
  217.         return $this;
  218.     }
  219.     public function getSource()
  220.     {
  221.         return $this->source;
  222.     }
  223.     public function setSource(SourceEntity $source)
  224.     {
  225.         $this->source = $source;
  226.         return $this;
  227.     }
  228.     public function setTranslatableLocale($locale)
  229.     {
  230.         $this->locale = $locale;
  231.     }
  232. }