function check_table_format($student_id, $json_string, $map_id = null) { $json_arr = json_decode($json_string, TRUE); if (empty($json_arr['id']) && empty($map_id)) { $maps = get_list_of_maps($student_id); $list = array(); foreach ($maps as $map) { $id = $map['id']; $list[$id] = $id; } $id = 1; while (!empty($list[$id])) { $id++; } } else { $id = $map_id; } $must_attributes = array('title' => null, 'id' => $id, 'concepts' => [], 'relationships' => []); if (!empty($json_arr)) { foreach ($must_attributes as $key => $value) { if (!empty($json_arr[$key])) { $must_attributes[$key] = $json_arr[$key]; } } $result = json_encode($must_attributes); return $result; } else { return null; } }
function does_map_exist_by_title($student_id, $title) { $list = get_list_of_maps($student_id); foreach ($list as $map) { foreach ($map as $key => $value) { if ($value == $title) { return true; } } } return false; }
deliver_response(405, "Request Method Not Allowed."); } else { if (does_student_exist($student_id)) { switch ($request_method) { case "GET": if ($map_id != null) { if (!does_map_exist_by_id($student_id, $map_id)) { deliver_response(200, "Map with id={$map_id} does not exist"); break; } $map = get_user_maps($student_id, $map_id); $map = xml_maps_to_json($map); $map = json_decode($map, true); deliver_response(200, "Map retrieving successful", $map[0]); } else { $maps = get_list_of_maps($student_id); if (empty($maps)) { deliver_response(200, "Maps were not found"); } else { deliver_response(200, "All Maps retrieved successful", $maps, "mapsList"); } } break; case "POST": $json_arr = json_decode($json_string, true); if (is_array($json_arr)) { $title = $json_arr['title']; $map_id = $json_arr['id']; if (does_map_exist_by_title($student_id, $title)) { deliver_response(200, "Map with title '{$title}' already exists"); break;