private function KalturaHelpers::getFullListOfKalturaObject in Kaltura 7.3
1 call to KalturaHelpers::getFullListOfKalturaObject()
- KalturaHelpers::getAllEntries in kaltura_client/
kaltura_helpers.php
File
- kaltura_client/
kaltura_helpers.php, line 466
Class
- KalturaHelpers
- Class KalturaHelpers.
Code
private function getFullListOfKalturaObject($filter, $listService, $idField = 'id', $valueFields = NULL, $printProgress = FALSE, $stopOnCreatedAtDate = false) {
$stopDateForCreatedAtFilter = null;
$serviceName = get_class($listService);
$filter->orderBy = '-createdAt';
$filter->createdAtLessThanOrEqual = NULL;
$pager = new KalturaFilterPager();
$pager->pageSize = 500;
$pager->pageIndex = 1;
$lastCreatedAt = 0;
$lastObjectIds = '';
$reachedLastObject = false;
$allObjects = array();
$count = 0;
$totalCount = 0;
$countAvailable = method_exists($listService, 'count');
if ($countAvailable) {
if ($stopOnCreatedAtDate && $stopDateForCreatedAtFilter != null && $stopDateForCreatedAtFilter > -1) {
$filter->createdAtGreaterThanOrEqual = $stopDateForCreatedAtFilter;
}
$totalCount = $listService
->count($filter) + 1;
//due to date filter grater vs. less-than there will be a 1 diff
$filter->createdAtGreaterThanOrEqual = KalturaClientBase::getKalturaNullValue();
}
// if this filter doesn't have idNotIn - we need to find the highest totalCount
// this is a workaround hack due to a bug in how categoryEntry list action calculates totalCount
if (!property_exists($filter, 'idNotIn')) {
$temppager = new KalturaFilterPager();
$temppager->pageSize = 500;
$temppager->pageIndex = 1;
$result = $listService
->listAction($filter, $temppager);
while (count($result->objects) > 0) {
$result = $listService
->listAction($filter, $temppager);
$totalCount = max($totalCount, $result->totalCount);
++$temppager->pageIndex;
}
}
while (!$reachedLastObject) {
if ($lastCreatedAt != 0) {
$filter->createdAtLessThanOrEqual = $lastCreatedAt;
}
if ($lastObjectIds != '' && property_exists($filter, 'idNotIn')) {
$filter->idNotIn = $lastObjectIds;
}
try {
$filteredListResult = $listService
->listAction($filter, $pager);
} catch (Exception $err) {
watchdog_exception('kaltura', $err
->getMessage());
}
if ($totalCount == 0) {
$totalCount = $filteredListResult->totalCount;
}
$resultsCount = count($filteredListResult->objects);
if ($resultsCount == 0 || $totalCount <= $count) {
$reachedLastObject = true;
break;
}
foreach ($filteredListResult->objects as $obj) {
if ($count < $totalCount) {
if ($valueFields == NULL) {
$allObjects[$obj->{$idField}] = $obj;
}
elseif (is_string($valueFields)) {
if (substr($valueFields, -1) == '*') {
$valfield = substr($valueFields, 0, -1);
if (!isset($allObjects[$obj->{$idField}])) {
$allObjects[$obj->{$idField}] = array();
}
$allObjects[$obj->{$idField}][] = $obj->{$valfield};
}
else {
$allObjects[$obj->{$idField}] = $obj->{$valueFields};
}
}
elseif (is_array($valueFields)) {
if (!isset($allObjects[$obj->{$idField}])) {
$allObjects[$obj->{$idField}] = array();
}
foreach ($valueFields as $field) {
$allObjects[$obj->{$idField}][$field] = $obj->{$field};
}
}
if ($lastCreatedAt > $obj->createdAt) {
$lastObjectIds = '';
}
$lastCreatedAt = $obj->createdAt;
if ($stopOnCreatedAtDate && $stopDateForCreatedAtFilter != null && $stopDateForCreatedAtFilter > -1 && $lastCreatedAt <= $stopDateForCreatedAtFilter) {
$reachedLastObject = true;
break;
}
if ($lastObjectIds != '') {
$lastObjectIds .= ',';
}
$lastObjectIds .= $obj->{$idField};
}
else {
$reachedLastObject = true;
break;
}
}
$count += $resultsCount;
}
return $allObjects;
}