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