1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ConversationHistory |
4
|
|
|
* |
5
|
|
|
* @package LivePersonInc\LiveEngageLaravel\Collections |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace LivePersonInc\LiveEngageLaravel\Collections; |
9
|
|
|
|
10
|
|
|
use Illuminate\Support\Collection; |
11
|
|
|
use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel; |
12
|
|
|
use LivePersonInc\LiveEngageLaravel\Facades\LiveEngageLaravel as LiveEngage; |
13
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\MetaData; |
14
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Conversation; |
15
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Info; |
16
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Visitor; |
17
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Campaign; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ConversationHistory class. |
21
|
|
|
* |
22
|
|
|
* @extends Collection |
23
|
|
|
*/ |
24
|
|
|
class ConversationHistory extends Collection |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* metaData |
28
|
|
|
* |
29
|
|
|
* @var \LivePersonInc\LiveEngageLaravel\Models\MetaData |
30
|
|
|
* @access public |
31
|
|
|
*/ |
32
|
|
|
public $metaData; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* __construct function. |
36
|
|
|
* |
37
|
|
|
* @access public |
38
|
|
|
* @param array $models (default: []) |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
1 |
|
public function __construct(array $models = []) |
42
|
|
|
{ |
43
|
|
|
$models = array_map(function($item) { |
44
|
1 |
|
return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Conversation') ? $item : new Conversation((array) $item); |
45
|
1 |
|
}, $models); |
46
|
1 |
|
$this->metaData = new MetaData(); |
47
|
1 |
|
parent::__construct($models); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* find function. |
52
|
|
|
* |
53
|
|
|
* @access public |
54
|
|
|
* @param mixed $engagementID |
55
|
|
|
* @return Conversation |
56
|
|
|
*/ |
57
|
|
|
public function find($engagementID) |
58
|
|
|
{ |
59
|
|
|
$result = $this->filter(function($value) use ($engagementID) { |
60
|
|
|
return $value->info->conversationId == $engagementID; |
61
|
|
|
}); |
62
|
|
|
|
63
|
|
|
return $result->first(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* next function. |
68
|
|
|
* |
69
|
|
|
* @access public |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
1 |
|
public function next() |
73
|
|
|
{ |
74
|
|
|
/** @scrutinizer ignore-call */ |
75
|
1 |
|
if ($this->metaData->next) { |
|
|
|
|
76
|
|
|
/** @scrutinizer ignore-call */ |
77
|
1 |
|
$next = LiveEngage::retrieveMsgHistory($this->metaData->start, $this->metaData->end, $this->metaData->next->href); |
|
|
|
|
78
|
1 |
|
if ($next) { |
79
|
|
|
|
80
|
1 |
|
$next->_metadata->start = $this->metaData->start; |
81
|
1 |
|
$next->_metadata->end = $this->metaData->end; |
82
|
|
|
|
83
|
1 |
|
$meta = new MetaData((array) $next->_metadata); |
84
|
|
|
|
85
|
1 |
|
$collection = new self($next->conversationHistoryRecords); |
86
|
1 |
|
$collection->metaData = $meta; |
87
|
|
|
|
88
|
1 |
|
return $collection; |
89
|
|
|
|
90
|
|
|
} else { |
91
|
|
|
return null; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
return null; |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* prev function. |
101
|
|
|
* |
102
|
|
|
* @access public |
103
|
|
|
* @return mixed |
104
|
|
|
*/ |
105
|
1 |
|
public function prev() |
106
|
|
|
{ |
107
|
|
|
/** @scrutinizer ignore-call */ |
108
|
1 |
|
if ($this->metaData->prev) { |
|
|
|
|
109
|
|
|
/** @scrutinizer ignore-call */ |
110
|
1 |
|
$prev = LiveEngage::retrieveMsgHistory($this->metaData->start, $this->metaData->end, $this->metaData->prev->href); |
|
|
|
|
111
|
1 |
|
if ($prev) { |
112
|
|
|
|
113
|
1 |
|
$prev->_metadata->start = $this->metaData->start; |
114
|
1 |
|
$prev->_metadata->end = $this->metaData->end; |
115
|
|
|
|
116
|
1 |
|
$meta = new MetaData((array) $prev->_metadata); |
117
|
|
|
|
118
|
1 |
|
$collection = new self($prev->conversationHistoryRecords); |
119
|
1 |
|
$collection->metaData = $meta; |
120
|
|
|
|
121
|
1 |
|
return $collection; |
122
|
|
|
|
123
|
|
|
} else { |
124
|
|
|
return null; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return null; |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* merge function. |
134
|
|
|
* |
135
|
|
|
* @access public |
136
|
|
|
* @param mixed $collection |
137
|
|
|
* @return ConversationHistory |
138
|
|
|
*/ |
139
|
|
|
public function merge($collection) { |
140
|
|
|
|
141
|
|
|
$meta = $collection->metaData; |
142
|
|
|
$collection = parent::merge($collection); |
143
|
|
|
$this->metaData = $meta; |
144
|
|
|
$collection->metaData = $meta; |
145
|
|
|
|
146
|
|
|
return $collection; |
147
|
|
|
|
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.