1 | <?php |
||
2 | /** |
||
3 | * AgentParticipants |
||
4 | * |
||
5 | * @package LivePersonInc\LiveEngageLaravel\Collections |
||
6 | */ |
||
7 | |||
8 | namespace LivePersonInc\LiveEngageLaravel\Collections; |
||
9 | |||
10 | use Illuminate\Support\Collection; |
||
11 | use LivePersonInc\LiveEngageLaravel\Models\Agent; |
||
12 | use LivePersonInc\LiveEngageLaravel\Models\MetaData; |
||
13 | |||
14 | /** |
||
15 | * AgentParticipants class. |
||
16 | * |
||
17 | * @extends Collection |
||
18 | */ |
||
19 | class AgentParticipants extends Collection |
||
20 | { |
||
21 | /** |
||
22 | * metaData |
||
23 | * |
||
24 | * @var \LivePersonInc\LiveEngageLaravel\Models\MetaData |
||
25 | * @access public |
||
26 | */ |
||
27 | public $metaData; |
||
28 | |||
29 | /** |
||
30 | * __construct function. |
||
31 | * |
||
32 | * @access public |
||
33 | * @param array $models (default: []) |
||
34 | * @return void |
||
35 | */ |
||
36 | 2 | public function __construct(array $models = []) |
|
37 | { |
||
38 | |||
39 | $models = array_map(function($item) { |
||
40 | 2 | return is_a($item, 'LivePersonInc\LiveEngageLaravel\Models\Agent') ? $item : new Agent((array) $item); |
|
41 | 2 | }, $models); |
|
42 | 2 | $this->metaData = new MetaData(); |
|
43 | 2 | parent::__construct($models); |
|
44 | 2 | } |
|
45 | |||
46 | /** |
||
47 | * state function returns any agents in the collection with the specified availability state. |
||
48 | * |
||
49 | * @access public |
||
50 | * @param string $state (default: 'ONLINE') |
||
51 | * @return \LivePersonInc\LiveEngageLaravel\Models\Agent |
||
52 | */ |
||
53 | 1 | public function state($state = 'ONLINE') |
|
54 | { |
||
55 | $result = $this->filter(function($value) use ($state) { |
||
56 | 1 | return strtolower($value->currentStatus) == strtolower($state); |
|
57 | 1 | }); |
|
58 | |||
59 | 1 | return $result; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
60 | } |
||
61 | |||
62 | /** |
||
63 | * findById function. |
||
64 | * |
||
65 | * @access public |
||
66 | * @param int $agentId |
||
67 | * @return \LivePersonInc\LiveEngageLaravel\Models\Agent |
||
68 | */ |
||
69 | 2 | public function findById($agentId) |
|
70 | { |
||
71 | $result = $this->filter(function($value) use ($agentId) { |
||
72 | 2 | return $value->agentId == $agentId; |
|
73 | 2 | }); |
|
74 | |||
75 | 2 | return $result->first(); |
|
76 | } |
||
77 | } |
||
78 |