/**
  * Returns JSON feed of annotations on an object representation
  *
  * Expects the following request parameters: 
  *		representation_id = the id of the ca_object_representations record to display; the representation must belong to the specified object 
  *
  */
 public function GetAnnotations()
 {
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $t_rep = new ca_object_representations($pn_representation_id);
     $va_annotations_raw = $t_rep->getAnnotations();
     $va_annotations = array();
     foreach ($va_annotations_raw as $vn_annotation_id => $va_annotation) {
         $va_annotations[] = array('annotation_id' => $va_annotation['annotation_id'], 'x' => caGetOption('x', $va_annotation, 0, array('castTo' => 'float')), 'y' => caGetOption('y', $va_annotation, 0, array('castTo' => 'float')), 'w' => caGetOption('w', $va_annotation, 0, array('castTo' => 'float')), 'h' => caGetOption('h', $va_annotation, 0, array('castTo' => 'float')), 'tx' => caGetOption('tx', $va_annotation, 0, array('castTo' => 'float')), 'ty' => caGetOption('ty', $va_annotation, 0, array('castTo' => 'float')), 'tw' => caGetOption('tw', $va_annotation, 0, array('castTo' => 'float')), 'th' => caGetOption('th', $va_annotation, 0, array('castTo' => 'float')), 'points' => caGetOption('points', $va_annotation, array(), array('castTo' => 'array')), 'label' => caGetOption('label', $va_annotation, '', array('castTo' => 'string')), 'description' => caGetOption('description', $va_annotation, '', array('castTo' => 'string')), 'type' => caGetOption('type', $va_annotation, 'rect', array('castTo' => 'string')), 'locked' => caGetOption('locked', $va_annotation, '0', array('castTo' => 'string')), 'options' => caGetOption('options', $va_annotation, array(), array('castTo' => 'array')));
     }
     $this->view->setVar('annotations', $va_annotations);
     $this->render('ajax_representation_annotations_json.php');
 }
			{{{previousLink}}}{{{resultsLink}}}
		</div><!-- end detailNavBgLeft -->
	</div><!-- end col -->
	<div class='col-xs-10 col-sm-10 col-md-10 col-lg-10'>
		<div class="container">
			<div class="row">
				<div class='col-sm-12 col-md-6 col-lg-6'>
					<H1>{{{<unit relativeTo="ca_collections" delimiter="_➔_"><l>^ca_collections.hierarchy.preferred_labels.name</l></unit><ifcount min="1" code="ca_collections"> ➔ </ifcount>}}}{{{ca_objects.preferred_labels.name}}}</H1>
				</div><!-- end col -->
			</div><!-- end row -->
			<div class="row">
				<div class='col-sm-12 col-md-12 col-lg-12'>
<?php 
if ($vn_audio_rep_id) {
    $t_rep->load($vn_audio_rep_id);
    $va_annotations = $t_rep->getAnnotations(array("checkAccess" => $this->getVar("access_values")));
    #print_r($va_annotations);
    print $t_rep->getMediaTag("media", $va_audio_media_display_info["display_version"], $va_audio_media_display_info, array("id" => "caPlayer"));
}
?>
					<div id="detailTools">						
						<div class="detailTool detailToolRight"><span class="glyphicon glyphicon-share-alt"></span>{{{shareLink}}}</div><!-- end detailTool -->
