UpdateVoiceCallStatusCommand.php
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace NexmoBundle\Event\Logger\Command;
use AppBundle\Entity\VoiceCall;
use Chromedia\AuditLogBundle\Entity\Action;
use Chromedia\AuditLogBundle\Entity\ObjectName;
use Chromedia\AuditLogBundle\Entity\ObjectType;
use NexmoBundle\Event\Logger\VoiceCallAuditLogCommand;
use NexmoBundle\VoiceCall\VoiceCallStatus;
class UpdateVoiceCallStatusCommand extends VoiceCallAuditLogCommand
{
public function isProcessable()
{
$knownStatus = [
VoiceCallStatus::STARTED,
VoiceCallStatus::COMPLETED,
VoiceCallStatus::FAILED,
VoiceCallStatus::BUSY
];
return parent::isProcessable() && \in_array($this->voiceCallLog->getStatus(), $knownStatus);
}
protected function buildLogData()
{
$actor = $this->voiceCallLog->getActor();
$data = [
// to show in patient logs, set object id to patient, object type account
"objectId" => $actor ? $actor->getId() : "Unknown",
"objectType" => ObjectType::ACCOUNT,
"objectName" => ObjectName::VOICE_CALL,
"actionStatus" => Action::STATUS_SUCCESS,
"subject" => $this->voiceCallLog->getActor()
? $this->voiceCallLog->getActor()->getProfile()->getFullName()
: "Anonymous",
];
$recipientName = $actor
? $this->voiceCallLog->getActor()->getProfile()->getFullName()
: "Unknown";
$statusHandlers = [
VoiceCallStatus::STARTED => function () use (&$data, $recipientName) {
$data["description"] = "started a voice call with {$recipientName}.";
$data["action"] = Action::STATUS_SUCCESS;
},
VoiceCallStatus::COMPLETED => function () use (&$data, $recipientName) {
$data["description"] = "completed a voice call with {$recipientName} ({$this->voiceCallLog->getFormattedDuration()}). ";
$data["action"] = Action::STATUS_SUCCESS;
},
VoiceCallStatus::FAILED => function () use (&$data, $recipientName) {
$data["description"] = "failed to complete a voice call with {$recipientName} ({$this->voiceCallLog->getFormattedDuration()}).";
$data["action"] = Action::STATUS_FAILURE;
},
VoiceCallStatus::BUSY => function () use (&$data, $recipientName) {
$data["description"] = "failed to complete a voice call with {$recipientName} ({$this->voiceCallLog->getFormattedDuration()}).";
$data["action"] = Action::STATUS_FAILURE;
},
];
if (array_key_exists($this->voiceCallLog->getStatus(), $statusHandlers)) {
$statusHandlers[$this->voiceCallLog->getStatus()]();
}
return $data;
}
}