src/Containers/CompanySection/StructureContainer/Entities/StructureEntity.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CompanySection\StructureContainer\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\Put;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Doctrine\DBAL\Types\Types;
  18. use Gedmo\Mapping\Annotation as Gedmo;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use App\Containers\CompanySection\EmployeeContainer\Entities\EmployeeEntity;
  21. use App\Containers\CompanySection\StructureContainer\Data\Repositories\StructureRepository;
  22. use App\Containers\CompanySection\IndexContainer\Entities\TranslationEntity;
  23. /** 
  24.  * Структура компании
  25. */
  26. #[ApiResource(
  27.     routePrefix'/company',
  28.     normalizationContext: ['groups' => 'read'],
  29.     operations: [
  30.         new Get(
  31.             uriTemplate'/structures/{id}'requirements: ['id' => '\d+'],
  32.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
  33.         ),
  34.         new Patch(
  35.             uriTemplate'/structures/{id}'requirements: ['id' => '\d+'],
  36.             security"is_granted('ROLE_ADMIN')"
  37.         ),
  38.         new Delete(
  39.             uriTemplate'/structures/{id}'requirements: ['id' => '\d+'],
  40.             security"is_granted('ROLE_ADMIN')"
  41.         ),
  42.         new Post(
  43.             uriTemplate'/structures',
  44.             security"is_granted('ROLE_ADMIN')"
  45.         ),
  46.         new GetCollection(
  47.             uriTemplate'/structures',
  48.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
  49.         ),
  50.     ],
  51.     shortName'Company_Structure'
  52. )]
  53. #[ApiFilter(SearchFilter::class, properties: ['title' => 'exact'])]
  54. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  55. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  56. #[ApiFilter(BooleanFilter::class, properties: ['forDelete'])]
  57. #[ApiFilter(OrderFilter::class)]
  58. #[Gedmo\Tree(type'nested')]
  59. #[ORM\Entity(repositoryClassStructureRepository::class)]
  60. #[ORM\Table(name'`company_structures`')]
  61. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  62. class StructureEntity
  63. {
  64.     #[ORM\Id]
  65.     #[ORM\GeneratedValue]
  66.     #[ORM\Column(typeTypes::INTEGER)]
  67.     #[Groups(['read'])]
  68.     private ?int $id null;
  69.     #[ORM\Column(typeTypes::BOOLEAN)]
  70.     #[Groups(['read'])]
  71.     private bool $isActive false;
  72.     #[ORM\Column(typeTypes::STRINGlength255)]
  73.     #[Gedmo\Translatable]
  74.     #[Groups(['read'])]
  75.     private string $title;
  76.     #[Gedmo\TreeLeft]
  77.     #[ORM\Column(name'lft'typeTypes::INTEGERnullabletrue)]
  78.     private $lft;
  79.     #[Gedmo\TreeLevel]
  80.     #[ORM\Column(name'lvl'typeTypes::INTEGERnullabletrue)]
  81.     private $lvl;
  82.     #[Gedmo\TreeRight]
  83.     #[ORM\Column(name'rgt'typeTypes::INTEGERnullabletrue)]
  84.     private $rgt;
  85.     #[Gedmo\TreeRoot]
  86.     #[ORM\ManyToOne(targetEntityStructureEntity::class)]
  87.     #[ORM\JoinColumn(name'tree_root'referencedColumnName'id'onDelete'CASCADE')]
  88.     #[Groups(['read'])]
  89.     private $root;
  90.     #[Gedmo\TreeParent]
  91.     #[ORM\ManyToOne(targetEntityStructureEntity::class, inversedBy'children')]
  92.     #[ORM\JoinColumn(name'parent_id'referencedColumnName'id'onDelete'CASCADE')]
  93.     #[Groups(['read'])]
  94.     private $parent;
  95.     #[ORM\OneToMany(targetEntityStructureEntity::class, mappedBy'parent')]
  96.     #[ORM\OrderBy(['lft' => 'ASC'])]
  97.     #[Groups(['read'])]
  98.     private $children;
  99.     
  100.     #[ORM\Column(typeTypes::BOOLEAN)]
  101.     #[Groups(['read'])]
  102.     private bool $forDelete false;
  103.     #[ORM\OneToOne(targetEntityEmployeeEntity::class)]
  104.     #[ORM\JoinColumn(name'supervisor_id'referencedColumnName'id'nullabletrue)]
  105.     #[Groups(['read'])]
  106.     private ?EmployeeEntity $supervisor null;
  107.     #[Gedmo\Timestampable(on'create')]
  108.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  109.     protected $createdAt;
  110.     #[Gedmo\Timestampable(on'update')]
  111.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  112.     protected $updatedAt;
  113.     /**
  114.      * Used locale to override Translation listener`s locale
  115.      * this is not a mapped field of entity metadata, just a simple property
  116.      */
  117.     #[Gedmo\Locale]
  118.     private $locale;
  119.     public function getId()
  120.     {
  121.         return $this->id;
  122.     }
  123.     public function getIsActive()
  124.     {
  125.         return $this->isActive;
  126.     }
  127.     public function setIsActive($isActive)
  128.     {
  129.         $this->isActive $isActive;
  130.         return $this;
  131.     }
  132.     public function getTitle()
  133.     {
  134.         return $this->title;
  135.     }
  136.     public function setTitle($title)
  137.     {
  138.         $this->title $title;
  139.         return $this;
  140.     }
  141.     public function getRoot(): ?self
  142.     {
  143.         return $this->root;
  144.     }
  145.     public function setParent(self $parent null): void
  146.     {
  147.         $this->parent $parent;
  148.     }
  149.     public function getParent(): ?self
  150.     {
  151.         return $this->parent;
  152.     }
  153.     public function getForDelete()
  154.     {
  155.         return $this->forDelete;
  156.     }
  157.     public function setForDelete($forDelete)
  158.     {
  159.         $this->forDelete $forDelete;
  160.         return $this;
  161.     }
  162.     public function getSupervisor()
  163.     {
  164.         return $this->supervisor;
  165.     }
  166.     public function setSupervisor($supervisor)
  167.     {
  168.         $this->supervisor $supervisor;
  169.         return $this;
  170.     }
  171.  
  172.     public function getChildren()
  173.     {
  174.         return $this->children;
  175.     }
  176.     public function setChildren($children)
  177.     {
  178.         $this->children $children;
  179.         return $this;
  180.     }
  181.     public function setTranslatableLocale($locale)
  182.     {
  183.         $this->locale $locale;
  184.     }
  185. }