Beispiel #1
0
<?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);
$user_id = $data->user_id;
try {
	if (is_numeric($user_id)) {
		$user = new ProfileUser(array(
			'user_id' => $user_id)
		);
		$arrayOfActions = $user->get_activity();
		if ($arrayOfActions) {
			http_response_code(200);
			echo json_encode($arrayOfActions, JSON_PRETTY_PRINT);
		}
		else {
			throw new RuntimeException('RuntimeException occured on request, could not fetch activity for some reason');
		}
	}
}
catch (Exception $e) {
	http_response_code(400);
	Database::print_exception($e);
}
Beispiel #2
0
	}
	require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/$class.php";
}
$request = file_get_contents('php://input');
$data = json_decode($request);
$profile_id = $data->profile_id;
//$profile_id  = 1069062649779910;
try {
	if (is_numeric($profile_id)) {
		$mysqli = Database::connection();
		$sql = "SELECT user_id, username, reputation, date_registered, avatar_link, last_seen, email, avatar, commuter, program, level, avatar_link, bio, accolades FROM `users` WHERE user_id = '$profile_id'";
		$result = $mysqli->query($sql)
		or die ($mysqli->error);
		if ($result->num_rows == 1) {
			$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
			$profile = new ProfileUser($row);
			$profile->get_number_of_joins();
			$profile->get_number_of_leaves();
			$profile->get_number_of_hosted_events();

			$denominator = ($profile->number_of_leaves == 0) ? 1 : $profile->number_of_leaves;
			if ($profile->number_of_joins != 0) {
				$profile->absence_ratio = ($profile->number_of_leaves / $profile->number_of_joins);
				$profile->absence_ratio = round($profile->absence_ratio, 3);
			}
			else {
				$profile->absence_ratio = 'N/A';
			}
			$profile->join_leave_ratio = $profile->number_of_joins / $denominator;
			
			http_response_code(200);