<?php 
print "<div class='detailTool'>";
if (caObjectsDisplayDownloadLink($this->request) && $vn_audio_rep_id) {
    # -- get version to download configured in media_display.conf
    $va_download_display_info = caGetMediaDisplayInfo('download', $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
    $vs_download_version = $va_download_display_info['display_version'];
    print caNavLink($this->request, " <span class='glyphicon glyphicon-download-alt'></span>", '', 'Detail', 'DownloadRepresentation', '', array('representation_id' => $t_rep->getPrimaryKey(), "object_id" => $t_object->get("object_id"), "download" => 1, "version" => $vs_download_version), array("title" => _t("Download"))) . "&nbsp;&nbsp;&nbsp;&nbsp;";
}
print $vs_transcript_link;
 /**
  * 
  */
 public function media()
 {
     if (!is_object($t_entity = $this->_checkEntity())) {
         return $t_entity;
     }
     $vn_id = $t_entity->getPrimaryKey();
     $t_list = new ca_lists();
     $vn_exhibition_audio_type_id = $t_list->getItemIDFromList('object_types', 'MemEx_Audio');
     $vs_filter = $this->opo_request->getParameter('filter', pString);
     if (!in_array($vs_filter, array('video', 'audio', 'image', 'pdf'))) {
         $vs_filter = null;
     }
     $t_object = new ca_objects();
     $va_data = array('id' => $vn_id);
     $from = $this->opo_request->getParameter('from', pString);
     $until = $this->opo_request->getParameter('until', pString);
     if (!$until) {
         $until = date('c');
     }
     $vs_range = $from && $until ? self::utcToDb($from) . ' to ' . self::utcToDb($until) : null;
     $o_tep = new TimeExpressionParser();
     $vb_parsed_date = false;
     if ($vs_range) {
         if ($vb_parsed_date = $o_tep->parse($vs_range)) {
             $va_range = $o_tep->getUnixTimestamps();
         }
     }
     $t_rep = new ca_object_representations();
     $t_list = new ca_lists();
     $va_pub_target_values = $t_list->getItemsForList('object_publication_targets', array('extractValuesByUserLocale' => true));
     $va_audio_target_values = $t_list->getItemsForList('audio_publication_targets', array('extractValuesByUserLocale' => true));
     $vn_memorial_exhibition_audio_type_id = $t_list->getItemIDFromList('object_types', 'MemEx_Audio');
     $vn_publish_annotation_id = $t_list->getItemIDFromList('annotation_publication_targets', 'interactive_tables');
     $vn_publish_rep = $t_list->getItemIDFromList("memex_status", "publish");
     $va_objects = $t_entity->getRelatedItems('ca_objects');
     foreach ($va_objects as $vn_relation_id => $va_object_info) {
         $va_timestamp = $t_object->getLastChangeTimestamp($va_object_info['object_id']);
         if ($vb_parsed_date && ($va_timestamp['timestamp'] <= $va_range['start'] || $va_timestamp['timestamp'] >= $va_range['end'])) {
             continue;
         }
         if ($t_object->load($va_object_info['object_id'])) {
             $va_reps = $t_object->getRepresentations(array("preview", "preview170", "icon", "small", "medium", "large", "large_png", "original", "h264_hi", "mp3"));
             if (!is_array($va_reps) || !sizeof($va_reps)) {
                 continue;
             }
             $va_filtered_reps = array();
             foreach ($va_reps as $vn_i => $va_rep) {
                 $va_tmp = explode('/', $vs_mimetype = $va_rep['info']['original']['MIMETYPE']);
                 if ($vs_filter && ($va_tmp[0] != $vs_filter && $va_tmp[1] != $vs_filter)) {
                     continue;
                 }
                 $vb_is_audio = false;
                 if ($t_object->get('type_id') == $vn_memorial_exhibition_audio_type_id) {
                     $va_pub_targets = $t_object->get('ca_objects.audio_publication_targets', array('returnAsArray' => true, 'convertCodesToDisplayText' => false));
                     $vb_is_audio = true;
                 } else {
                     $va_pub_targets = $t_object->get('ca_objects.object_publication_targets', array('returnAsArray' => true, 'convertCodesToDisplayText' => false));
                 }
                 if (!sizeof($va_pub_targets)) {
                     continue;
                 }
                 if (!$t_rep->load($va_rep['representation_id'])) {
                     continue;
                 }
                 if ($t_rep->get("ca_object_representations.memex_status", array('convertCodesToDisplayText' => false)) != $vn_publish_rep) {
                     continue;
                 }
                 // reset filesize property to reflect size of version, not size of original
                 foreach ($va_reps[$vn_i]['paths'] as $vs_version => $vs_path) {
                     $va_reps[$vn_i]['info'][$vs_version]['PROPERTIES']['filesize'] = @filesize($va_reps[$vn_i]['paths'][$vs_version]);
                 }
                 unset($va_reps[$vn_i]['paths']);
                 unset($va_reps[$vn_i]['tags']);
                 unset($va_reps[$vn_i]['media']);
                 unset($va_reps[$vn_i]['media_metadata']);
                 unset($va_reps[$vn_i]['is_primary']);
                 unset($va_reps[$vn_i]['name']);
                 unset($va_reps[$vn_i]['status']);
                 unset($va_reps[$vn_i]['locale_id']);
                 unset($va_reps[$vn_i]['type_id']);
                 $va_reps[$vn_i]['lastupdate_timestamp'] = date('o-m-N', $va_timestamp['timestamp']) . "T" . date('H:i:s', $va_timestamp['timestamp']) . "Z";
                 //date('c', $va_timestamp['timestamp']);
                 $va_reps[$vn_i]['type_id'] = $vn_type_id = $t_object->get('ca_objects.type_id');
                 $va_reps[$vn_i]['typename'] = $t_object->getTypeName();
                 $va_reps[$vn_i]['typecode'] = $t_object->getTypeCode();
                 $va_targets = array();
                 foreach ($va_pub_targets as $vn_attr_id => $va_value) {
                     $va_targets[] = $va_pub_target_values[$va_value['object_publication_targets']]['idno'] ? $va_pub_target_values[$va_value['object_publication_targets']]['idno'] : $va_audio_target_values[$va_value['audio_publication_targets']]['idno'];
                 }
                 $va_reps[$vn_i]['publication_targets'] = $va_targets;
                 $va_reps[$vn_i]['title'] = $t_object->get('ca_objects.memex_title');
                 $va_reps[$vn_i]['credit'] = $t_object->get('ca_objects.memex_credit_line');
                 $va_reps[$vn_i]['caption'] = $t_object->get('ca_objects.memex_caption');
                 if ($t_object->get('type_id') == $vn_exhibition_audio_type_id) {
                     $va_reps[$vn_i]['transcript'] = $t_object->get('ca_objects.final_text_inner_chamber');
                     $va_reps[$vn_i]['attribution'] = $t_object->get('ca_objects.remembrance_attribution');
                 }
                 if ($va_rep['num_multifiles'] > 0) {
                     $va_pages = $t_rep->getFileList($va_rep['representation_id'], null, null, array('page_preview'));
                     $va_page_urls = array();
                     foreach ($va_pages as $vn_file_id => $va_file_info) {
                         $va_page_urls[] = $va_file_info['page_preview_url'];
                     }
                     $va_reps[$vn_i]['page_images'] = $va_page_urls;
                 }
                 $va_reps[$vn_i]['clips'] = array();
                 if (is_array($va_annotations = $t_rep->getAnnotations()) && sizeof($va_annotations)) {
                     foreach ($va_annotations as $vn_index => $va_annotation) {
                         $vn_annotation_id = $va_annotation['annotation_id'];
                         //if ($va_annotation['access'] == 0) { continue; }
                         $t_annotation = new ca_representation_annotations($vn_annotation_id);
                         if ($vn_publish_annotation_id != $t_annotation->get('annotation_publication_targets')) {
                             continue;
                         }
                         // skip ones not marked for publication
                         unset($va_annotation['props']);
                         $va_annotation['description'] = $t_annotation->get('description');
                         $va_annotation['transcript'] = $t_annotation->get('transcript');
                         //$va_annotation['mp3'] = $t_annotation->getAppConfig()->get('site_host')."/service.php/ns11mmServices/Victim/getClip/id/{$vn_annotation_id}";
                         $va_annotation['mp3'] = $t_annotation->getMediaUrl('ca_representation_annotations.preview', 'original');
                         $va_annotation['md5'] = $t_annotation->getMediaInfo('ca_representation_annotations.preview', 'original', 'MD5');
                         $va_reps[$vn_i]['clips'][] = $va_annotation;
                     }
                 }
                 $va_filtered_reps[] = $va_reps[$vn_i];
             }
             if (sizeof($va_filtered_reps)) {
                 $va_data['media'][$va_object_info['object_id']] = $va_filtered_reps;
             }
         }
     }
     return $this->makeResponse($va_data);
 }