InboundVoiceCallCommand.php
2.51 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
<?php
namespace NexmoBundle\Event\Logger\Command;
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 InboundVoiceCallCommand extends VoiceCallAuditLogCommand
{
public function isProcessable()
{
return parent::isProcessable();
}
protected function buildLogData()
{
$actor = $this->voiceCallLog->getActor();
$subject = $actor
? $actor->getProfile()->getFullName()
: $this->voiceCallLog->getFromNumber();
$data = [
// to show in patient logs, set object id to patient, object type account
"objectId" => $actor ? $actor->getId() : null,
"objectType" => ObjectType::ACCOUNT,
"objectName" => ObjectName::VOICE_CALL,
"actionStatus" => Action::STATUS_SUCCESS,
"subject" => $subject
];
// actor will be admin recipient, since activity logs should always show in admin user's context
if ($actor) {
$data["actor"] = $this->voiceCallLog->getRecipient();
}
$statusHandlers = [
VoiceCallStatus::ANSWERED => function () use (&$data, $subject) {
$data["description"] = "{$subject} started an inbound call";
$data["action"] = Action::STATUS_SUCCESS;
},
VoiceCallStatus::COMPLETED => function () use (&$data, $subject) {
$data["description"] = "completed an inbound call with {$subject} with duration: ({$this->voiceCallLog->getFormattedDuration()}). ";
$data["action"] = Action::STATUS_SUCCESS;
},
VoiceCallStatus::FAILED => function () use (&$data, $subject) {
$data["description"] = "failed to complete an inbound call with {$subject} ({$this->voiceCallLog->getFormattedDuration()}).";
$data["action"] = Action::STATUS_FAILURE;
},
VoiceCallStatus::BUSY => function () use (&$data, $subject) {
$data["description"] = "failed to complete an inbound call with {$subject} ({$this->voiceCallLog->getFormattedDuration()}).";
$data["action"] = Action::STATUS_FAILURE;
},
];
if (array_key_exists($this->voiceCallLog->getStatus(), $statusHandlers)) {
$statusHandlers[$this->voiceCallLog->getStatus()]();
}
return $data;
}
}