jsonp_nocache_exit(array('status' => 'error', 'error' => 'not mapper in parameter')); } $is_new_data = true; do { if (empty($mapper)) { break; } $map_val = @$mapper[$map_key]; if (empty($map_val)) { break; } $map_file = "{$table_root}/{$map_val}.json"; if (!file_exists($map_file)) { break; } $ori_data = object_read($map_file); if (empty($ori_data)) { break; } if (!set_data_id($data, $map_val)) { jsonp_nocache_exit(array('status' => 'error', 'error' => 'no id field')); } $is_new_data = false; } while (false); if ($is_new_data) { $output = create_new_data($db_name, $table_name, $data); } else { $output = update_current_data($db_name, $table_name, $data); } jsonp_nocache_exit($output); }
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); }