Skip to content

Instantly share code, notes, and snippets.

@zoharbabin
Last active April 16, 2021 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoharbabin/b422686f15a228876256c4ca598d8d54 to your computer and use it in GitHub Desktop.
Save zoharbabin/b422686f15a228876256c4ca598d8d54 to your computer and use it in GitHub Desktop.
example of using baseEntry.exportToCsv action to get a full list of Kaltura entries as CSV emailed to you
// IMPORTANT: This action will EMAIL the CSV file to the email defined in the user's email field. Be sure to set userId in the KS that belongs to a user object that has email field properly set to a valid email address
//initialize kaltura
$kConfig = new KalturaConfiguration($pid);
$kConfig->setServiceUrl('https://www.kaltura.com');
$kConfig->setLogger($this);
$this->client = new KalturaClient($kConfig);
$this->ks = $this->client->session->start($secret, 'userIdToSendEmailWithCSV', SessionType::ADMIN, $pid, 86400, 'list:*,disableentitlement,*');
$this->client->setKs($this->ks);
// First create a fileter to get only the entries you wish:
$filter = new BaseEntryFilter();
$filter->categoriesIdsMatchAnd = 202345753;
$filter->advancedSearch = new MetadataSearchItem();
$filter->advancedSearch->type = SearchOperatorType::SEARCH_OR;
$filter->advancedSearch->items = array();
$filter->advancedSearch->items[0] = new SearchCondition();
$filter->advancedSearch->items[0]->field = "/*[local-name()='metadata']/*[local-name()='BroadcastType']";
$filter->advancedSearch->items[0]->value = 'Live';
$filter->advancedSearch->items[1] = new SearchCondition();
$filter->advancedSearch->items[1]->field = "/*[local-name()='metadata']/*[local-name()='BroadcastType']";
$filter->advancedSearch->items[1]->value = 'Simulive';
$filter->advancedSearch->metadataProfileId = 14774093;
// You can specify an additional metadata profile to pull fields from, you'll need to specify each field you'd like to export in the CSV:
$metadataProfileId = 14645233;
$additionalFields = array();
$additionalFields[0] = new CsvAdditionalFieldInfo();
$additionalFields[0]->fieldName = 'CTA_Url'; // the header name in the exported CSV
$additionalFields[0]->xpath = "/metadata/Detail[Key='entrycalltoaction']/Value"; //the xPath to the field you'd like to include in your CSV
// By default, the exportToCsv action will only export the id and name fields. If you'd like to export more baseEntry fields, include them in the mappedFields:
$mappedFields = array();
$mappedFields[0] = new KeyValue();
$mappedFields[0]->key = 'external_id'; // the header name in the exported CSV
$mappedFields[0]->value = 'referenceId'; // the baseEntry field name
// The result will be the email address to which the email will be sent
$email = $this->client->getBaseEntryService()->exportToCsv($filter, $metadataProfileId, $additionalFields, $mappedFields);
echo PHP_EOL . 'The export CSV file will be emailed to: ' . $email . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment