1 | <?php |
||
2 | /** |
||
3 | * EngagementHistory |
||
4 | * |
||
5 | * @package LivePersonInc\LiveEngageLaravel\Collections |
||
6 | */ |
||
7 | |||
8 | namespace LivePersonInc\LiveEngageLaravel\Collections; |
||
9 | |||
10 | use Illuminate\Support\Collection; |
||
11 | use LivePersonInc\LiveEngageLaravel\Models\Engagement; |
||
12 | use LivePersonInc\LiveEngageLaravel\Models\MetaData; |
||
13 | use LivePersonInc\LiveEngageLaravel\Traits\Pageable; |
||
14 | |||
15 | /** |
||
16 | * EngagementHistory class. |
||
17 | * |
||
18 | * @extends Collection |
||
19 | */ |
||
20 | class EngagementHistory extends Collection |
||
21 | { |
||
22 | use Pageable; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
23 | |||
24 | /** |
||
25 | * metaData |
||
26 | * |
||
27 | * @var \LivePersonInc\LiveEngageLaravel\Models\MetaData |
||
28 | * @access public |
||
29 | */ |
||
30 | public $metaData; |
||
31 | |||
32 | /** |
||
33 | * historyFunction |
||
34 | * |
||
35 | * Required for the Pageable trait (default value: 'retrieveHistory') |
||
36 | * |
||
37 | * @var string |
||
38 | * @access protected |
||
39 | */ |
||
40 | protected $historyFunction = 'retrieveHistory'; |
||
41 | |||
42 | /** |
||
43 | * __construct function. |
||
44 | * |
||
45 | * @access public |
||
46 | * @param array $models (default: []) |
||
47 | * @return void |
||
48 | */ |
||
49 | 2 | public function __construct($models = []) |
|
50 | { |
||
51 | $models = array_map(function($item) { |
||
52 | 2 | return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Engagement') ? $item : new Engagement((array) $item); |
|
53 | 2 | }, $models ?: []); |
|
54 | 2 | $this->metaData = new MetaData(); |
|
55 | 2 | parent::__construct($models); |
|
56 | 2 | } |
|
57 | |||
58 | /** |
||
59 | * find function. |
||
60 | * |
||
61 | * @access public |
||
62 | * @param mixed $engagementID |
||
63 | * @return Engagement |
||
64 | */ |
||
65 | 1 | public function find($engagementID) |
|
66 | { |
||
67 | $result = $this->filter(function($value) use ($engagementID) { |
||
68 | 1 | return $value->info->sessionId == $engagementID; |
|
69 | 1 | }); |
|
70 | |||
71 | 1 | return $result->first(); |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * merge function. |
||
76 | * |
||
77 | * @access public |
||
78 | * @param EngagementHistory $collection |
||
79 | * @return EngagementHistory |
||
80 | */ |
||
81 | 1 | public function merge($collection) { |
|
82 | |||
83 | 1 | $meta = $collection->metaData; |
|
84 | 1 | $collection = parent::merge($collection); |
|
85 | 1 | $this->metaData = $meta; |
|
86 | 1 | $collection->metaData = $meta; |
|
87 | |||
88 | 1 | return $collection; |
|
89 | |||
90 | } |
||
91 | } |
||
92 |