@@ -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 postPersist(TaskInteration $taskInteration): TaskInteration |
|
125 | - { |
|
124 | + public function postPersist(TaskInteration $taskInteration): TaskInteration |
|
125 | + { |
|
126 | 126 | return $this->notifyClient($taskInteration); |
127 | - } |
|
127 | + } |
|
128 | 128 | } |