| @@ 9-65 (lines=57) @@ | ||
| 6 | use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel; |
|
| 7 | use LivePersonInc\LiveEngageLaravel\Models\Conversation; |
|
| 8 | ||
| 9 | class ConversationHistory extends Collection |
|
| 10 | { |
|
| 11 | private $instance; |
|
| 12 | ||
| 13 | public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
|
| 14 | { |
|
| 15 | $this->instance = $instance; |
|
| 16 | ||
| 17 | parent::__construct($models); |
|
| 18 | } |
|
| 19 | ||
| 20 | public function next() |
|
| 21 | { |
|
| 22 | if (! $this->instance) { |
|
| 23 | return false; |
|
| 24 | } |
|
| 25 | ||
| 26 | $instance = $this->instance; |
|
| 27 | ||
| 28 | $next = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->next); |
|
| 29 | if (property_exists($next->_metadata, 'next')) { |
|
| 30 | $instance->next = $next->_metadata->next->href; |
|
| 31 | ||
| 32 | $history = []; |
|
| 33 | foreach ($next->conversationHistoryRecords as $item) { |
|
| 34 | $history[] = new Conversation((array) $item); |
|
| 35 | } |
|
| 36 | ||
| 37 | return $this->merge(new self($history)); |
|
| 38 | } else { |
|
| 39 | return false; |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||
| 43 | public function prev() |
|
| 44 | { |
|
| 45 | if (! $this->instance) { |
|
| 46 | return false; |
|
| 47 | } |
|
| 48 | ||
| 49 | $instance = $this->instance; |
|
| 50 | ||
| 51 | $prev = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->prev); |
|
| 52 | if (property_exists($prev->_metadata, 'prev')) { |
|
| 53 | $instance->prev = $prev->_metadata->prev->href; |
|
| 54 | ||
| 55 | $history = []; |
|
| 56 | foreach ($next->conversationHistoryRecords as $item) { |
|
| 57 | $history[] = new Conversation((array) $item); |
|
| 58 | } |
|
| 59 | ||
| 60 | return $this->merge(new self($history)); |
|
| 61 | } else { |
|
| 62 | return false; |
|
| 63 | } |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| @@ 9-65 (lines=57) @@ | ||
| 6 | use LivePersonInc\LiveEngageLaravel\LiveEngageLaravel; |
|
| 7 | use LivePersonInc\LiveEngageLaravel\Models\Engagement; |
|
| 8 | ||
| 9 | class EngagementHistory extends Collection |
|
| 10 | { |
|
| 11 | private $instance; |
|
| 12 | ||
| 13 | public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
|
| 14 | { |
|
| 15 | $this->instance = $instance; |
|
| 16 | ||
| 17 | parent::__construct($models); |
|
| 18 | } |
|
| 19 | ||
| 20 | public function next() |
|
| 21 | { |
|
| 22 | if (! $this->instance) { |
|
| 23 | return false; |
|
| 24 | } |
|
| 25 | ||
| 26 | $instance = $this->instance; |
|
| 27 | ||
| 28 | $next = $instance->retrieveHistory($instance->start, $instance->end, $instance->next); |
|
| 29 | if (property_exists($next->_metadata, 'next')) { |
|
| 30 | $instance->next = $next->_metadata->next->href; |
|
| 31 | ||
| 32 | $history = []; |
|
| 33 | foreach ($next->interactionHistoryRecords as $item) { |
|
| 34 | $history[] = new Engagement((array) $item); |
|
| 35 | } |
|
| 36 | ||
| 37 | return $this->merge(new self($history)); |
|
| 38 | } else { |
|
| 39 | return false; |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||
| 43 | public function prev() |
|
| 44 | { |
|
| 45 | if (! $this->instance) { |
|
| 46 | return false; |
|
| 47 | } |
|
| 48 | ||
| 49 | $instance = $this->instance; |
|
| 50 | ||
| 51 | $prev = $instance->retrieveHistory($instance->start, $instance->end, $instance->prev); |
|
| 52 | if (property_exists($prev->_metadata, 'prev')) { |
|
| 53 | $instance->prev = $prev->_metadata->prev->href; |
|
| 54 | ||
| 55 | $history = []; |
|
| 56 | foreach ($next->interactionHistoryRecords as $item) { |
|
| 57 | $history[] = new Engagement((array) $item); |
|
| 58 | } |
|
| 59 | ||
| 60 | return $this->merge(new self($history)); |
|
| 61 | } else { |
|
| 62 | return false; |
|
| 63 | } |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||