fieldtype = TRUE; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
$this->defaulttype = 'VARCHAR'; // 当用户没有选择字段类型时的缺省值
}
// 调出字段遍历出来
protected function _get_select_field($option, $field, $id, $at) {
$str = '
';
foreach ($field as $t) {
if ($t['disabled']) {
continue;
} elseif ($t['fieldtype'] == 'Merge') {
continue;
} elseif ($t['fieldtype'] == 'Group') {
continue;
}
$str.= '';
}
$str.= '
';
return $str;
}
/**
* 字段相关属性参数
*
* @param array $value 值
* @return string
*/
public function option($option, $field = NULL) {
$data = dr_format_option_array($option['options']);
if (!$data) {
$ld = dr_lang('需要保存字段配置后才能配置联动关系');
} else {
$ld = '';
}
$option['options'] = isset($option['options']) ? $option['options'] : 'name1|1'.PHP_EOL.'name2|2';
return [
'
'.$this->field_type($option['fieldtype'], $option['fieldlength']).'
'
];
}
/**
* 字段表单输入
*
* @return string
*/
public function input($field, $value = '') {
// 字段禁止修改时就返回显示字符串
if ($this->_not_edit($field, $value)) {
return $this->show($field, $value);
}
// 字段存储名称
$name = $field['fieldname'];
// 字段显示名称
$text = ($field['setting']['validate']['required'] ? ' * ' : '').dr_lang($field['name']);
// 字段提示信息
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? ''.$field['setting']['validate']['tips'].'' : '';
// 字段默认值
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
$str = '';
// 显示方式
$show_type = (int)$field['setting']['option']['show_type'];
if ($field['setting']['option']['is_field_ld'] && $field['setting']['option']['field_ld']) {
$str.= '';
$field['setting']['validate']['formattr'].= ' onclick="field_ld_'.$name.'(this.value)"';
}
// 表单选项
$options = dr_format_option_array($field['setting']['option']['options']);
if ($options) {
foreach ($options as $v => $n) {
$s = $v == $value ? ' checked' : '';
$kj = '';
$str.= '';
}
}
return $this->input_format($name, $text, ''.$str.'
'.$tips);
}
/**
* 字段表单显示
*
* @param string $field 字段数组
* @param array $value 值
* @return string
*/
public function show($field, $value = null) {
$options = dr_format_option_array($field['setting']['option']['options']);
$str = ' '.(isset($options[$value]) ? dr_lang($options[$value]) : dr_lang('未选择')).'
';
return $this->input_format($field['fieldname'], $field['name'], $str);
}
}