@@ -14,8 +14,8 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class TaskRepository extends ServiceEntityRepository |
| 16 | 16 | { |
| 17 | - public function __construct(ManagerRegistry $registry) |
|
| 18 | - { |
|
| 17 | + public function __construct(ManagerRegistry $registry) |
|
| 18 | + { |
|
| 19 | 19 | parent::__construct($registry, Task::class); |
| 20 | - } |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -14,8 +14,8 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class TaskInterationRepository extends ServiceEntityRepository |
| 16 | 16 | { |
| 17 | - public function __construct(ManagerRegistry $registry) |
|
| 18 | - { |
|
| 17 | + public function __construct(ManagerRegistry $registry) |
|
| 18 | + { |
|
| 19 | 19 | parent::__construct($registry, TaskInteration::class); |
| 20 | - } |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -13,21 +13,21 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class TaskService |
| 15 | 15 | { |
| 16 | - private $request; |
|
| 16 | + private $request; |
|
| 17 | 17 | |
| 18 | - public function __construct( |
|
| 18 | + public function __construct( |
|
| 19 | 19 | private EntityManagerInterface $manager, |
| 20 | 20 | private Security $security, |
| 21 | 21 | private RequestStack $requestStack, |
| 22 | 22 | private StatusService $statusService, |
| 23 | 23 | private PeopleService $peopleService, |
| 24 | 24 | private FileService $fileService |
| 25 | - ) { |
|
| 25 | + ) { |
|
| 26 | 26 | $this->request = $this->requestStack->getCurrentRequest(); |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
|
| 30 | - { |
|
| 29 | + public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
|
| 30 | + { |
|
| 31 | 31 | |
| 32 | 32 | /* |
| 33 | 33 | $companies = $this->peopleService->getMyCompanies(); |
@@ -36,5 +36,5 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | 38 | //echo $queryBuilder->getQuery()->getSQL(); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -12,42 +12,42 @@ discard block |
||
| 12 | 12 | class TaskInterationService |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - public function __construct( |
|
| 15 | + public function __construct( |
|
| 16 | 16 | private EntityManagerInterface $manager, |
| 17 | 17 | private Security $security, |
| 18 | 18 | private StatusService $statusService, |
| 19 | 19 | private PeopleService $peopleService, |
| 20 | 20 | private FileService $fileService, |
| 21 | 21 | private IntegrationService $integrationService |
| 22 | - ) {} |
|
| 22 | + ) {} |
|
| 23 | 23 | |
| 24 | - public function addClientInteration(MessageInterface $message, People $provider, string $type): TaskInteration |
|
| 25 | - { |
|
| 24 | + public function addClientInteration(MessageInterface $message, People $provider, string $type): TaskInteration |
|
| 25 | + { |
|
| 26 | 26 | |
| 27 | 27 | $number = preg_replace('/\D/', '', $message->getOriginNumber()); |
| 28 | 28 | $name = ''; |
| 29 | 29 | $phone = [ |
| 30 | - 'ddi' => substr($number, 0, 2), |
|
| 31 | - 'ddd' => substr($number, 2, 2), |
|
| 32 | - 'phone' => substr($number, 4) |
|
| 30 | + 'ddi' => substr($number, 0, 2), |
|
| 31 | + 'ddd' => substr($number, 2, 2), |
|
| 32 | + 'phone' => substr($number, 4) |
|
| 33 | 33 | ]; |
| 34 | 34 | $registredBy = $this->peopleService->discoveryPeople(null, null, $phone, $name, null); |
| 35 | 35 | $task = $this->discoveryOpenTask($provider, $registredBy, $type, $number); |
| 36 | 36 | |
| 37 | 37 | return $this->addInteration($registredBy, $message, $task, $type, 'public'); |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function addInteration(People $registredBy, MessageInterface $message, Task $task, string $type, ?string $visibility = 'private') |
|
| 41 | - { |
|
| 40 | + public function addInteration(People $registredBy, MessageInterface $message, Task $task, string $type, ?string $visibility = 'private') |
|
| 41 | + { |
|
| 42 | 42 | |
| 43 | 43 | $file = null; |
| 44 | 44 | $media = $message->getMessageContent()->getMedia(); |
| 45 | 45 | if ($media) |
| 46 | - $file = $this->fileService->addFile( |
|
| 46 | + $file = $this->fileService->addFile( |
|
| 47 | 47 | $registredBy, |
| 48 | 48 | pack("C*", ...$media->getData()), |
| 49 | 49 | $type |
| 50 | - ); |
|
| 50 | + ); |
|
| 51 | 51 | |
| 52 | 52 | $taskInteration = new TaskInteration(); |
| 53 | 53 | $taskInteration->setTask($task); |
@@ -56,32 +56,32 @@ discard block |
||
| 56 | 56 | $taskInteration->setBody($message->getMessageContent()->getBody()); |
| 57 | 57 | $taskInteration->setRegisteredBy($registredBy); |
| 58 | 58 | if ($file) |
| 59 | - $taskInteration->setFile($file); |
|
| 59 | + $taskInteration->setFile($file); |
|
| 60 | 60 | |
| 61 | 61 | $this->manager->persist($taskInteration); |
| 62 | 62 | $this->manager->flush(); |
| 63 | 63 | |
| 64 | 64 | return $taskInteration; |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function discoveryOpenTask(People $provider, People $registredBy, string $type, ?string $announce = null): Task |
|
| 68 | - { |
|
| 67 | + public function discoveryOpenTask(People $provider, People $registredBy, string $type, ?string $announce = null): Task |
|
| 68 | + { |
|
| 69 | 69 | |
| 70 | 70 | $openStatus = $this->statusService->discoveryStatus('open', 'open', $type); |
| 71 | 71 | $pendingStatus = $this->statusService->discoveryStatus('pending', 'pending', $type); |
| 72 | 72 | |
| 73 | 73 | $task = $this->manager->getRepository(Task::class)->findOneBy([ |
| 74 | - 'taskStatus' => [$openStatus, $pendingStatus], |
|
| 75 | - 'provider' => $provider, |
|
| 76 | - 'registeredBy' => $registredBy, |
|
| 77 | - 'type' => $type |
|
| 74 | + 'taskStatus' => [$openStatus, $pendingStatus], |
|
| 75 | + 'provider' => $provider, |
|
| 76 | + 'registeredBy' => $registredBy, |
|
| 77 | + 'type' => $type |
|
| 78 | 78 | ]); |
| 79 | 79 | |
| 80 | 80 | if (!$task) { |
| 81 | - $task = new Task(); |
|
| 82 | - $task->setRegisteredBy($registredBy); |
|
| 83 | - $task->setProvider($provider); |
|
| 84 | - $task->settype($type); |
|
| 81 | + $task = new Task(); |
|
| 82 | + $task->setRegisteredBy($registredBy); |
|
| 83 | + $task->setProvider($provider); |
|
| 84 | + $task->settype($type); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | if ($announce) $task->addAnnounce($announce); |
@@ -90,39 +90,39 @@ discard block |
||
| 90 | 90 | $this->manager->flush(); |
| 91 | 91 | |
| 92 | 92 | return $task; |
| 93 | - } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function notifyClient(TaskInteration $taskInteration): TaskInteration |
|
| 96 | - { |
|
| 95 | + public function notifyClient(TaskInteration $taskInteration): TaskInteration |
|
| 96 | + { |
|
| 97 | 97 | |
| 98 | 98 | $task = $taskInteration->getTask(); |
| 99 | 99 | $origin = "551131360353"; |
| 100 | 100 | |
| 101 | 101 | foreach ($task->getAnnounce(true) as $destination) { |
| 102 | - if ($origin != $destination) { |
|
| 102 | + if ($origin != $destination) { |
|
| 103 | 103 | $message = json_encode([ |
| 104 | - "action" => "sendMessage", |
|
| 105 | - "origin" => $origin, |
|
| 106 | - "destination" => $destination, |
|
| 107 | - "message" => json_encode($taskInteration->getBody()), |
|
| 108 | - //"file" => $taskInteration->getFile() |
|
| 104 | + "action" => "sendMessage", |
|
| 105 | + "origin" => $origin, |
|
| 106 | + "destination" => $destination, |
|
| 107 | + "message" => json_encode($taskInteration->getBody()), |
|
| 108 | + //"file" => $taskInteration->getFile() |
|
| 109 | 109 | ]); |
| 110 | 110 | $this->integrationService->addIntegration($message, 'WhatsApp', null, null, $task->getProvider()); |
| 111 | - } |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | return $taskInteration; |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function prePersist(TaskInteration $taskInteration): TaskInteration |
|
| 118 | - { |
|
| 117 | + public function prePersist(TaskInteration $taskInteration): TaskInteration |
|
| 118 | + { |
|
| 119 | 119 | if (!$taskInteration->getRegisteredBy()) |
| 120 | - $taskInteration->setRegisteredBy($this->security->getToken()->getUser()->getPeople()); |
|
| 120 | + $taskInteration->setRegisteredBy($this->security->getToken()->getUser()->getPeople()); |
|
| 121 | 121 | return $taskInteration; |
| 122 | - } |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - public function posPersist(TaskInteration $taskInteration): TaskInteration |
|
| 125 | - { |
|
| 124 | + public function posPersist(TaskInteration $taskInteration): TaskInteration |
|
| 125 | + { |
|
| 126 | 126 | return $this->notifyClient($taskInteration); |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | 'ddd' => substr($number, 2, 2), |
| 32 | 32 | 'phone' => substr($number, 4) |
| 33 | 33 | ]; |
| 34 | - $registredBy = $this->peopleService->discoveryPeople(null, null, $phone, $name, null); |
|
| 34 | + $registredBy = $this->peopleService->discoveryPeople(null, null, $phone, $name, null); |
|
| 35 | 35 | $task = $this->discoveryOpenTask($provider, $registredBy, $type, $number); |
| 36 | 36 | |
| 37 | 37 | return $this->addInteration($registredBy, $message, $task, $type, 'public'); |
@@ -42,12 +42,13 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | $file = null; |
| 44 | 44 | $media = $message->getMessageContent()->getMedia(); |
| 45 | - if ($media) |
|
| 46 | - $file = $this->fileService->addFile( |
|
| 45 | + if ($media) { |
|
| 46 | + $file = $this->fileService->addFile( |
|
| 47 | 47 | $registredBy, |
| 48 | 48 | pack("C*", ...$media->getData()), |
| 49 | 49 | $type |
| 50 | 50 | ); |
| 51 | + } |
|
| 51 | 52 | |
| 52 | 53 | $taskInteration = new TaskInteration(); |
| 53 | 54 | $taskInteration->setTask($task); |
@@ -55,8 +56,9 @@ discard block |
||
| 55 | 56 | $taskInteration->setVisibility($visibility); |
| 56 | 57 | $taskInteration->setBody($message->getMessageContent()->getBody()); |
| 57 | 58 | $taskInteration->setRegisteredBy($registredBy); |
| 58 | - if ($file) |
|
| 59 | - $taskInteration->setFile($file); |
|
| 59 | + if ($file) { |
|
| 60 | + $taskInteration->setFile($file); |
|
| 61 | + } |
|
| 60 | 62 | |
| 61 | 63 | $this->manager->persist($taskInteration); |
| 62 | 64 | $this->manager->flush(); |
@@ -84,7 +86,9 @@ discard block |
||
| 84 | 86 | $task->settype($type); |
| 85 | 87 | } |
| 86 | 88 | |
| 87 | - if ($announce) $task->addAnnounce($announce); |
|
| 89 | + if ($announce) { |
|
| 90 | + $task->addAnnounce($announce); |
|
| 91 | + } |
|
| 88 | 92 | $task->setTaskStatus($openStatus); |
| 89 | 93 | $this->manager->persist($task); |
| 90 | 94 | $this->manager->flush(); |
@@ -116,8 +120,9 @@ discard block |
||
| 116 | 120 | |
| 117 | 121 | public function prePersist(TaskInteration $taskInteration): TaskInteration |
| 118 | 122 | { |
| 119 | - if (!$taskInteration->getRegisteredBy()) |
|
| 120 | - $taskInteration->setRegisteredBy($this->security->getToken()->getUser()->getPeople()); |
|
| 123 | + if (!$taskInteration->getRegisteredBy()) { |
|
| 124 | + $taskInteration->setRegisteredBy($this->security->getToken()->getUser()->getPeople()); |
|
| 125 | + } |
|
| 121 | 126 | return $taskInteration; |
| 122 | 127 | } |
| 123 | 128 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | { |
| 291 | 291 | return $this->alterDate; |
| 292 | 292 | } |
| 293 | - public function getAnnounce(bool $decode = false): string|array |
|
| 293 | + public function getAnnounce(bool $decode = false): string | array |
|
| 294 | 294 | { |
| 295 | 295 | // Ensure we're decoding a string, even if it was temporarily an array internally |
| 296 | 296 | $announceString = is_array($this->announce) ? json_encode($this->announce) : $this->announce; |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | return $this->setAnnounce($announce); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - public function setAnnounce(string|array|object $announce): self |
|
| 310 | + public function setAnnounce(string | array | object $announce): self |
|
| 311 | 311 | { |
| 312 | 312 | if (is_string($announce)) |
| 313 | 313 | $announce = json_decode($announce, true); |
@@ -301,16 +301,18 @@ |
||
| 301 | 301 | { |
| 302 | 302 | $announce = $this->getAnnounce(true); |
| 303 | 303 | |
| 304 | - if (!in_array($value, $announce)) |
|
| 305 | - array_push($announce, $value); |
|
| 304 | + if (!in_array($value, $announce)) { |
|
| 305 | + array_push($announce, $value); |
|
| 306 | + } |
|
| 306 | 307 | |
| 307 | 308 | return $this->setAnnounce($announce); |
| 308 | 309 | } |
| 309 | 310 | |
| 310 | 311 | public function setAnnounce(string|array|object $announce): self |
| 311 | 312 | { |
| 312 | - if (is_string($announce)) |
|
| 313 | - $announce = json_decode($announce, true); |
|
| 313 | + if (is_string($announce)) { |
|
| 314 | + $announce = json_decode($announce, true); |
|
| 315 | + } |
|
| 314 | 316 | |
| 315 | 317 | $this->announce = json_encode($announce); |
| 316 | 318 | return $this; |