<?php
namespace App\Containers\CrmSection\TaskContainer\Entities;
use ApiPlatform\Metadata\GraphQl\Mutation;
use ApiPlatform\Metadata\GraphQl\Query;
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\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Metadata\ApiProperty;
use App\Containers\CompanySection\EmployeeContainer\Entities\EmployeeEntity;
use App\Containers\CrmSection\TaskContainer\Data\Repositories\TaskRepository;
use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
use App\Containers\SettingSection\ListContainer\Entities\TaskTypeEntity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
#[ORM\Entity(repositoryClass: TaskRepository::class)]
#[ORM\Table(name: '`crm_tasks`')]
#[ApiResource(
routePrefix: '/crm',
operations: [
new GetCollection(
uriTemplate: '/tasks',
openapiContext: [
"summary" => ""
]
),
new Get(
uriTemplate: '/tasks/{id}',
openapiContext: [
"summary" => ""
]
),
new Post(
uriTemplate: '/tasks',
openapiContext: [
"summary" => ""
]
),
new Patch(
uriTemplate: '/tasks/{id}',
openapiContext: [
"summary" => ""
]
),
new Put(
uriTemplate: '/tasks/{id}',
openapiContext: [
"summary" => ""
]
),
new Delete(
uriTemplate: '/tasks/{id}',
openapiContext: [
"summary" => ""
]
)
],
normalizationContext: ['groups' => ['read'], 'enable_max_depth' => true],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')",
shortName: 'CRM_Tasks'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'title' => 'partial',
'manager' => 'exact',
'responsible' => 'exact',
'material' => 'exact',
'status' => 'exact',
'client' => 'exact',
'contract' => 'exact',
'type' => 'exact'
])]
#[ApiFilter(DateFilter::class, properties: ['dateDeadline', 'dateCompletion'])]
#[ApiFilter(OrderFilter::class)]
class TaskEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
// Заголовок
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
#[Groups(['read'])]
private string $title;
// Клиент
#[ORM\ManyToOne(targetEntity: ClientEntity::class)]
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?ClientEntity $client = null;
// Договор
#[ORM\ManyToOne(targetEntity: ContractEntity::class)]
#[ORM\JoinColumn(name: 'contract_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?ContractEntity $contract = null;
// Дата крайнего срока
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['read'])]
private ?\DateTimeInterface $dateDeadline = null;
// Статус
#[ORM\ManyToOne(targetEntity: StatusEntity::class)]
#[ORM\JoinColumn(name: 'status_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ?StatusEntity $status = null;
// Тип задачи
#[ORM\ManyToOne(targetEntity: TaskTypeEntity::class)]
#[ORM\JoinColumn(name: 'type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ?TaskTypeEntity $type = null;
// Постановщик
#[ORM\ManyToOne(targetEntity: EmployeeEntity::class)]
#[ORM\JoinColumn(name: 'manager_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[ApiProperty(push: true)]
#[MaxDepth(2)]
private ?EmployeeEntity $manager = null;
// Ответственный
#[ORM\ManyToOne(targetEntity: EmployeeEntity::class)]
#[ORM\JoinColumn(name: 'responsible_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ?EmployeeEntity $responsible = null;
// Описание
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['read'])]
private ?string $description = null;
// Дата завершения
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['read'])]
private ?\DateTimeInterface $dateCompletion = 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;
public function getId()
{
return $this->id;
}
public function getTitle()
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function getContract()
{
return $this->contract;
}
public function setContract($contract)
{
$this->contract = $contract;
return $this;
}
public function getClient()
{
return $this->client;
}
public function setClient($client)
{
$this->client = $client;
return $this;
}
public function getDateDeadline()
{
return $this->dateDeadline;
}
public function setDateDeadline(\DateTimeImmutable|null $date)
{
$this->dateDeadline = $date;
return $this;
}
public function getStatus()
{
return $this->status;
}
public function setStatus($status)
{
$this->status = $status;
return $this;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
$this->type = $type;
return $this;
}
public function getManager()
{
return $this->manager;
}
public function setManager($manager)
{
$this->manager = $manager;
return $this;
}
public function getResponsible()
{
return $this->responsible;
}
public function setResponsible($responsible)
{
$this->responsible = $responsible;
return $this;
}
public function getDescription()
{
return $this->description;
}
public function setDescription(?string $description)
{
$this->description = $description;
return $this;
}
public function getDateCompletion()
{
return $this->dateCompletion;
}
public function setDateCompletion(\DateTimeImmutable|null $date)
{
$this->dateCompletion = $date;
return $this;
}
}