1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LivePersonInc\LiveEngageLaravel\Collections; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel; |
7
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Engagement; |
8
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Info; |
9
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Visitor; |
10
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Campaign; |
11
|
|
|
|
12
|
|
|
class EngagementHistory extends Collection |
13
|
|
|
{ |
14
|
|
|
private $instance; |
15
|
|
|
|
16
|
|
|
public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
17
|
|
|
{ |
18
|
|
|
$this->instance = $instance; |
19
|
|
|
|
20
|
|
|
return parent::__construct($models); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function find($engagementID) |
24
|
|
|
{ |
25
|
|
|
$result = $this->filter(function ($value, $key) use ($engagementID) { |
|
|
|
|
26
|
|
|
return $value->info->sessionId == $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->retrieveHistory($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->interactionHistoryRecords as $item) { |
|
|
|
|
46
|
|
|
|
47
|
|
|
if (property_exists($item, 'info')) { |
48
|
|
|
$item->info = new Info((array) $item->info); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (property_exists($item, 'visitorInfo')) { |
52
|
|
|
$item->visitorInfo = new Visitor((array) $item->visitorInfo); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (property_exists($item, 'campaign')) { |
56
|
|
|
$item->campaign = new Campaign((array) $item->campaign); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$history[] = new Engagement((array) $item); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->merge(new EngagementHistory($history)); |
63
|
|
|
} else { |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function prev() |
69
|
|
|
{ |
70
|
|
|
if (! $this->instance) { |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$instance = $this->instance; |
75
|
|
|
|
76
|
|
|
$prev = $instance->retrieveHistory($instance->start, $instance->end, $instance->prev); |
|
|
|
|
77
|
|
|
if (property_exists($prev->_metadata, 'prev')) { |
|
|
|
|
78
|
|
|
$instance->prev = $prev->_metadata->prev->href; |
79
|
|
|
|
80
|
|
|
$history = []; |
81
|
|
|
foreach ($next->interactionHistoryRecords as $item) { |
|
|
|
|
82
|
|
|
|
83
|
|
|
if (property_exists($item, 'info')) { |
84
|
|
|
$item->info = new Info((array) $item->info); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (property_exists($item, 'visitorInfo')) { |
88
|
|
|
$item->visitorInfo = new Visitor((array) $item->visitorInfo); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (property_exists($item, 'campaign')) { |
92
|
|
|
$item->campaign = new Campaign((array) $item->campaign); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$history[] = new Engagement((array) $item); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->merge(new self($history)); |
99
|
|
|
} else { |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.