<?php
namespace App\Containers\CrmSection\TelephonyContainer\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\DateFilter;
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 Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use App\Ship\Utils\FormattingUtil;
use App\Containers\CrmSection\TelephonyContainer\Data\Repositories\CallRepository;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\SettingSection\ListContainer\Entities\CallTypeEntity;
use App\Containers\SettingSection\ListContainer\Entities\CallStateEntity;
use App\Containers\CrmSection\TelephonyContainer\UI\ApiPlatform\Controllers\PostBinotelOutgoingCallController;
use App\Containers\CrmSection\TelephonyContainer\UI\ApiPlatform\Controllers\Public\PostBinotelCallStartController;
use App\Containers\CrmSection\TelephonyContainer\UI\ApiPlatform\Controllers\Public\PostBinotelCallEndController;
use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Звонок
*/
#[ApiResource(
normalizationContext: [
'groups' => 'read',
'enable_max_depth' => true
],
operations: [
new Get(
uriTemplate: '/crm/calls/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/crm/calls/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
),
// new Put(
// uriTemplate: '/calls/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
// ),
new Delete(
uriTemplate: '/crm/calls/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
),
// new Post(
// uriTemplate: '/calls',
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
// ),
new GetCollection(
uriTemplate: '/crm/calls',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Post(
uriTemplate: '/crm/calls/binotel_call/outgoing',
controller: PostBinotelOutgoingCallController::class,
deserialize: false,
serialize: false,
openapiContext: [
"summary" => "Initiation of outgoing call from Binotel",
"description" => "",
'parameters' => [
[
'in' => 'query',
'name' => 'externalNumber',
'required' => true,
'schema' => [
'type' => 'string'
]
]
],
'requestBody' => [
'required' => false,
'content' => []
],
'responses' => [
'200' => [
'description' => '',
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'externalCallId' => [
'type' => 'string',
'readOnly' => true
]
]
]
]
]
]
]
],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
),
new Post(
uriTemplate: '/public/binotel_call/start',
controller: PostBinotelCallStartController::class,
deserialize: false,
serialize: false,
openapiContext: [
"summary" => "Initiating a phone call from Binotel",
"description" => "",
'parameters' => [
[
'in' => 'query',
'name' => 'externalNumber',
'required' => true,
'schema' => [
'type' => 'string'
]
]
],
'requestBody' => [
'required' => false,
'content' => []
],
'responses' => [
'200' => [
'description' => '',
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'customerData' => [
'type' => 'object',
'properties' => [
'name' => [
'type' => 'string',
'readOnly' => true
],
'description' => [
'type' => 'string',
'readOnly' => true
],
'linkToCrmUrl' => [
'type' => 'string',
'readOnly' => true
],
'assignedToEmployeeEmail' => [
'type' => 'string',
'readOnly' => true
]
]
]
]
]
]
]
]
]
]
),
new Post(
uriTemplate: '/public/binotel_call/end',
controller: PostBinotelCallEndController::class,
deserialize: false,
serialize: false,
openapiContext: [
"summary" => "Ending a phone call from Binotel",
"description" => "",
'parameters' => [
[
'in' => 'query',
'name' => 'attemptsCounter',
'required' => false,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[externalNumber]',
'required' => true,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[callType]',
'required' => true,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[generalCallID]',
'required' => true,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[startTime]',
'required' => false,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[internalNumber]',
'required' => false,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[waitsec]',
'required' => false,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[billsec]',
'required' => false,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[disposition]',
'required' => false,
'schema' => [
'type' => 'string'
]
],
[
'in' => 'query',
'name' => 'callDetails[pbxNumberData][number]',
'required' => false,
'schema' => [
'type' => 'string'
]
]
],
'requestBody' => [
'required' => false,
'content' => []
],
'responses' => [
'201' => [
'description' => '',
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'status' => [
'type' => 'string',
'readOnly' => true
]
]
]
]
]
]
]
]
)
],
shortName: 'CRM_Calls'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'externalCode' => 'partial',
'externalCallId' => 'partial',
'client' => 'exact',
'type' => 'exact',
'state' => 'exact',
'incomingPhone' => 'partial',
'internalPhone' => 'partial',
'externalPhone' => 'partial',
'client.name' => 'partial',
'client.lastName' => 'partial',
'client.patronymic' => 'partial',
'client.externalCode' => 'partial',
'client.phone' => 'exact',
'client.email' => 'exact',
'client.inn' => 'exact',
'type.name' => 'exact',
'type.code' => 'exact',
'state.name' => 'exact',
'state.code' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: ['id', 'attemptsCounter', 'callWaitSec', 'callDurationSec'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'attemptsCounter', 'callWaitSec', 'callDurationSec'])]
#[ApiFilter(DateFilter::class, properties: ['dateStart'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'externalCode', 'externalCallId', 'incomingPhone', 'internalPhone', 'externalPhone'])]
#[ORM\Entity(repositoryClass: CallRepository::class)]
#[ORM\Table(name: '`crm_calls`')]
#[ORM\Index(columns: ['external_call_id'], name: 'crm_calls_custom_idx')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class CallEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $externalCode = null;
// Идентификатор звонка в телефонии
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $externalCallId = null;
// Тип звонка
#[ORM\ManyToOne(targetEntity: CallTypeEntity::class)]
#[ORM\JoinColumn(name: 'call_type_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(1)]
private CallTypeEntity $type;
// Состояние звонка
#[ORM\ManyToOne(targetEntity: CallStateEntity::class)]
#[ORM\JoinColumn(name: 'call_state_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?CallStateEntity $state = 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 $dateStart = null;
// Клиент
#[ORM\ManyToOne(targetEntity: ClientEntity::class)]
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ?ClientEntity $client = null;
// Номер, на который поступил звонок
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Groups(['read'])]
private ?string $incomingPhone = null;
// Внутренний номер сотрудника
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Groups(['read'])]
private ?string $internalPhone = null;
// Номер, с которого поступил звонок
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Groups(['read'])]
private ?string $externalPhone = null;
// Количество попыток соединения
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $attemptsCounter = null;
// Ожидание соединения
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $callWaitSec = null;
// Длительность разговора
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $callDurationSec = null;
// Комментарий
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $comment = 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(): ?int
{
return $this->id;
}
public function getExternalCode()
{
return $this->externalCode;
}
public function setExternalCode($code)
{
$this->externalCode = $code;
return $this;
}
public function getExternalCallId()
{
return $this->externalCallId;
}
public function setExternalCallId($callId)
{
$this->externalCallId = $callId;
return $this;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
$this->type = $type;
return $this;
}
public function getState()
{
return $this->state;
}
public function setState($state)
{
$this->state = $state;
return $this;
}
public function setDateStart(\DateTimeImmutable|null $date)
{
$this->dateStart = $date;
return $this;
}
public function getDateStart()
{
return $this->dateStart;
}
public function getClient()
{
return $this->client;
}
public function setClient($client)
{
$this->client = $client;
return $this;
}
public function getIncomingPhone()
{
return $this->incomingPhone;
}
public function setIncomingPhone($value)
{
$this->incomingPhone = (!empty($value))
? FormattingUtil::phoneNumber($value)
: $value;
return $this;
}
public function getInternalPhone()
{
return $this->internalPhone;
}
public function setInternalPhone($value)
{
$this->internalPhone = (!empty($value))
? FormattingUtil::phoneNumber($value)
: $value;
return $this;
}
public function getExternalPhone()
{
return $this->externalPhone;
}
public function setExternalPhone($value)
{
$this->externalPhone = (!empty($value))
? FormattingUtil::phoneNumber($value)
: $value;
return $this;
}
public function getAttemptsCounter()
{
return $this->attemptsCounter;
}
public function setAttemptsCounter($value)
{
$this->attemptsCounter = $value;
return $this;
}
public function getCallWaitSec()
{
return $this->callWaitSec;
}
public function setCallWaitSec($sec)
{
$this->callWaitSec = $sec;
return $this;
}
public function getCallDurationSec()
{
return $this->callDurationSec;
}
public function setCallDurationSec($sec)
{
$this->callDurationSec = $sec;
return $this;
}
public function getComment()
{
return $this->comment;
}
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}