public function info($pa_parameters)
 {
     AssetLoadManager::register('panel');
     parent::info($pa_parameters);
     $vn_annotation_id = isset($pa_parameters['annotation_id']) ? $pa_parameters['annotation_id'] : null;
     $t_annotation = new ca_representation_annotations($vn_annotation_id);
     $t_rep = new ca_object_representations($t_annotation->get('representation_id'));
     if ($vn_annotation_id) {
         $this->view->setVar('screen', $this->request->getActionExtra());
         // name of screen
         // find object editor screen with media bundle
         $t_ui = ca_editor_uis::loadDefaultUI('ca_object_representations', $this->request, $t_rep->getTypeID());
         $this->view->setVar('representation_editor_screen', $t_ui->getScreenWithBundle('ca_representation_annotations', $this->request));
     }
     return $this->render('widget_representation_annotation_info_html.php', true);
 }
 /**
  * 
  */
 public function deleteAnnotation()
 {
     $vn_annotation_id = $this->request->getParameter('annotation_id', pInteger);
     $va_response = array('code' => 0, 'id' => $vn_annotation_id, errors => array());
     $t_annotation = new ca_representation_annotations();
     if ($t_annotation->load($vn_annotation_id)) {
         $t_annotation->setMode(ACCESS_WRITE);
         $t_annotation->delete(true);
         if ($t_annotation->numErrors()) {
             $va_response = array('code' => 10, 'id' => $vn_annotation_id, 'errors' => $t_annotation->getErrors());
         }
     } else {
         $va_response = array('code' => 10, 'errors' => array(_t('Invalid annotation_id')));
     }
     $this->view->setVar('response', $va_response);
     return $this->render('ajax_representation_annotation_delete_json.php');
 }
 /**
  *
  */
 protected function _processRepresentationAnnotations($po_request, $ps_form_prefix, $ps_placement_code)
 {
     $va_rel_items = $this->getAnnotations();
     $o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType());
     $vn_c = 0;
     foreach ($va_rel_items as $vn_id => $va_rel_item) {
         $this->clearErrors();
         if (strlen($vn_status = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_status_' . $va_rel_item['annotation_id'], pString))) {
             $vn_access = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_access_' . $va_rel_item['annotation_id'], pInteger);
             $vn_locale_id = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_locale_id_' . $va_rel_item['annotation_id'], pInteger);
             $va_properties = array();
             foreach ($o_coder->getPropertyList() as $vs_property) {
                 $va_properties[$vs_property] = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_' . $vs_property . '_' . $va_rel_item['annotation_id'], pString);
             }
             // edit annotation
             $this->editAnnotation($va_rel_item['annotation_id'], $vn_locale_id, $va_properties, $vn_status, $vn_access);
             if ($this->numErrors()) {
                 $po_request->addActionErrors($this->errors(), 'ca_representation_annotations', $va_rel_item['annotation_id']);
             } else {
                 // try to add/edit label
                 if ($vs_label = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_label_' . $va_rel_item['annotation_id'], pString)) {
                     $t_annotation = new ca_representation_annotations($va_rel_item['annotation_id']);
                     if ($t_annotation->getPrimaryKey()) {
                         $t_annotation->setMode(ACCESS_WRITE);
                         $va_pref_labels = $t_annotation->getPreferredLabels(array($vn_locale_id), false);
                         if (sizeof($va_pref_labels)) {
                             // edit existing label
                             foreach ($va_pref_labels as $vn_annotation_dummy_id => $va_labels_by_locale) {
                                 foreach ($va_labels_by_locale as $vn_locale_dummy_id => $va_labels) {
                                     $t_annotation->editLabel($va_labels[0]['label_id'], array('name' => $vs_label), $vn_locale_id, null, true);
                                 }
                             }
                         } else {
                             // create new label
                             $t_annotation->addLabel(array('name' => $vs_label), $vn_locale_id, null, true);
                         }
                         if ($t_annotation->numErrors()) {
                             $po_request->addActionErrors($t_annotation->errors(), 'ca_representation_annotations', 'new_' . $vn_c);
                             $vn_c++;
                         }
                     }
                 }
             }
         } else {
             // is it a delete key?
             $this->clearErrors();
             if ($po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_' . $va_rel_item['annotation_id'] . '_delete', pInteger) > 0) {
                 // delete!
                 $this->removeAnnotation($va_rel_item['annotation_id']);
                 if ($this->numErrors()) {
                     $po_request->addActionErrors($this->errors(), 'ca_representation_annotations', $va_rel_item['annotation_id']);
                 }
             }
         }
     }
     // check for new annotations to add
     foreach ($_REQUEST as $vs_key => $vs_value) {
         if (!preg_match('/^' . $ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_status_new_([\\d]+)/', $vs_key, $va_matches)) {
             continue;
         }
         $vn_c = intval($va_matches[1]);
         if (strlen($vn_status = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_status_new_' . $vn_c, pString)) > 0) {
             $vn_access = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_access_new_' . $vn_c, pInteger);
             $vn_locale_id = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_locale_id_new_' . $vn_c, pInteger);
             $va_properties = array();
             foreach ($o_coder->getPropertyList() as $vs_property) {
                 $va_properties[$vs_property] = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_' . $vs_property . '_new_' . $vn_c, pString);
             }
             // create annotation
             $vs_label = $po_request->getParameter($ps_placement_code . $ps_form_prefix . '_ca_representation_annotations_label_new_' . $vn_c, pString);
             $vn_annotation_id = $this->addAnnotation($vs_label, $vn_locale_id, $po_request->getUserID(), $va_properties, $vn_status, $vn_access);
             if ($this->numErrors()) {
                 $po_request->addActionErrors($this->errors(), 'ca_representation_annotations', 'new_' . $vn_c);
             }
         }
     }
     return true;
 }
示例#4
0
 /**
  * 
  */
 public static function regenerate_annotation_previews($po_opts = null)
 {
     require_once __CA_LIB_DIR__ . "/core/Db.php";
     require_once __CA_MODELS_DIR__ . "/ca_representation_annotations.php";
     $o_db = new Db();
     $t_rep = new ca_object_representations();
     $t_rep->setMode(ACCESS_WRITE);
     if (!($vn_start = (int) $po_opts->getOption('start_id'))) {
         $vn_start = null;
     }
     if (!($vn_end = (int) $po_opts->getOption('end_id'))) {
         $vn_end = null;
     }
     $vs_sql_where = null;
     $va_params = array();
     if ($vn_start > 0 && $vn_end > 0 && $vn_start <= $vn_end || $vn_start > 0 && $vn_end == null) {
         $vs_sql_where = "WHERE annotation_id >= ?";
         $va_params[] = $vn_start;
         if ($vn_end) {
             $vs_sql_where .= " AND annotation_id <= ?";
             $va_params[] = $vn_end;
         }
     }
     $qr_reps = $o_db->query("\n\t\t\t\tSELECT annotation_id \n\t\t\t\tFROM ca_representation_annotations \n\t\t\t\t{$vs_sql_where}\n\t\t\t\tORDER BY annotation_id\n\t\t\t", $va_params);
     $vn_total = $qr_reps->numRows();
     print CLIProgressBar::start($vn_total, _t('Finding annotations'));
     $vn_c = 1;
     while ($qr_reps->nextRow()) {
         $t_instance = new ca_representation_annotations($vn_id = $qr_reps->get('annotation_id'));
         print CLIProgressBar::next(1, _t('Annotation %1', $vn_id));
         $t_instance->setMode(ACCESS_WRITE);
         $t_instance->update(array('forcePreviewGeneration' => true));
         $vn_c++;
     }
     print CLIProgressBar::finish();
 }
					{{{<unit delimiter="<br/>">^ca_objects.LcshNames</unit>}}}				
				</div><!-- end col -->
				<div class='col-sm-12 col-md-6 col-lg-6'>
					{{{<ifdef code="ca_objects.pbcoreFormatLocation"><H3>Location:</H3>^ca_objects.pbcoreFormatLocation<br/></ifdef>}}}
					{{{<ifdef code="ca_objects.idno"><H3>Identifier:</H3>^ca_objects.idno<br/></ifdef>}}}
					{{{<h3>MLA Citation:</h3><i>^ca_objects.preferred_labels.name</i>. <ifdef code="ca_objects.dateSet.setDisplayValue"><unit>^ca_objects.dateSet.setDisplayValue</unit>. </ifdef><ifcount code="ca_collections" min="1" max="1"><unit>^ca_collections.hierarchy.preferred_labels.name</unit>. </ifcount><i>New School Archives and Special Collections Digital Archive</i>. Web. ^DATE}}}
<?php 
if (sizeof($va_audios > 1)) {
    foreach ($va_audios as $va_audio) {
        print "<H3>Additional Audio</H3>";
        print caDetailLink($this->request, '<span class="glyphicon glyphicon-volume-up"></span> ' . $va_audio["label"], '', 'ca_objects', $t_object->get("object_id"), array("representation_id" => $va_audio["representation_id"])) . "<br/>";
    }
}
if (sizeof($va_annotations)) {
    print "<H3>Clips</H3>";
    $t_annotation = new ca_representation_annotations();
    foreach ($va_annotations as $va_annotation) {
        $t_annotation->load($va_annotation["annotation_id"]);
        $va_labels = caExtractValuesByUserLocale($va_annotation["labels"]);
        print "<p>";
        foreach ($va_labels as $vs_label) {
            print "<a href='#' onclick='caAnnoEditorPlayerPlay(" . $va_annotation["startTimecode_raw"] . "); return false;'><strong>" . $vs_label . "</strong></a><br/>";
        }
        print "<a href='#' onclick='caAnnoEditorPlayerPlay(" . $va_annotation["startTimecode_raw"] . "); return false;'><span class='glyphicon glyphicon-play-circle'></span></a> " . $va_annotation["startTimecode"] . " - " . $va_annotation["endTimecode"];
        print "<div class='indent'>";
        if ($t_annotation->get("description")) {
            print "<p>" . $t_annotation->get("description") . "</p>";
        }
        if ($t_annotation->get("ca_entities.preferred_labels")) {
            print "<strong class='uppercase'>" . _t("Related people/organizations") . "</strong><br/>" . $t_annotation->get("ca_entities.preferred_labels", array("delimiter" => ", ", "returnAsLink" => true));
        }
 /**
  * 
  */
 public function getClip()
 {
     $pn_id = $this->opo_request->getParameter('id', pInteger);
     $va_data = array();
     $t_annotation = new ca_representation_annotations($pn_id);
     if ($t_annotation->getPrimaryKey()) {
         $vs_start = $t_annotation->getPropertyValue('startTimecode');
         $vs_end = $t_annotation->getPropertyValue('endTimecode');
         $va_data['start'] = $vs_start;
         $va_data['end'] = $vs_end;
         $t_rep = new ca_object_representations($t_annotation->get('representation_id'));
         $va_data['file'] = $vs_file = $t_rep->getMediaPath('media', 'original');
         $o_media = new Media();
         if ($o_media->read($vs_file)) {
             $o_media->writeClip($vs_file = tempnam('/tmp', 'meow'), $vs_start, $vs_end);
         }
         header("Content-type: audio/mpeg");
         header("Content-length: " . @filesize($vs_file));
         readfile($vs_file);
         return;
     }
     return $this->makeResponse($va_data, 500, "No such clip");
 }
 /**
  * Returns data for annotations attached to current representation
  *
  * @param array $pa_options Optional array of options. Supported options are:
  *			checkAccess = array of access codes to filter count by. Only annotations with an access value set to one of the specified values will be returned
  *			start =
  *			max = 
  *			labelsOnly =
  *			idsOnly = 
  *			user_id = 
  *			item_id =
  * @return array List of annotations attached to the current representation, key'ed on annotation_id. Value is an array will all values; annotation labels are returned in the current locale.
  */
 public function getAnnotations($pa_options = null)
 {
     if (!($vn_representation_id = $this->getPrimaryKey())) {
         return null;
     }
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $pn_user_id = caGetOption('user_id', $pa_options, null);
     $pn_item_id = caGetOption('item_id', $pa_options, null);
     $pb_ids_only = caGetOption('idsOnly', $pa_options, false);
     $pb_labels_only = caGetOption('labelsOnly', $pa_options, false);
     if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) {
         // does not support annotations
         return null;
     }
     $va_params = array((int) $vn_representation_id);
     $o_db = $this->getDb();
     $vs_annotation_table = $this->annotationTable();
     $vs_annotation_label_table = $this->annotationLabelTable();
     $vs_access_sql = '';
     if (is_array($pa_options['checkAccess']) && sizeof($pa_options['checkAccess'])) {
         $vs_access_sql = ' AND cra.access IN (' . join(',', $pa_options['checkAccess']) . ')';
     }
     $vs_limit_sql = '';
     if ($pn_user_id) {
         $vs_limit_sql = ' AND cra.user_id = ?';
         $va_params[] = $pn_user_id;
     }
     if ($pn_item_id) {
         $vs_limit_sql .= ' AND cra.item_id = ?';
         $va_params[] = $pn_item_id;
     }
     $qr_annotations = $o_db->query("\n \t\t\tSELECT \tcra.annotation_id, cra.locale_id, cra.props, cra.representation_id, cra.user_id, cra.type_code, cra.access, cra.status\n \t\t\tFROM {$vs_annotation_table} cra\n \t\t\tWHERE\n \t\t\t\tcra.representation_id = ? {$vs_access_sql} {$vs_limit_sql}\n \t\t", $va_params);
     $vs_sort_by_property = $this->getAnnotationSortProperty();
     $va_annotations = array();
     $vn_start = caGetOption('start', $pa_options, 0, array('castTo' => 'int'));
     $vn_max = caGetOption('max', $pa_options, 100, array('castTo' => 'int'));
     $va_rep_props = $this->getMediaInfo('media', 'original');
     $vn_timecode_offset = isset($va_rep_props['PROPERTIES']['timecode_offset']) ? (double) $va_rep_props['PROPERTIES']['timecode_offset'] : 0;
     while ($qr_annotations->nextRow()) {
         $va_tmp = $qr_annotations->getRow();
         $va_annotation_ids[] = $va_tmp['annotation_id'];
         unset($va_tmp['props']);
         $o_coder->setPropertyValues($qr_annotations->getVars('props'));
         foreach ($o_coder->getPropertyList() as $vs_property) {
             $va_tmp[$vs_property] = $o_coder->getProperty($vs_property);
             $va_tmp[$vs_property . '_raw'] = $o_coder->getProperty($vs_property, true);
         }
         $va_tmp['timecodeOffset'] = $vn_timecode_offset;
         if (!($vs_sort_key = $va_tmp[$vs_sort_by_property])) {
             $vs_sort_key = '_default_';
         }
         $va_annotations[$vs_sort_key][$va_tmp['annotation_id']] = $va_tmp;
     }
     if (!sizeof($va_annotation_ids)) {
         return array();
     }
     ksort($va_annotations, SORT_NUMERIC);
     // get annotation labels
     $qr_annotations = caMakeSearchResult($vs_annotation_table, $va_annotation_ids);
     $va_labels = $va_annotation_classes = array();
     // Check if "class" element is configured, exists and is a list element
     if ($vs_class_element = $this->getAppConfig()->get('annotation_class_element')) {
         $t_anno = new ca_representation_annotations();
         if (!$t_anno->hasElement($vs_class_element)) {
             $vs_class_element = null;
         } elseif ($t_anno->_getElementDatatype($vs_class_element) != __CA_ATTRIBUTE_VALUE_LIST__) {
             // not a list element
             $vs_class_element = null;
         }
     }
     while ($qr_annotations->nextHit()) {
         $va_labels[$vn_annotation_id = $qr_annotations->get("{$vs_annotation_table}.annotation_id")][$qr_annotations->get("{$vs_annotation_label_table}.locale_id")][] = $qr_annotations->get("{$vs_annotation_table}.preferred_labels.name");
         if ($vs_class_element) {
             $va_annotation_classes[$vn_annotation_id] = $qr_annotations->get("{$vs_annotation_table}.{$vs_class_element}", array('returnAsArray' => true));
         }
     }
     $va_labels_for_locale = caExtractValuesByUserLocale($va_labels);
     if ($pb_labels_only) {
         return $va_labels_for_locale;
     }
     $va_annotation_classes_flattened = array();
     foreach ($va_annotation_classes as $vn_annotation_id => $va_classes) {
         $va_annotation_classes_flattened[$vn_annotation_id] = array_shift($va_classes);
     }
     $va_key = array();
     if ($qr_list_items = caMakeSearchResult('ca_list_items', array_values($va_annotation_classes_flattened))) {
         while ($qr_list_items->nextHit()) {
             $va_key[$qr_list_items->get('item_id')] = array('name' => $qr_list_items->get('ca_list_items.preferred_labels.name_plural'), 'idno' => $qr_list_items->get('ca_list_items.idno'), 'color' => $qr_list_items->get('ca_list_items.color'));
         }
     }
     $va_sorted_annotations = array();
     foreach ($va_annotations as $vs_key => $va_values) {
         foreach ($va_values as $va_val) {
             $vn_annotation_id = $va_val['annotation_id'];
             $vs_label = is_array($va_labels_for_locale[$va_val['annotation_id']]) ? array_shift($va_labels_for_locale[$va_val['annotation_id']]) : '';
             if ($pb_ids_only) {
                 $va_val = $vn_annotation_id;
             } elseif ($pb_labels_only) {
                 $va_val = $vs_label;
             } else {
                 $va_val['labels'] = $va_labels[$vn_annotation_id] ? $va_labels[$vn_annotation_id] : array();
                 $va_val['label'] = $vs_label;
                 $va_val['key'] = $va_key[$va_annotation_classes_flattened[$vn_annotation_id]];
             }
             $va_sorted_annotations[$vn_annotation_id] = $va_val;
         }
     }
     if ($pb_ids_only || $pb_labels_only) {
         return array_values($va_sorted_annotations);
     }
     if ($vn_start > 0 || $vn_max > 0) {
         if ($vn_max > 0) {
             $va_sorted_annotations = array_slice($va_sorted_annotations, $vn_start, $vn_max);
         } else {
             $va_sorted_annotations = array_slice($va_sorted_annotations, $vn_start);
         }
     }
     return $va_sorted_annotations;
 }