You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.2 KiB
70 lines
2.2 KiB
<?php
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
namespace Chamilo\PluginBundle\Zoom\API;
|
|
|
|
use Exception;
|
|
|
|
/**
|
|
* Trait Pagination
|
|
* properties for Pagination objects, which are paginated lists of items,
|
|
* retrieved in chunks from the server over one or several API calls, one per page.
|
|
*
|
|
* @package Chamilo\PluginBundle\Zoom\API
|
|
*/
|
|
trait Pagination
|
|
{
|
|
use JsonDeserializableTrait;
|
|
|
|
/** @var int The number of pages returned for the request made. */
|
|
public $page_count;
|
|
|
|
/** @var int The page number of the current results, counting from 1 */
|
|
public $page_number;
|
|
|
|
/** @var int The number of records returned with a single API call. Default 30, max 300. */
|
|
public $page_size;
|
|
|
|
/** @var int The total number of all the records available across pages. */
|
|
public $total_records;
|
|
|
|
/**
|
|
* Retrieves all items from the server, possibly generating several API calls.
|
|
*
|
|
* @param string $arrayPropertyName item array property name
|
|
* @param Client $client
|
|
* @param string $relativePath relative path to pass to Client::send
|
|
* @param array $parameters parameter array to pass to Client::send
|
|
*
|
|
* @throws Exception
|
|
*
|
|
* @return array united list of items
|
|
*/
|
|
protected static function loadItems($arrayPropertyName, $client, $relativePath, $parameters = [])
|
|
{
|
|
$items = [];
|
|
$pageCount = 1;
|
|
$pageSize = 300;
|
|
$totalRecords = 0;
|
|
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
|
|
$response = static::fromJson(
|
|
$client->send(
|
|
'GET',
|
|
$relativePath,
|
|
array_merge(['page_size' => $pageSize, 'page_number' => $pageNumber], $parameters)
|
|
)
|
|
);
|
|
$items = array_merge($items, $response->$arrayPropertyName);
|
|
if (0 === $totalRecords) {
|
|
$pageCount = $response->page_count;
|
|
$pageSize = $response->page_size;
|
|
$totalRecords = $response->total_records;
|
|
}
|
|
}
|
|
if (count($items) !== $totalRecords) {
|
|
error_log('Zoom announced '.$totalRecords.' records but returned '.count($items));
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
}
|
|
|