function refresh_listview_exit($req) { $db_name = @$req['db_name']; $table_name = @$req['table_name']; $counter = refresh_listview($db_name, $table_name); clean_unmapper_data($db_name, $table_name); jsonp_nocache_exit(array('status' => 'ok', 'counter' => $counter)); }
function combobox_to_checkbox_exit($req) { $db_name = @$req['db_name']; $table_name = @$req['table_name']; $field = @$req['field']; $seperator = @$req['seperator']; if (all_empty(array($db_name, $table_name, $field, $seperator))) { jsonp_nocache_exit(array('status' => 'error', 'error' => 'command parameter error.')); } $data_path = table_root($db_name, $table_name); $schema = object_read("{$data_path}/schema.json"); $fields = $schema['fields']; $group_name = null; $field_type = null; foreach ($fields as $group => $items) { foreach ($items as $name => $value) { if ($name === $field) { $group_name = $group; $field_type = $value; break 2; } } } if (all_empty(array($group_name, $field_type))) { jsonp_nocache_exit(array('status' => 'error', 'error' => 'command parameter field name error.')); } if ($field_type !== 'jqxComboBox') { jsonp_nocache_exit(array('status' => 'error', 'error' => 'the target field not a combobox.')); } $schema['fields'][$group_name][$field] = 'jqxCheckBox'; object_save("{$data_path}/schema.json", $schema); foreach (glob("{$data_path}/*.json") as $file) { if (is_dir($file)) { continue; } if (!preg_match('~/(\\d+)\\.json$~', $file, $matches)) { continue; } $item_id = $matches[1]; $data_obj = object_read($file); if (empty($data_obj)) { continue; } $combo_str = @$data_obj[$group_name][$field]; if (empty($combo_str)) { continue; } $check_arr = explode($seperator, $combo_str); $data_obj[$group_name][$field] = $check_arr; object_save($file, $data_obj); } $counter = refresh_listview($db_name, $table_name); jsonp_nocache_exit(array('status' => 'ok', 'counter' => $counter)); }
function join_multiple_data($db_name, $table_name, $data, $force_empty = false) { $table_root = table_root($db_name, $table_name); $schema = object_read("{$table_root}/schema.json"); $mapper = object_read("{$table_root}/mapper.json"); $refresh_files = array(); $listviews = array(); //批量处理各个数据 foreach ($data as $sub_data) { if ($req_id = __data_exists($table_root, $schema, $mapper, $sub_data)) { set_data_id($sub_data, $req_id); list($req_id, $new_data, $ori_data) = update_single_data($table_root, $sub_data, $force_empty); if ($new_data) { //共享字段的同步 foreach (sync_affected_fields($table_root, $req_id, $ori_data) as $file) { $refresh_files[] = $file; } //记录需要刷新listview的数据文件名 $refresh_files[] = "{$table_root}/{$req_id}.json"; $listviews[] = make_listview_item($table_root, $new_data); } } else { list($req_id, $new_data) = create_single_data($table_root, $sub_data); if ($new_data) { foreach (sync_affected_fields($table_root, $req_id) as $file) { $refresh_files[] = $file; } $refresh_files[] = "{$table_root}/{$req_id}.json"; $listviews[] = make_listview_item($table_root, $new_data); } } } //批量刷新listview refresh_listview($db_name, $table_name, $refresh_files); return array('status' => 'ok', 'listview' => $listviews); }