<?php header("Content-Type: application/json"); //Set header for outputing the JSON information require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/autoload.php'; $request = file_get_contents('php://input'); $data = json_decode($request); $date_id = $data->date_id; //$date_id = 16; try { $user = User::get_current_user(); if (is_numeric($date_id) && ($user instanceof CurrentUser)) { $date = new PublicProposedDate(array( 'date_id' => $date_id) ); $date->get_times(); $date->get_datename(); $result = $user->leave_date($date); if ($result) { http_response_code(200); } else { throw new OutOfBoundsException('OutOfBoundsException occured on request, the left deadline has already passed'); } } else { throw new UnexpectedValueException('UnexpectedValueException occured on request, parameters are not numeric or no user is not logged in currently'); } } catch (Exception $e) { http_response_code(400); Database::print_exception($e); }
ON t2.user_id = t1.creator_id WHERE MONTH(date_id) = MONTH('$date_string') ORDER BY t1.begin_datetime ASC"; $result = $mysqli->query($sql) or die ($mysqli->error); $dates = array(); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $row['creator'] = new ProfileUser($row); if ($row['confirmed']) { $badminton_date = new ConfirmedBadmintonDate($row); } else { if ($row['bool_group']) { $badminton_date = new GrouProposedDate($row); } else { $badminton_date = new PublicProposedDate($row); } } $badminton_date->get_attendees(); array_push($dates, $badminton_date); } http_response_code(200); echo json_encode($dates, JSON_PRETTY_PRINT); } } catch (Exception $e) { http_response_code(400); Database::print_exceptoin($e); } ?>
<?php header("Content-Type: application/json"); //Set header for outputing the JSON information require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/autoload.php'; $request = file_get_contents('php://input'); $data = json_decode($request); $date_id = $data->date_id; //$date_id = 19; $user = User::get_current_user(); try { if (($user instanceof User) && (is_numeric($date_id))) { $badminton_date = new PublicProposedDate(array( 'date_id' => $date_id) ); $badminton_date->get_datename(); $result = $user->join_badminton_date($badminton_date); if ($result) { http_response_code(200); } else { throw new RuntimeException('RuntimeException occured on request, could not join badminton date for some reason'); } } else { throw new UnexpectedValueException('UnexpectedValueException occured on request'); } } catch (Exception $e) { http_response_code(400); Database::print_exception($e); }
WHERE t1.date_id = '$date_id'"; //echo $sql; $result = $mysqli->query($sql) or die ($mysqli->error); if ($result->num_rows == 1) { $row = mysqli_fetch_array($result, MYSQLI_ASSOC); $row['creator'] = new ProfileUser($row); if ($row['confirmed']) { $badminton_date = new ConfirmedBadmintonDate($row); } else { if ($row['bool_group']) { $badminton_date = new GroupProposedDate($row); } else { $badminton_date = new PublicProposedDate($row); } } $badminton_date->get_attendees(); $badminton_date->get_absences(); http_response_code(200); echo json_encode($badminton_date, JSON_PRETTY_PRINT); } else { throw new OutOfRangeException('OutOfRangeException occured on request, date could not be found'); } } else { throw new UnexpectedValueException('UnexpectedValueException occured on request'); } }
$mysqli = Database::connection(); $sql = "SELECT t1.date_id, t1.datename, DATE_FORMAT(t1.begin_datetime, '%b %e, %Y - %r') as `begin_datetime`, DATE_FORMAT(t1.end_datetime, '%b %e, %Y - %r') as `end_datetime`, t1.creator_id as `user_id`, t2.username, t2.email, t2.reputation, t2.avatar, t1.bool_group, t1.confirmed FROM `badminton_dates` as t1 INNER JOIN `users` as t2 ON t2.user_id = t1.creator_id WHERE WEEKOFYEAR(date_id) = WEEKOFYEAR('$date_string') ORDER BY t1.begin_datetime ASC"; $result = $mysqli->query($sql) or die ($mysqli->error); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $row['creator'] = new ProfileUser($row); if ($row['confirmed']) { $badminton_date = new ConfirmedBadmintonDate($row); } else { if ($row['bool_group']) { $badminton_date = new GrouProposedDate($row); } else { $badminton_date = new PublicProposedDate($row); } } $badminton_date->get_attendees(); } } } catch (Exception $e) { http_response_code(400); Database::print_exceptoin($e); } ?>