本文整理汇总了PHP中ca_metadata_elements::getElementDatatype方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_metadata_elements::getElementDatatype方法的具体用法?PHP ca_metadata_elements::getElementDatatype怎么用?PHP ca_metadata_elements::getElementDatatype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_metadata_elements
的用法示例。
在下文中一共展示了ca_metadata_elements::getElementDatatype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveInlineEdit
/**
* Save edits from "spreadsheet" (editable results) mode
*
*/
public function saveInlineEdit($pa_options = null)
{
global $g_ui_locale_id;
$pa_changes = $this->request->getParameter("changes", pArray);
$vs_resp = array();
$o_dm = Datamodel::load();
if (!is_array($pa_changes) || !sizeof($pa_changes)) {
$va_resp['messages'][0] = _t("Nothing to save");
} else {
foreach ($pa_changes as $vn_i => $pa_change) {
$ps_table = $pa_change['table'];
$pa_bundle = explode("-", $ps_bundle = $pa_change['bundle']);
$pn_id = (int) $pa_change['id'];
$ps_val = $pa_change['value'];
if (!($t_instance = $o_dm->getInstanceByTableName($ps_table, true))) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Invalid table: %1', $ps_table));
} else {
if (!$t_instance->load($pn_id)) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Invalid id: %1', $pn_id));
} else {
if (!$t_instance->isSaveable($this->request)) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.'));
} elseif ($pa_bundle[0] == 'preferred_labels') {
if ($this->request->user->getBundleAccessLevel($ps_table, $pa_bundle[0]) != __CA_BUNDLE_ACCESS_EDIT__) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.'));
} else {
$vn_label_id = $t_instance->getPreferredLabelID($g_ui_locale_id);
$va_label_values = array();
if (sizeof($pa_bundle) == 1) {
// is generic "preferred_labels"
$va_label_values[$t_instance->getLabelDisplayField()] = $ps_val;
} else {
$vs_preferred_label_element = $pa_bundle[1];
$va_label_values[$vs_preferred_label_element] = $ps_val;
}
if ($vn_label_id) {
$t_instance->editLabel($vn_label_id, $va_label_values, $g_ui_locale_id, null, true);
// TODO: what about type?
} else {
$t_instance->addLabel($va_label_values, $g_ui_locale_id, null, true);
}
if ($t_instance->numErrors()) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Could not set preferred label %1 to %2: %3', $ps_bundle, $ps_val, join("; ", $t_instance->getErrors())));
} else {
$va_resp['messages'][$pn_id] = array('message' => _t('Set preferred label %1 to %2', $ps_bundle, $ps_val), 'value' => $ps_val);
}
}
} elseif ($t_instance->hasField($ps_bundle)) {
if ($this->request->user->getBundleAccessLevel($ps_table, $ps_bundle) != __CA_BUNDLE_ACCESS_EDIT__) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.'));
} else {
// is it a list?
$t_list = new ca_lists();
$t_instance->setMode(ACCESS_WRITE);
if (($vs_list_code = $t_instance->getFieldInfo($ps_bundle, 'LIST')) && ($va_item = $t_list->getItemFromListByLabel($vs_list_code, $ps_val))) {
$t_instance->set($ps_bundle, $va_item['item_value']);
} elseif (($vs_list_code = $t_instance->getFieldInfo($ps_bundle, 'LIST_CODE')) && ($vn_item_id = $t_list->getItemIDFromListByLabel($vs_list_code, $ps_val))) {
$t_instance->set($ps_bundle, $vn_item_id);
} else {
$t_instance->set($ps_bundle, $ps_val);
}
$t_instance->update();
if ($t_instance->numErrors()) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Could not set %1 to %2: %3', $ps_bundle, $ps_val, join("; ", $t_instance->getErrors())));
} else {
$va_resp['messages'][$pn_id] = array('message' => _t('Set %1 to %2', $ps_bundle, $ps_val), 'value' => $ps_val);
}
}
} elseif ($t_instance->hasElement($ps_bundle)) {
$vn_datatype = ca_metadata_elements::getElementDatatype($ps_bundle);
// Check if it repeats?
if ($vn_count = $t_instance->getAttributeCountByElement($ps_bundle) > 1) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Cannot edit <em>%1</em> here because it has multiple values. Try editing it directly.', mb_strtolower($t_instance->getDisplayLabel("{$ps_table}.{$ps_bundle}"))));
} elseif (!in_array($vn_datatype, array(1, 2, 3, 5, 6, 8, 9, 10, 11, 12))) {
// Check if it's a supported type?
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('Cannot edit <em>%1</em> here. Try editing it directly.', mb_strtolower($t_instance->getDisplayLabel("{$ps_table}.{$ps_bundle}"))));
} elseif ($this->request->user->getBundleAccessLevel($ps_table, $ps_bundle) != __CA_BUNDLE_ACCESS_EDIT__) {
$va_resp['errors'][$pn_id] = array('error' => 100, 'message' => _t('You are not allowed to edit this.'));
} else {
// Do edit
$t_instance->setMode(ACCESS_WRITE);
$vs_val_proc = null;
if ($vn_datatype == 3) {
if ($vn_id = ca_list_items::find(array('preferred_labels' => array('name_plural' => $ps_val)), array('returnAs' => 'firstId'))) {
$t_instance->replaceAttribute(array('locale_id' => $g_ui_locale_id, $ps_bundle => $vn_id), $ps_bundle);
// convert list codes to display text
$t_list_item = new ca_list_items((int) $vn_id);
if ($t_list_item->getPrimaryKey()) {
$vs_val_proc = $t_list_item->get('ca_list_items.preferred_labels.name_plural');
}
}
} else {
$t_instance->replaceAttribute(array('locale_id' => $g_ui_locale_id, $ps_bundle => $ps_val), $ps_bundle);
}
$t_instance->update();
if (!$vs_val_proc) {
//.........这里部分代码省略.........
示例2: getPlacements
//.........这里部分代码省略.........
// Intrinsics are editable, except for type_id
//
if ($va_bundle_name[1] == $t_subject->getTypeFieldName()) {
$va_placements[$vn_placement_id]['allowInlineEditing'] = false;
$va_placements[$vn_placement_id]['inlineEditingType'] = null;
} else {
if (isset($va_bundle_name[1])) {
// check if identifier is editable
$id_editable = $t_subject->opo_idno_plugin_instance->isFormatEditable($vs_subject_table);
// Do not allow in-line editing if the intrinsic element is identifier and
// a). is not editable (editable = 0 in multipart_id_numbering.conf)
// b). consists of multiple elements
if ($va_bundle_name[1] == $t_subject->getProperty('ID_NUMBERING_ID_FIELD') && $id_editable == false) {
$va_placements[$vn_placement_id]['allowInlineEditing'] = false;
} else {
$va_placements[$vn_placement_id]['allowInlineEditing'] = true;
}
}
switch ($t_subject->getFieldInfo($va_bundle_name[1], 'DISPLAY_TYPE')) {
case 'DT_SELECT':
if (($vs_list_code = $t_subject->getFieldInfo($va_bundle_name[1], 'LIST')) || ($vs_list_code = $t_subject->getFieldInfo($va_bundle_name[1], 'LIST_CODE'))) {
$va_placements[$vn_placement_id]['inlineEditingType'] = DT_SELECT;
if (!is_array($va_list_labels = $t_list->getItemsForList($vs_list_code, array('labelsOnly' => true)))) {
$va_list_labels = array();
}
$va_placements[$vn_placement_id]['inlineEditingListValues'] = array_values($va_list_labels);
} else {
$va_placements[$vn_placement_id]['inlineEditingType'] = DT_FIELD;
}
break;
default:
$va_placements[$vn_placement_id]['inlineEditingType'] = DT_FIELD;
break;
}
}
} elseif ($t_subject->hasElement($va_bundle_name[1])) {
$vn_data_type = ca_metadata_elements::getElementDatatype($va_bundle_name[1]);
switch ($vn_data_type) {
case 1:
case 2:
case 5:
case 6:
case 8:
case 9:
case 10:
case 11:
case 12:
$va_placements[$vn_placement_id]['allowInlineEditing'] = true;
$va_placements[$vn_placement_id]['inlineEditingType'] = DT_FIELD;
break;
case 3:
// lists
if ($t_element = ca_metadata_elements::getInstance($va_bundle_name[1])) {
switch ($t_element->getSetting('render')) {
case 'select':
case 'yes_no_checkboxes':
case 'radio_buttons':
case 'checklist':
$va_placements[$vn_placement_id]['allowInlineEditing'] = true;
$va_placements[$vn_placement_id]['inlineEditingType'] = DT_SELECT;
$va_placements[$vn_placement_id]['inlineEditingListValues'] = array_values($t_list->getItemsForList($t_element->get("list_id"), array('labelsOnly' => true)));
break;
case 'lookup':
case 'horiz_hierbrowser':
case 'horiz_hierbrowser_with_search':
case 'vert_hierbrowser':
$va_placements[$vn_placement_id]['allowInlineEditing'] = true;
$va_placements[$vn_placement_id]['inlineEditingType'] = DT_LOOKUP;
$va_placements[$vn_placement_id]['inlineEditingList'] = $t_element->get('list_id');
break;
default:
// if it's a render setting we don't know about it's not editable
$va_placements[$vn_placement_id]['allowInlineEditing'] = false;
$va_placements[$vn_placement_id]['inlineEditingType'] = null;
break;
}
}
break;
default:
$va_placements[$vn_placement_id]['allowInlineEditing'] = false;
$va_placements[$vn_placement_id]['inlineEditingType'] = null;
break;
}
} else {
$va_placements[$vn_placement_id]['allowInlineEditing'] = false;
$va_placements[$vn_placement_id]['inlineEditingType'] = null;
}
} else {
// Related bundles are never inline-editable (for now)
$va_placements[$vn_placement_id]['allowInlineEditing'] = false;
$va_placements[$vn_placement_id]['inlineEditingType'] = null;
}
}
} else {
if ($pb_return_all_available_if_empty) {
$va_placements = $this->getAvailableBundles($this->get('table_num'));
}
}
return ca_bundle_displays::$s_placement_list_cache[$vs_cache_key] = $va_placements;
}