1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LivePersonInc\LiveEngageLaravel\Collections; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel; |
7
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Conversation; |
8
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Info; |
9
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Visitor; |
10
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Campaign; |
11
|
|
|
|
12
|
|
|
class ConversationHistory extends Collection |
13
|
|
|
{ |
14
|
|
|
private $instance; |
15
|
|
|
|
16
|
|
|
public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
17
|
|
|
{ |
18
|
|
|
$this->instance = $instance; |
19
|
|
|
|
20
|
|
|
parent::__construct($models); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function find($engagementID) |
24
|
|
|
{ |
25
|
|
|
$result = $this->filter(function ($value, $key) use ($engagementID) { |
|
|
|
|
26
|
|
|
return $value->info->conversationId == $engagementID; |
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
return $result->first(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function next() |
33
|
|
|
{ |
34
|
|
|
if (! $this->instance) { |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$instance = $this->instance; |
39
|
|
|
|
40
|
|
|
$next = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->next); |
|
|
|
|
41
|
|
|
if (property_exists($next->_metadata, 'next')) { |
|
|
|
|
42
|
|
|
$instance->next = $next->_metadata->next->href; |
43
|
|
|
|
44
|
|
|
$history = []; |
45
|
|
|
foreach ($next->conversationHistoryRecords as $item) { |
|
|
|
|
46
|
|
|
if (property_exists($item, 'info')) { |
47
|
|
|
$item->info = new Info((array) $item->info); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (property_exists($item, 'visitorInfo')) { |
51
|
|
|
$item->visitorInfo = new Visitor((array) $item->visitorInfo); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (property_exists($item, 'campaign')) { |
55
|
|
|
$item->campaign = new Campaign((array) $item->campaign); |
56
|
|
|
} |
57
|
|
|
$history[] = new Conversation((array) $item); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->merge(new self($history)); |
61
|
|
|
} else { |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function prev() |
67
|
|
|
{ |
68
|
|
|
if (! $this->instance) { |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$instance = $this->instance; |
73
|
|
|
|
74
|
|
|
$prev = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->prev); |
|
|
|
|
75
|
|
|
if (property_exists($prev->_metadata, 'prev')) { |
|
|
|
|
76
|
|
|
$instance->prev = $prev->_metadata->prev->href; |
77
|
|
|
|
78
|
|
|
$history = []; |
79
|
|
|
foreach ($next->conversationHistoryRecords as $item) { |
|
|
|
|
80
|
|
|
if (property_exists($item, 'info')) { |
81
|
|
|
$item->info = new Info((array) $item->info); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (property_exists($item, 'visitorInfo')) { |
85
|
|
|
$item->visitorInfo = new Visitor((array) $item->visitorInfo); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (property_exists($item, 'campaign')) { |
89
|
|
|
$item->campaign = new Campaign((array) $item->campaign); |
90
|
|
|
} |
91
|
|
|
$history[] = new Conversation((array) $item); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $this->merge(new self($history)); |
95
|
|
|
} else { |
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getMetaDataAttribute() |
101
|
|
|
{ |
102
|
|
|
return $this->attributes['_metaData']; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setMetaDataAttribute($value) |
106
|
|
|
{ |
107
|
|
|
$this->attributes['_metaData'] = $value; |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.