function add_map($student_id, $json_string) { $json_arr = json_decode($json_string, true); $xml_object = json_arr_to_xml($json_arr); $student_record = get_user_maps($student_id); if (empty($student_record)) { $xml_of_maps = simplexml_load_string("<maps></maps>"); xml_adopt($xml_of_maps, $xml_object); $map_as_string = xml_to_string($xml_of_maps); } else { $maps = get_user_maps($student_id); xml_adopt($maps, $xml_object); $map_as_string = xml_to_string($maps); } $query = "UPDATE Students SET MAPS='{$map_as_string}' WHERE STUDENT_ID={$student_id}"; exec_query($query); }
$map = from_db_to_json($conceptmap); $map = json_decode($map, true); // echo $map['id']; if ($map['id'] != null) { deliver_response("Map retrieving successful", $map); } else { deliver_response("Map not found"); } break; case 'PUT': $json_string = file_get_contents('php://input'); $json_arr = json_decode($json_string, true); $conceptmap->mapxml = ""; if (empty($conceptmap->mapxml)) { // updating empty record with whole map $mapxml = json_arr_to_xml($json_arr); $mapxml = xml_to_string($mapxml); } else { // updating only the differences // $mapxml = format_xml($conceptmap->mapxml); // $mapxml = xml_maps_to_json($mapxml); // $mapxml = json_decode($mapxml, true)[0]; // foreach ($mapxml as $key => $value) { // if (!empty($json_arr[$key])) { // $mapxml[$key] = $json_arr[$key]; // } // } } $conceptmap->mapxml = $mapxml; $DB->update_record($table, $conceptmap, $bulk = false); // super_echo($conceptmap); // result as XML