ApiVideo /
php-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace ApiVideo\Client\Api; |
||
| 5 | |||
| 6 | |||
| 7 | use ApiVideo\Client\Model\Analytic\PlayerSessionEvent; |
||
| 8 | use DateTime; |
||
| 9 | use Exception; |
||
| 10 | |||
| 11 | class AnalyticsSessionEvents extends BaseApi |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param $sessionId |
||
| 16 | * @param array $parameters |
||
| 17 | * @return PlayerSessionEvent[]|null |
||
| 18 | */ |
||
| 19 | public function search($sessionId, array $parameters = array()) |
||
| 20 | { |
||
| 21 | $currentPage = isset($parameters['currentPage']) ? $parameters['currentPage'] : 1; |
||
| 22 | $parameters['pageSize'] = isset($parameters['pageSize']) ? $parameters['pageSize'] : 100; |
||
| 23 | $analyticSessionEvent = null; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 24 | $items = array(); |
||
| 25 | |||
| 26 | do { |
||
| 27 | $parameters['currentPage'] = $currentPage; |
||
| 28 | $response = $this->browser->get("/analytics/sessions/$sessionId/events?".http_build_query($parameters)); |
||
| 29 | |||
| 30 | if (!$response->isSuccessful()) { |
||
| 31 | $this->registerLastError($response); |
||
| 32 | |||
| 33 | return null; |
||
| 34 | } |
||
| 35 | |||
| 36 | $json = json_decode($response->getContent(), true); |
||
| 37 | $analytics = $json['data']; |
||
| 38 | $items[] = $this->castAll($analytics); |
||
| 39 | |||
| 40 | if (isset($parameters['currentPage'])) { |
||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | $pagination = $json['pagination']; |
||
| 45 | $pagination['currentPage']++; |
||
| 46 | } while ($pagination['pagesTotal'] >= $pagination['currentPage']); |
||
| 47 | |||
| 48 | $items = call_user_func_array('array_merge', $items); |
||
| 49 | |||
| 50 | return $items; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param array $data |
||
| 55 | * @return PlayerSessionEvent |
||
| 56 | * @throws Exception |
||
| 57 | */ |
||
| 58 | protected function cast(array $data) |
||
| 59 | { |
||
| 60 | return new PlayerSessionEvent( |
||
| 61 | $data['type'], |
||
| 62 | new DateTime($data['emittedAt']), |
||
| 63 | isset($data['at']) ? $data['at'] : null, |
||
| 64 | isset($data['from']) ? $data['from'] : null, |
||
| 65 | isset($data['to']) ? $data['to'] : null |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | } |