/** * */ public function editAnnotation($pn_annotation_id, $pn_locale_id, $pa_properties, $pn_status, $pn_access, $pa_values = null, $pa_options = null) { if (!($vn_representation_id = $this->getPrimaryKey())) { return null; } if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) { // does not support annotations return null; } foreach ($o_coder->getPropertyList() as $vs_property) { if (!$o_coder->setProperty($vs_property, $pa_properties[$vs_property])) { // error setting values $this->errors = $o_coder->errors; return false; } } if (!$o_coder->validate()) { $this->errors = $o_coder->errors; return false; } $t_annotation = new ca_representation_annotations($pn_annotation_id); if ($t_annotation->getPrimaryKey() && $t_annotation->get('representation_id') == $vn_representation_id) { foreach ($o_coder->getPropertyList() as $vs_property) { $t_annotation->setPropertyValue($vs_property, $o_coder->getProperty($vs_property)); } $t_annotation->setMode(ACCESS_WRITE); $t_annotation->set('type_code', $o_coder->getType()); $t_annotation->set('locale_id', $pn_locale_id); $t_annotation->set('status', $pn_status); $t_annotation->set('access', $pn_access); $t_annotation->update(); if ($t_annotation->numErrors()) { $this->errors = $t_annotation->errors; return false; } if (is_array($pa_values)) { foreach ($pa_values as $vs_element => $va_value) { if (is_array($va_value)) { // array of values (complex multi-valued attribute) $t_annotation->addAttribute(array_merge($va_value, array('locale_id' => $pn_locale_id)), $vs_element); } else { // scalar value (simple single value attribute) if ($va_value) { $t_annotation->addAttribute(array('locale_id' => $pn_locale_id, $vs_element => $va_value), $vs_element); } } } } $t_annotation->update(); if ($t_annotation->numErrors()) { $this->errors = $t_annotation->errors; return false; } if (is_array($pa_properties) && isset($pa_properties['label'])) { $t_annotation->replaceLabel(array('name' => $pa_properties['label']), $pn_locale_id, null, true); } if (isset($pa_options['returnAnnotation']) && (bool) $pa_options['returnAnnotation']) { return $t_annotation; } return true; } return false; }
/** * */ 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(); }