function get_party_people($party_id, $db_conn) { // First, get all of the people $party_people_query = $db_conn->prepare("CALL get_people_in_party(:party_id)"); $party_people_query->bindParam(":party_id", $party_id); $party_people_query->execute(); $people = $party_people_query->fetchAll(PDO::FETCH_ASSOC); $party_people_query->closeCursor(); // Get the available food choices $food_choices = get_food_choices($db_conn); // Next, get the allergy information for each person $allergy_query = $db_conn->prepare("CALL get_allergies(:person_id)"); for ($i = 0; $i < count($people); ++$i) { // Map all boolean results to actual booleans (for javascript) $people[$i]["is_attending"] = map_to_boolean($people[$i]["is_attending"]); $people[$i]["is_attending_rehearsal"] = map_to_boolean($people[$i]["is_attending_rehearsal"]); $people[$i]["is_attending_movie"] = map_to_boolean($people[$i]["is_attending_movie"]); $people[$i]["is_invited_to_movie"] = map_to_boolean($people[$i]["is_invited_to_movie"]); $people[$i]["is_invited_to_rehearsal"] = map_to_boolean($people[$i]["is_invited_to_rehearsal"]); $people[$i]["is_plus_one"] = map_to_boolean($people[$i]["is_plus_one"]); $people[$i]["over_21"] = map_to_boolean($people[$i]["over_21"]); $allergy_query->bindParam(":person_id", $people[$i]["person_id"]); $allergy_query->execute(); $allergies = array(); while ($allergy = $allergy_query->fetch(PDO::FETCH_ASSOC)) { array_push($allergies, $allergy["food_allergy"]); } $people[$i]["allergies"] = $allergies; $allergy_query->closeCursor(); } return $people; }
if ($party_current_plus_ones >= $party_max_plus_ones) { $return_value["status"] = false; $return_value["reason"] = "Max number of plus ones reached"; } else { $new_person_id = add_plus_one($first_name, $last_name, $food_pref, $over_21, $is_attending, $party_id, $db_conn); if ($new_person_id < 0) { $return_value["status"] = false; $return_value["reason"] = "Error adding person"; } else { $return_value["status"] = true; $return_value["person_id"] = $new_person_id; $return_value["first_name"] = $first_name; $return_value["last_name"] = $last_name; $return_value["food_pref"] = $food_pref; $return_value["over_21"] = $over_21; $return_value["is_attending"] = $is_attending; $food_choices = get_food_choices($db_conn); } } } } } } } } } header("Content-type: application/json"); header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Expires: 0"); echo json_encode($return_value);
function validate_food_choice($food_choice, $db_conn) { $food_choices = get_food_choices($db_conn); return $food_choice > 0 && $food_choice <= count($food_choices); }
$login_query->bindParam(":login_hash", $login_hash); $login_query->execute(); $results = $login_query->fetchAll(PDO::FETCH_ASSOC); if (count($results) > 0) { $login_query->closeCursor(); $party_id = $results[0]["party_id"]; $return_value["login_successful"] = true; // Generate the login token $return_value["auth_token"] = generate_login_token($party_id, $db_conn); $return_value["party_id"] = $party_id; // Get party data $return_value["party_info"] = get_party_data($party_id, $db_conn); $return_value["party_info"]["current_plus_ones"] = get_current_plus_ones($party_id, $db_conn); // Get people in party $return_value["party_people"] = get_party_people($party_id, $db_conn); // Get music suggestions $return_value["music_suggestions"] = get_music_suggestions($party_id, $db_conn); // Get the food choices $return_value["food_choices"] = get_food_choices($db_conn); } else { $return_value["login_successful"] = false; $return_value["reason"] = "Invalid login code"; } } } } header("Content-type: application/json"); header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Expires: 0"); echo json_encode($return_value);