Introduction
This short guide features a usage process of the list action available on the baseEntry object API.
In this guide we'll create an HTML list view with pager and entry type filter.
This guide form a basic usage of the list action API that is used to create the KGallery implementation.
The code
Download the list entries script.
The code explained
To call the list entries action, we need to use an ADMIN type KS (Read more), and so before calling the list action, we define the partner id and it's ADMIN secret:
Then, using the partner credentials, we generate the KS:
$partnerUserID = '31'; // this can be whatever you decide depending on your implementation
//Construction of Kaltura objects for session initiation
$config = new KalturaConfiguration(KALTURA_PARTNER_ID);
$client = new KalturaClient($config);
$ks = $client->session->start(KALTURA_PARTNER_WEB_SERVICE_ADMIN_SECRET, $partnerUserID, KalturaSessionType::ADMIN);
//Set the generated KS as the default actions KS to use by the client library
$client->setKs($ks);
Now that we have a KS set up, the following steps call the list action:
- Define the filter to use when listing the entries:
$entryFilter = new KalturaBaseEntryFilter();/**
* Available types (defined within KalturaEntryType class under KalturaClient.php):
* AUTOMATIC = -1;
* MEDIA_CLIP = 1;
* MIX = 2;
* PLAYLIST = 5;
* DATA = 6;
* DOCUMENT = 10;
*/
if (isset($_GET['entryType']))
$entryFilter->typeEqual = (int)$_GET['entryType'];
$entryFilter->statusEqual = KalturaEntryStatus::READY;
$entryFilter->orderBy = KalturaBaseEntryOrderBy::CREATED_AT_DESC;
In order to allow for the list to filter according to a url parameter by the name of entryType, we use the
$_GET['entryType']variable. If not filter is defined, all entries will be returned by the list action.
We also usestatusEqualto return only the entries that have finished ingestion process and are ready to be used and viewed by the users andorderByto return the list ordered such as the latest entries created will be shown first. - Define the pager:
$kalturaPager = new KalturaFilterPager();$kalturaPager->pageSize = 10;
$kalturaPager->pageIndex = (isset($_GET['p']))? $_GET['p']: 1;
In order to divide the result to smaller chunks and return only 10 entries per request, we use a pager. The pager decide how many results to return and the results chunk number (page).
i.e. if we have 120 entries and we set thepageSizeto 10, we will have 12 pages that each represents a chunk of 10 entries.
Again, in order to set the page number from a url parameter, we use the$_GET['p']variable. - The last part, we call the list action with the filter and pager we created:
$result = $client->baseEntry->listAction($entryFilter, $kalturaPager);
To present the list on the page, we print out an HTML for the returned list:
<div id="<?php echo $entry->id; ?>" class="doc">
<div><span>Name: </span><?php echo $entry->name; ?></div>
<div><span>Created: </span><?php echo date('Y-m-d H:i:s', $entry->createdAt); ?></div>
<div><a href="#" onclick="$('#infodiv<?php echo $entry->id; ?>').toggle('fast');" >More...</a><div style="display:none;overflow:hidden;" id="infodiv<?php echo $entry->id; ?>"><pre><?php echo print_r($entry, true); ?></pre></div></div>
</div>
<? endforeach; ?>
And lastly, create the pager:
<?php
$page = 1;
while($page)
{
$filename = pathinfo(__FILE__, PATHINFO_FILENAME).'.'.pathinfo(__FILE__, PATHINFO_EXTENSION);
if($page == $kalturaPager->pageIndex)
echo $page.' ';
else
if (isset($_GET['entryType']))
echo '<a href="'.$filename.'?p='.$page.'&entryType='.$_GET['entryType'].'">'.$page.'</a> ';
else
echo '<a href="'.$filename.'?p='.$page.'">'.$page.'</a> ';
if($page*$kalturaPager->pageSize > $result->totalCount)
break;
$page++;
}
?>
</div>
-
$filename- will hold the base url to the page, in order to build the url according to the selected page - The rest of the code print a list of links, each represents a call for a new page. Building the page links using the base url (
$filename), the page selected and the entryType specified on the url.
| Attachment | Size |
|---|---|
| list-entries-script.zip | 16.54 KB |



