0

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.

Blake Plumb
  • 6,779
  • 3
  • 33
  • 54

2 Answers2

2

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++;
}
Blake Plumb
  • 6,779
  • 3
  • 33
  • 54
1

You should call entry.list, then implode the entry ids you receive in the result with commas (e.g. '0_jhb23ad,0_jhbasd3,0_askdja3') and then call metadata.list passing the list of entry ids in the field 'objectIdIn'.

Btw, you got a bug -

$filter->orderBy = 'CREATED_AT_DESC';

Has no effect, it should be

KalturaMediaEntryOrderBy::CREATED_AT_DESC;
Zohar.Babin
  • 265
  • 1
  • 2
  • 8
  • I am new to kaltura's api, but I have been able to get the xml by applying a KalturaMetadataFilter() inside my foreach(). This seems to work, but is not as effective as I would like. Can you give me a more specific example of what you mean by calling the metadata.list – Blake Plumb Nov 22 '12 at 00:13