Search code examples
phpkaltura

Accessing Custom Data Fields with Kaltura API version: 3.1.5 and PHP


I have created a custom metadata field called Record Date to my videos, and I am wondering how I can echo this information out when I sort my data by category. Here is a clip of the code I have working so far.

$pager = new KalturaFilterPager();
$pager->pageIndex = "1";
$pager->pageSize = "200";

if(isset($_REQUEST['category'])){
    $category = $_REQUEST['category'];
}
else{
    $category = "";
}

$filter = new KalturaMediaEntryFilter();
$filter->categoriesMatchOr = $category;
$filter->orderBy = KalturaMediaEntryOrderBy::CREATED_AT_DESC;

$entries = $client->media->listAction($filter, $pager);

if (!$entries)
{
   $entries = array();
}
?>

<ol id="list">
<?php 
$count = 0;
foreach ($entries->objects as $entry)
{
 echo '<li id="'.$count.'"><img src="'.$entry->thumbnailUrl.'"/> <strong>Name:</strong> '.$entry->name.' <strong>Record Date:</strong> '.date('m/d/Y', $entry->createdAt).' <strong>Duration:</strong> '.$entry->duration.' sec</li>';
 $count++;
}
?>
</ol>

I would like to replace $entry->createdAt with my custom metadata field value. Any help would be appreciated.


Solution

  • I have solved the problem by applying a KalturaMetadataFilter() inside of my foreach() statement. Here is the code.

    foreach ($entries->objects as $entry){
        $filter_meta = new KalturaMetadataFilter();
        $filter_meta->metadataObjectTypeEqual = KalturaMetadataObjectType::ENTRY;
        $filter_meta->objectIdEqual = $entry->id;
        $filter_meta->statusEqual = KalturaMetadataStatus::VALID;
        $metadataPlugin = KalturaMetadataClientPlugin::get($client);
        $result = $metadataPlugin->metadata->listAction($filter_meta);
        //print_r($result);
        if(isset($result->objects[0]->xml)){
            $xml = simplexml_load_string($result->objects[0]->xml);
            $record_date = (int)$xml->RecordDate;
        }
        else{
            $record_date = $entry->createdAt;
        }
        echo '<li id="'.$count.'"><img src="'.$entry->thumbnailUrl.'"/> <strong>Name:</strong> '.$entry->name.' <strong>Record Date:</strong> '.date('m/d/Y', $record_date).' <strong>Duration:</strong> '.$entry->duration.' sec</li>';
        $count++;
    }