/** * Saves annotations to an object representation * * Expects the following request parameters: * representation_id = the id of the ca_object_representations record to save annotations to; the representation must belong to the specified object * */ public function SaveAnnotations() { global $g_ui_locale_id; $pn_representation_id = $this->request->getParameter('representation_id', pInteger); $t_rep = new ca_object_representations($pn_representation_id); $pa_annotations = $this->request->getParameter('save', pArray); $va_annotation_ids = array(); if (is_array($pa_annotations)) { foreach ($pa_annotations as $vn_i => $va_annotation) { $vs_label = isset($va_annotation['label']) && $va_annotation['label'] ? $va_annotation['label'] : ''; if (isset($va_annotation['annotation_id']) && ($vn_annotation_id = $va_annotation['annotation_id'])) { // edit existing annotation $t_rep->editAnnotation($vn_annotation_id, $g_ui_locale_id, $va_annotation, 0, 0); $va_annotation_ids[$va_annotation['index']] = $vn_annotation_id; } else { // new annotation $va_annotation_ids[$va_annotation['index']] = $t_rep->addAnnotation($vs_label, $g_ui_locale_id, $this->request->getUserID(), $va_annotation, 0, 0); } } } $va_annotations = array('error' => $t_rep->numErrors() ? join("; ", $t_rep->getErrors()) : null, 'annotation_ids' => $va_annotation_ids); $pa_annotations = $this->request->getParameter('delete', pArray); if (is_array($pa_annotations)) { foreach ($pa_annotations as $vn_to_delete_annotation_id) { $t_rep->removeAnnotation($vn_to_delete_annotation_id); } } $this->view->setVar('annotations', $va_annotations); $this->render('ajax_representation_annotations_json.php'); }