VoiceCallAuditLogCommand.php
1.33 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
<?php
namespace NexmoBundle\Event\Logger;
use AppBundle\Entity\User;
use AppBundle\Entity\VoiceCall;
use AppBundle\Event\VoiceCallEvent;
use Symfony\Component\EventDispatcher\Event;
abstract class VoiceCallAuditLogCommand
{
/**
* @var VoiceCallEvent
*/
protected $event;
/**
* @var VoiceCall
*/
protected $voiceCallLog;
protected $logData = [];
public function isProcessable()
{
$this->event = $this->event instanceof VoiceCallEvent ? $this->event : null;
$this->voiceCallLog = $this->event ? $this->event->getVoiceCall() : null;
return $this->event && $this->voiceCallLog instanceof VoiceCall && $this->voiceCallLog->getDuration() > 0;
}
abstract protected function buildLogData();
protected function commonLogData()
{
/**
* actor, currently our webhook sets caller as the employee and recipient as the employee
*/
return array(
"actionDateTime" => new \DateTime(),
"actor" => $this->event->getVoiceCall()->getRecipient()
);
}
final public function resolve(Event $event)
{
$this->event = $event;
if ($this->isProcessable()) {
$this->logData = array_merge($this->commonLogData(), $this->buildLogData()) ;
}
return $this->logData;
}
}