<?php
header("Content-Type: application/json"); //Set header for outputing the JSON information
function __autoload($class) {
	if ($class == 'ProfileUser') {
		$class = 'User';
	}
	if ($class == 'PublicProposedDate') {
		$class = 'BadmintonDate';
	}
	if (($class == 'Message') || ($class == 'Conversation')) {
		$class = 'WebMessage';
	}
	require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/$class.php";
}
$mysqli = Database::connection();
$sql = "SELECT date_id, datename, begin_datetime, end_datetime 
FROM `badminton_dates`
WHERE DATE(begin_datetime) >= CURDATE()";
$result = $mysqli->query($sql)
or die ($mysqli->error);
$dates = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
	$badminton_date = new BadmintonDate($row);
	$badminton_date->get_attendees();
	array_push($dates, $badminton_date);
}
http_response_code(200);
echo json_encode($dates, JSON_PRETTY_PRINT);
?>
Example #2
0
	final public function join_badminton_date(BadmintonDate $badminton_date) {
		/*
		(Date) -> Bool
		The current user attempts to join the badminton date
		 */
		if ($this->user_id && $badminton_date->date_id) {
			$sql = "INSERT INTO joins (date_id, user_id, date_joined, status) VALUES('$badminton_date->date_id', '$this->user_id', NOW(), '" . self::JOINED_STATUS . "')
			ON DUPLICATE KEY UPDATE join_id = join_id";
			//echo $sql;
			$result = $this->dbc->query($sql)
			or die ($this->dbc->error);

			$affected_rows = $this->dbc->affected_rows;
			if ($affected_rows == 1) {
				//New row was inserted
				//Push the notificatoins and check for method allowed
				$this->get_fields();
				$action = new JoinBadmintonDate(array(
					'joiner' => clone $this,
					'badminton_date' =>  $badminton_date,
					'trigger' => clone $this)
				);
				//Push action
				ActionPusher::push_action($action);
				//Push notification, only if the current user is not the creator of the badminton date
				//Push the pending action to evaluate the hoster, only if the current user is not the creator of the badminton date
				if ($this->user_id != $badminton_date->creator->user_id) {
					NotificationPusher::push_notification($action);
					$sql = "SELECT end_datetime FROM badminton_date WHERE date_id = '$badminton_date->date_id'";
					$result = $this->dbc->query($sql)
					or die ($this->dbc->error);
					if ($result->num_rows == 1){
						$end_datetime = mysqli_fetch_row($result)[0];
						//Issue the pending endorsement
						$sql = "INSERT INTO `pending_actions` (date_issued, awaiting_user, active) VALUES ('$end_datetime', '$this->user_id', '" . self::ACTIVE . "')";
						$result = $this->dbc->query($sql)
						or die ($this->dbc->error);

						$token_id = $this->dbc->insert_id;
						$badminton_date->get_creator();
						$sql = "INSERT INTO `pending_user_endorsements` (token_id, user_to_endorse, date_id) VALUES ('$token_id', '{$badminton_date->creator->user_id}', '$badminton_date->date_id')";
						$result = $this->dbc->query($sql)
						or die ($this->dbc->error);
						return true;
					}
					else {
						throw new OutOfRangeException('OutOfRangeException occured on method call ' . __METHOD__ . ' because the date id does not exist');
					}
				}
				else {
					return true;
				}
			}
			return true;
		}
		else {
			return false;
		}
	}