src/Containers/CrmSection/TelephonyContainer/Entities/CallEntity.php line 321

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\TelephonyContainer\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\DateFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  16. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Doctrine\DBAL\Types\Types;
  19. use Gedmo\Mapping\Annotation as Gedmo;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use Symfony\Component\Serializer\Annotation\MaxDepth;
  22. use Symfony\Component\Serializer\Annotation\Context;
  23. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  24. use App\Ship\Utils\FormattingUtil;
  25. use App\Containers\CrmSection\TelephonyContainer\Data\Repositories\CallRepository;
  26. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  27. use App\Containers\SettingSection\ListContainer\Entities\CallTypeEntity;
  28. use App\Containers\SettingSection\ListContainer\Entities\CallStateEntity;
  29. use App\Containers\CrmSection\TelephonyContainer\UI\ApiPlatform\Controllers\PostBinotelOutgoingCallController;
  30. use App\Containers\CrmSection\TelephonyContainer\UI\ApiPlatform\Controllers\Public\PostBinotelCallStartController;
  31. use App\Containers\CrmSection\TelephonyContainer\UI\ApiPlatform\Controllers\Public\PostBinotelCallEndController;
  32. use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
  33. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  34. /** 
  35.  * Звонок
  36. */
  37. #[ApiResource(
  38.     normalizationContext: [
  39.         'groups' => 'read',
  40.         'enable_max_depth' => true
  41.     ],
  42.     operations: [
  43.         new Get(
  44.             uriTemplate'/crm/calls/{id}'requirements: ['id' => '\d+'],
  45.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  46.         ),
  47.         new Patch(
  48.             uriTemplate'/crm/calls/{id}'requirements: ['id' => '\d+'],
  49.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
  50.         ),
  51.         // new Put(
  52.         //     uriTemplate: '/calls/{id}', requirements: ['id' => '\d+'],
  53.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
  54.         // ),
  55.         new Delete(
  56.             uriTemplate'/crm/calls/{id}'requirements: ['id' => '\d+'],
  57.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
  58.         ),
  59.         // new Post(
  60.         //     uriTemplate: '/calls',
  61.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
  62.         // ),
  63.         new GetCollection(
  64.             uriTemplate'/crm/calls',
  65.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  66.         ),
  67.         new Post(
  68.             uriTemplate'/crm/calls/binotel_call/outgoing',
  69.             controllerPostBinotelOutgoingCallController::class,
  70.             deserializefalse,
  71.             serializefalse,
  72.             openapiContext: [
  73.                 "summary" => "Initiation of outgoing call from Binotel",
  74.                 "description" => "",
  75.                 'parameters' => [
  76.                     [
  77.                         'in' => 'query',
  78.                         'name' => 'externalNumber',
  79.                         'required' => true,
  80.                         'schema' => [
  81.                             'type' => 'string'
  82.                         ]
  83.                     ]
  84.                 ],
  85.                 'requestBody' => [
  86.                     'required' => false,
  87.                     'content' => []
  88.                 ],
  89.                 'responses' => [
  90.                     '200' => [
  91.                         'description' => '',
  92.                         'content' => [
  93.                             'application/json' => [
  94.                                 'schema' => [
  95.                                     'type' => 'object',
  96.                                     'properties' => [
  97.                                         'externalCallId' => [
  98.                                             'type' => 'string',
  99.                                             'readOnly' => true
  100.                                         ]
  101.                                     ]
  102.                                 ]
  103.                             ]
  104.                         ]
  105.                     ]
  106.                 ]
  107.             ],
  108.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER')"
  109.         ),
  110.         new Post(
  111.             uriTemplate'/public/binotel_call/start',
  112.             controllerPostBinotelCallStartController::class,
  113.             deserializefalse,
  114.             serializefalse,
  115.             openapiContext: [
  116.                 "summary" => "Initiating a phone call from Binotel",
  117.                 "description" => "",
  118.                 'parameters' => [
  119.                     [
  120.                         'in' => 'query',
  121.                         'name' => 'externalNumber',
  122.                         'required' => true,
  123.                         'schema' => [
  124.                             'type' => 'string'
  125.                         ]
  126.                     ]
  127.                 ],
  128.                 'requestBody' => [
  129.                     'required' => false,
  130.                     'content' => []
  131.                 ],
  132.                 'responses' => [
  133.                     '200' => [
  134.                         'description' => '',
  135.                         'content' => [
  136.                             'application/json' => [
  137.                                 'schema' => [
  138.                                     'type' => 'object',
  139.                                     'properties' => [
  140.                                         'customerData' => [
  141.                                             'type' => 'object',
  142.                                             'properties' => [
  143.                                                 'name' => [
  144.                                                     'type' => 'string',
  145.                                                     'readOnly' => true
  146.                                                 ],
  147.                                                 'description' => [
  148.                                                     'type' => 'string',
  149.                                                     'readOnly' => true
  150.                                                 ],
  151.                                                 'linkToCrmUrl' => [
  152.                                                     'type' => 'string',
  153.                                                     'readOnly' => true
  154.                                                 ],
  155.                                                 'assignedToEmployeeEmail' => [
  156.                                                     'type' => 'string',
  157.                                                     'readOnly' => true
  158.                                                 ]
  159.                                             ]
  160.                                         ]
  161.                                     ]
  162.                                 ]
  163.                             ]
  164.                         ]
  165.                     ]
  166.                 ]
  167.             ]
  168.         ),
  169.         new Post(
  170.             uriTemplate'/public/binotel_call/end',
  171.             controllerPostBinotelCallEndController::class,
  172.             deserializefalse,
  173.             serializefalse,
  174.             openapiContext: [
  175.                 "summary" => "Ending a phone call from Binotel",
  176.                 "description" => "",
  177.                 'parameters' => [
  178.                     [
  179.                         'in' => 'query',
  180.                         'name' => 'attemptsCounter',
  181.                         'required' => false,
  182.                         'schema' => [
  183.                             'type' => 'string'
  184.                         ]
  185.                     ],
  186.                     [
  187.                         'in' => 'query',
  188.                         'name' => 'callDetails[externalNumber]',
  189.                         'required' => true,
  190.                         'schema' => [
  191.                             'type' => 'string'
  192.                         ]
  193.                     ],
  194.                     [
  195.                         'in' => 'query',
  196.                         'name' => 'callDetails[callType]',
  197.                         'required' => true,
  198.                         'schema' => [
  199.                             'type' => 'string'
  200.                         ]
  201.                     ],
  202.                     [
  203.                         'in' => 'query',
  204.                         'name' => 'callDetails[generalCallID]',
  205.                         'required' => true,
  206.                         'schema' => [
  207.                             'type' => 'string'
  208.                         ]
  209.                     ],
  210.                     [
  211.                         'in' => 'query',
  212.                         'name' => 'callDetails[startTime]',
  213.                         'required' => false,
  214.                         'schema' => [
  215.                             'type' => 'string'
  216.                         ]
  217.                     ],
  218.                     [
  219.                         'in' => 'query',
  220.                         'name' => 'callDetails[internalNumber]',
  221.                         'required' => false,
  222.                         'schema' => [
  223.                             'type' => 'string'
  224.                         ]
  225.                     ],
  226.                     [
  227.                         'in' => 'query',
  228.                         'name' => 'callDetails[waitsec]',
  229.                         'required' => false,
  230.                         'schema' => [
  231.                             'type' => 'string'
  232.                         ]
  233.                     ],
  234.                     [
  235.                         'in' => 'query',
  236.                         'name' => 'callDetails[billsec]',
  237.                         'required' => false,
  238.                         'schema' => [
  239.                             'type' => 'string'
  240.                         ]
  241.                     ],
  242.                     [
  243.                         'in' => 'query',
  244.                         'name' => 'callDetails[disposition]',
  245.                         'required' => false,
  246.                         'schema' => [
  247.                             'type' => 'string'
  248.                         ]
  249.                     ],
  250.                     [
  251.                         'in' => 'query',
  252.                         'name' => 'callDetails[pbxNumberData][number]',
  253.                         'required' => false,
  254.                         'schema' => [
  255.                             'type' => 'string'
  256.                         ]
  257.                     ]
  258.                 ],
  259.                 'requestBody' => [
  260.                     'required' => false,
  261.                     'content' => []
  262.                 ],
  263.                 'responses' => [
  264.                     '201' => [
  265.                         'description' => '',
  266.                         'content' => [
  267.                             'application/json' => [
  268.                                 'schema' => [
  269.                                     'type' => 'object',
  270.                                     'properties' => [
  271.                                         'status' => [
  272.                                             'type' => 'string',
  273.                                             'readOnly' => true
  274.                                         ]
  275.                                     ]
  276.                                 ]
  277.                             ]
  278.                         ]
  279.                     ]
  280.                 ]
  281.             ]
  282.         )
  283.     ],
  284.     shortName'CRM_Calls'
  285. )]
  286. #[ApiFilter(SearchFilter::class, properties: [
  287.     'id' => 'exact'
  288.     'externalCode' => 'partial',
  289.     'externalCallId' => 'partial',
  290.     'client' => 'exact',
  291.     'type' => 'exact',
  292.     'state' => 'exact',
  293.     'incomingPhone' => 'partial',
  294.     'internalPhone' => 'partial',
  295.     'externalPhone' => 'partial',
  296.     'client.name' => 'partial'
  297.     'client.lastName' => 'partial'
  298.     'client.patronymic' => 'partial'
  299.     'client.externalCode' => 'partial',
  300.     'client.phone' => 'exact',
  301.     'client.email' => 'exact',
  302.     'client.inn' => 'exact',
  303.     'type.name' => 'exact',
  304.     'type.code' => 'exact',
  305.     'state.name' => 'exact',
  306.     'state.code' => 'exact'
  307. ])]
  308. #[ApiFilter(NumericFilter::class, properties: ['id''attemptsCounter''callWaitSec''callDurationSec'])]
  309. #[ApiFilter(RangeFilter::class, properties: ['id''attemptsCounter''callWaitSec''callDurationSec'])]
  310. #[ApiFilter(DateFilter::class, properties: ['dateStart'])]
  311. #[ApiFilter(OrderFilter::class)]
  312. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  313.     'externalCode''externalCallId''incomingPhone''internalPhone''externalPhone'])]
  314. #[ORM\Entity(repositoryClassCallRepository::class)]
  315. #[ORM\Table(name'`crm_calls`')]
  316. #[ORM\Index(columns: ['external_call_id'], name'crm_calls_custom_idx')]
  317. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  318. class CallEntity
  319. {   
  320.     #[ORM\Id]
  321.     #[ORM\GeneratedValue]
  322.     #[ORM\Column(typeTypes::INTEGER)]
  323.     #[Groups(['read'])]
  324.     private ?int $id null;
  325.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  326.     #[Groups(['read'])]
  327.     private ?string $externalCode null;
  328.     // Идентификатор звонка в телефонии
  329.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  330.     #[Groups(['read'])]
  331.     private ?string $externalCallId null;
  332.     // Тип звонка
  333.     #[ORM\ManyToOne(targetEntityCallTypeEntity::class)]
  334.     #[ORM\JoinColumn(name'call_type_id'referencedColumnName'id'nullablefalse)]
  335.     #[Groups(['read'])]
  336.     #[MaxDepth(1)]
  337.     private CallTypeEntity $type;
  338.     // Состояние звонка
  339.     #[ORM\ManyToOne(targetEntityCallStateEntity::class)]
  340.     #[ORM\JoinColumn(name'call_state_id'referencedColumnName'id'nullabletrue)]
  341.     #[Groups(['read'])]
  342.     #[MaxDepth(1)]
  343.     private ?CallStateEntity $state null;
  344.     // Дата начала звонка
  345.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  346.     #[Context(
  347.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  348.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  349.     )]
  350.     #[Groups(['read'])]
  351.     private ?\DateTimeInterface $dateStart null;
  352.     // Клиент
  353.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  354.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullabletrue)]
  355.     #[Groups(['read'])]
  356.     #[MaxDepth(2)]
  357.     private ?ClientEntity $client null;
  358.     // Номер, на который поступил звонок
  359.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  360.     #[Groups(['read'])]
  361.     private ?string $incomingPhone null;
  362.     // Внутренний номер сотрудника
  363.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  364.     #[Groups(['read'])]
  365.     private ?string $internalPhone null;
  366.     // Номер, с которого поступил звонок
  367.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  368.     #[Groups(['read'])]
  369.     private ?string $externalPhone null;
  370.     // Количество попыток соединения
  371.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  372.     #[Groups(['read'])]
  373.     private ?int $attemptsCounter null;
  374.     // Ожидание соединения
  375.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  376.     #[Groups(['read'])]
  377.     private ?int $callWaitSec null;
  378.     // Длительность разговора
  379.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  380.     #[Groups(['read'])]
  381.     private ?int $callDurationSec null;
  382.     // Комментарий
  383.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  384.     #[Gedmo\Translatable]
  385.     #[Groups(['read'])]
  386.     private ?string $comment null;
  387.     #[Gedmo\Timestampable(on'create')]
  388.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  389.     protected $createdAt;
  390.     #[Gedmo\Timestampable(on'update')]
  391.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  392.     protected $updatedAt;
  393.     /**
  394.      * Used locale to override Translation listener`s locale
  395.      * this is not a mapped field of entity metadata, just a simple property
  396.      */
  397.     #[Gedmo\Locale]
  398.     private $locale;
  399.     public function getId(): ?int
  400.     {
  401.         return $this->id;
  402.     }
  403.     public function getExternalCode()
  404.     {
  405.         return $this->externalCode;
  406.     }
  407.     public function setExternalCode($code)
  408.     {
  409.         $this->externalCode $code;
  410.         return $this;
  411.     }
  412.     public function getExternalCallId()
  413.     {
  414.         return $this->externalCallId;
  415.     }
  416.     public function setExternalCallId($callId)
  417.     {
  418.         $this->externalCallId $callId;
  419.         return $this;
  420.     }
  421.     public function getType()
  422.     {
  423.         return $this->type;
  424.     }
  425.     public function setType($type)
  426.     {
  427.         $this->type $type;
  428.         return $this;
  429.     }
  430.     public function getState()
  431.     {
  432.         return $this->state;
  433.     }
  434.     public function setState($state)
  435.     {
  436.         $this->state $state;
  437.         return $this;
  438.     }
  439.     public function setDateStart(\DateTimeImmutable|null $date)
  440.     {
  441.         $this->dateStart $date;
  442.         return $this;
  443.     }
  444.     public function getDateStart()
  445.     {
  446.         return $this->dateStart;
  447.     }
  448.  
  449.     public function getClient()
  450.     {
  451.         return $this->client;
  452.     }
  453.     public function setClient($client)
  454.     {
  455.         $this->client $client;
  456.         return $this;
  457.     }
  458.     public function getIncomingPhone()
  459.     {
  460.         return $this->incomingPhone;
  461.     }
  462.     public function setIncomingPhone($value)
  463.     {
  464.         $this->incomingPhone = (!empty($value))
  465.             ? FormattingUtil::phoneNumber($value)
  466.             : $value;
  467.         return $this;
  468.     }
  469.     public function getInternalPhone()
  470.     {
  471.         return $this->internalPhone;
  472.     }
  473.     public function setInternalPhone($value)
  474.     {
  475.         $this->internalPhone = (!empty($value))
  476.             ? FormattingUtil::phoneNumber($value)
  477.             : $value;
  478.         return $this;
  479.     }
  480.     public function getExternalPhone()
  481.     {
  482.         return $this->externalPhone;
  483.     }
  484.     public function setExternalPhone($value)
  485.     {
  486.         $this->externalPhone = (!empty($value))
  487.             ? FormattingUtil::phoneNumber($value)
  488.             : $value;
  489.         return $this;
  490.     }
  491.     public function getAttemptsCounter()
  492.     {
  493.         return $this->attemptsCounter;
  494.     }
  495.     public function setAttemptsCounter($value)
  496.     {
  497.         $this->attemptsCounter $value;
  498.         return $this;
  499.     }
  500.     public function getCallWaitSec()
  501.     {
  502.         return $this->callWaitSec;
  503.     }
  504.     public function setCallWaitSec($sec)
  505.     {
  506.         $this->callWaitSec $sec;
  507.         return $this;
  508.     }
  509.     public function getCallDurationSec()
  510.     {
  511.         return $this->callDurationSec;
  512.     }
  513.     public function setCallDurationSec($sec)
  514.     {
  515.         $this->callDurationSec $sec;
  516.         return $this;
  517.     }
  518.     public function getComment()
  519.     {
  520.         return $this->comment;
  521.     }
  522.     public function setComment($comment)
  523.     {
  524.         $this->comment $comment;
  525.         return $this;
  526.     }
  527.     public function setTranslatableLocale($locale)
  528.     {
  529.         $this->locale $locale;
  530.     }
  531. }