mediamosa_batch_jobs_parse_table($files = array(), $type = 'queue')Parse the job table based on given type (queue or history).
$files array()
$type string: 'queue', 'history'
array($headers, $table)
sites/all/modules/mediamosa/modules/batch_jobs/mediamosa_batch_jobs.helpers.inc, line 32
<?php
function mediamosa_batch_jobs_parse_table($files = array(), $type = 'queue') {
$table = array(); // Table data.
$headers = array(); // Table header.
$dom = new DOMDocument(); // XML document vuf.
$dom_metadata = new DOMDocument(); // XML document metadata.
$record = array(); // Table row data.
// Loop through all files, parse the xml and add data to table array.
foreach ($files as $file) {
// Log if the file is parsed, if no videos are found in the xml,
// the file should still appear in the table.
$file_parsed = FALSE;
if (file_exists($file->uri)) {
if (@$dom->load($file->uri)) {
if ($dom->getElementsByTagName('video')->length > 0) {
// Loop through video tags in XML.
foreach ($dom->getElementsByTagName('video') as $video) {
foreach ($video->getElementsByTagName('formats') as $format) {
switch ($type) {
case 'queue':
$record['user_id'] = mediamosa_unicode::substr(basename(dirname($file->uri)), 0, -3);
$record['app_id'] = ltrim(mediamosa_unicode::substr(dirname($file->uri), -3), '0');
$metadatafile = dirname($file->uri) .'/'. $video->getElementsByTagName('metadataFile')->item(0)->nodeValue;
// Load metadata.
if (file_exists($metadatafile)) {
@$dom_metadata->load($metadatafile);
$record['title'] = $dom_metadata->getElementsByTagName('title')->item(0)->nodeValue;
}
else {
$record['title'] = '';
}
break;
case 'history':
$record['processed'] = mediamosa_unicode::format_date(filectime($file->uri), 'small');
break;
}
$usr = mediamosa_unicode::substr(basename(dirname($file->uri)), 0, -3) . '_' . ltrim(mediamosa_unicode::substr(dirname($file->uri), -3), '0');
$record['vuf'] = basename($file->uri);
$record['email'] = l($dom->getElementsByTagName('email')->item(0)->nodeValue, 'mailto:'. $dom->getElementsByTagName('email')->item(0)->nodeValue);
$record['referenceId'] = $video->getElementsByTagName('referenceId')->item(0)->nodeValue;
$record['action'] = $video->getElementsByTagName('action')->item(0)->nodeValue;
$record['mediaFile'] = $format->getElementsByTagName('mediaFile')->item(0)->nodeValue;
$record['status'] = l(t('Log'), 'admin/mediamosa/browse/ftp_batch/log/' . basename($file->uri) . '/'. $usr);
// Delete doesn't work because the apache user has insufficient rights.
// @todo: rewrite canceling of queued jobs.
/*
if ($type == 'queue') {
$record['remove'] = l(t('Delete'), 'admin/mediamosa/browse/ftp_batch/queue/delete/'. urlencode(basename($file->uri)));
}
*/
if (!empty($record)) {
// Add row to table and empty array.
$table[] = $record;
$file_parsed = true;
$record = array();
}
}
}
}
else { // No video tags in XML file.
$messsage = t('No video tags in XML file.');
}
}
else { // DOM not loaded.
$messsage = t('Could not load XML file.');
}
}
else { // File doesn't exist.
$messsage = t('File not found.');
}
// Create a row for files without valid XML data.
if (!$file_parsed) {
switch ($type) {
case 'queue':
$record['user_id'] = mediamosa_unicode::substr(basename(dirname($file->uri)), 0, -3);
$record['app_id'] = ltrim(mediamosa_unicode::substr(dirname($file->uri), -3), '0');
$record['title'] = '';
break;
case 'history':
$record['processed'] = mediamosa_unicode::format_date(filectime($file->uri), 'small');
break;
}
$record['vuf'] = basename($file->uri);
$record['email'] = '';
$record['referenceId'] = !empty($messsage) ? $messsage : t('n.a.');
$record['action'] = '';
$record['mediaFile'] = '';
if ($type == 'queue') {
//@todo: link to correct file.
$record['status'] = '';
}
else {
$usr = mediamosa_unicode::substr(basename(dirname($file->uri)), 0, -3) . '_' . ltrim(mediamosa_unicode::substr(dirname($file->uri), -3), '0');
$record['status'] = l(t('Log'), 'admin/mediamosa/browse/ftp_batch/log/' . basename($file->uri) . '/'. $usr);
}
// Delete doesn't work because the apache user has insufficient rights.
// @todo: rewrite canceling of queued jobs.
/*
if ($type == 'queue') {
$record['remove'] = l(t('Delete'), 'admin/mediamosa/browse/ftp_batch/queue/delete/'. urlencode(basename($file->uri)));
}
*/
// Add row to table and empty array.
$table[] = $record;
$record = array();
}
}
if (!empty($table)) {
// Convert array keys to table headers.
$headers = array_keys($table[0]);
foreach ($headers as &$header) {
$header = ucwords(str_replace('_', ' ', $header));
}
}
return array($headers, $table);
}
?>