本文整理汇总了PHP中ca_lists::getItemFromListByLabel方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_lists::getItemFromListByLabel方法的具体用法?PHP ca_lists::getItemFromListByLabel怎么用?PHP ca_lists::getItemFromListByLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_lists
的用法示例。
在下文中一共展示了ca_lists::getItemFromListByLabel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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) {
//.........这里部分代码省略.........