<?php
namespace App\Containers\CompanySection\StructureContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
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\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Containers\CompanySection\EmployeeContainer\Entities\EmployeeEntity;
use App\Containers\CompanySection\StructureContainer\Data\Repositories\StructureRepository;
use App\Containers\CompanySection\IndexContainer\Entities\TranslationEntity;
/**
* Структура компании
*/
#[ApiResource(
routePrefix: '/company',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/structures/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/structures/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Delete(
uriTemplate: '/structures/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/structures',
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/structures',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
),
],
shortName: 'Company_Structure'
)]
#[ApiFilter(SearchFilter::class, properties: ['title' => 'exact'])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(BooleanFilter::class, properties: ['forDelete'])]
#[ApiFilter(OrderFilter::class)]
#[Gedmo\Tree(type: 'nested')]
#[ORM\Entity(repositoryClass: StructureRepository::class)]
#[ORM\Table(name: '`company_structures`')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class StructureEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private bool $isActive = false;
#[ORM\Column(type: Types::STRING, length: 255)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private string $title;
#[Gedmo\TreeLeft]
#[ORM\Column(name: 'lft', type: Types::INTEGER, nullable: true)]
private $lft;
#[Gedmo\TreeLevel]
#[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)]
private $lvl;
#[Gedmo\TreeRight]
#[ORM\Column(name: 'rgt', type: Types::INTEGER, nullable: true)]
private $rgt;
#[Gedmo\TreeRoot]
#[ORM\ManyToOne(targetEntity: StructureEntity::class)]
#[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[Groups(['read'])]
private $root;
#[Gedmo\TreeParent]
#[ORM\ManyToOne(targetEntity: StructureEntity::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[Groups(['read'])]
private $parent;
#[ORM\OneToMany(targetEntity: StructureEntity::class, mappedBy: 'parent')]
#[ORM\OrderBy(['lft' => 'ASC'])]
#[Groups(['read'])]
private $children;
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private bool $forDelete = false;
#[ORM\OneToOne(targetEntity: EmployeeEntity::class)]
#[ORM\JoinColumn(name: 'supervisor_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?EmployeeEntity $supervisor = null;
#[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()
{
return $this->id;
}
public function getIsActive()
{
return $this->isActive;
}
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
public function getTitle()
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function getRoot(): ?self
{
return $this->root;
}
public function setParent(self $parent = null): void
{
$this->parent = $parent;
}
public function getParent(): ?self
{
return $this->parent;
}
public function getForDelete()
{
return $this->forDelete;
}
public function setForDelete($forDelete)
{
$this->forDelete = $forDelete;
return $this;
}
public function getSupervisor()
{
return $this->supervisor;
}
public function setSupervisor($supervisor)
{
$this->supervisor = $supervisor;
return $this;
}
public function getChildren()
{
return $this->children;
}
public function setChildren($children)
{
$this->children = $children;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}