1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Conversation |
4
|
|
|
* |
5
|
|
|
* @package LivePersonInc\LiveEngageLaravel\Models |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace LivePersonInc\LiveEngageLaravel\Models; |
9
|
|
|
|
10
|
|
|
use Illuminate\Database\Eloquent\Model; |
11
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\AgentParticipants; |
12
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\ConsumerParticipants; |
13
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\Transfers; |
14
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\Transcript; |
15
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\SDEs; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Conversation class. |
19
|
|
|
* |
20
|
|
|
* @extends Model |
21
|
|
|
*/ |
22
|
|
|
class Conversation extends Model |
23
|
|
|
{ |
24
|
|
|
protected $guarded = []; |
25
|
|
|
|
26
|
|
|
protected $appends = [ |
27
|
|
|
'textTranscript', |
28
|
|
|
]; |
29
|
|
|
|
30
|
2 |
|
public function __construct(array $item) |
31
|
|
|
{ |
32
|
2 |
|
|
33
|
2 |
|
|
34
|
2 |
|
$init = [ |
35
|
2 |
|
'info' => [], |
36
|
2 |
|
'visitorInfo' => [], |
37
|
2 |
|
'campaign' => [], |
38
|
2 |
|
'transfers' => [], |
39
|
2 |
|
'agentParticipants' => [], |
40
|
|
|
'consumerParticipants' => [], |
41
|
2 |
|
'messageRecords' => [], |
42
|
2 |
|
'monitoring' => [], |
43
|
|
|
'sdes' => new SDE(), |
44
|
|
|
'unAuthSdes' => new SDE(), |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
$item = array_merge($init, $item); |
48
|
|
|
|
49
|
|
|
$item['info'] = new MessagingInfo((array) $item['info']); |
50
|
|
|
$item['monitoring'] = new MessagingInfo((array) $item['monitoring']); |
51
|
|
|
$item['visitorInfo'] = new Visitor((array) $item['visitorInfo']); |
52
|
|
|
$item['campaign'] = new Campaign((array) $item['campaign']); |
53
|
|
|
$item['transfers'] = new Transfers($item['transfers']); |
54
|
|
|
$item['agentParticipants'] = new AgentParticipants($item['agentParticipants']); |
55
|
|
|
$item['consumerParticipants'] = new ConsumerParticipants($item['consumerParticipants']); |
56
|
|
|
$item['messageRecords'] = new Transcript($item['messageRecords'], $item['agentParticipants']); |
57
|
|
|
$item['sdes'] = new SDEs($item['sdes']->events ?: []); |
58
|
|
|
$item['unAuthSdes'] = new SDEs($item['unAuthSdes']->events ?: []); |
59
|
|
|
|
60
|
|
|
parent::__construct($item); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/*public function getInfoAttribute() |
64
|
|
|
{ |
65
|
|
|
return new MessagingInfo((array) $this->attributes['info']); |
66
|
|
|
}*/ |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @codeCoverageIgnore |
70
|
|
|
*/ |
71
|
|
|
public function getTextTranscriptAttribute() |
72
|
|
|
{ |
73
|
|
|
return $this->messageRecords->textTranscript(); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @codeCoverageIgnore |
78
|
|
|
*/ |
79
|
|
|
public function getExportAttribute() |
80
|
|
|
{ |
81
|
|
|
$info = $this->info->attributes; |
|
|
|
|
82
|
|
|
$info['transcript'] = $this->textTranscript; |
83
|
|
|
return ((object)$info); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function extractEmail() |
87
|
|
|
{ |
88
|
|
|
$matches = []; |
89
|
|
|
$pattern = '/[.A-Za-z0-9_-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][.A-Za-z0-9_]+)/'; //regex for pattern of e-mail address |
90
|
|
|
preg_match_all($pattern, $this->textTranscript, $matches); |
91
|
|
|
return count($matches) ? $matches[0] : null; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.