/**
  * 
  */
 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;
 }
示例#3
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();
 }