Skip to content

Commit

Permalink
also
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharles committed Mar 14, 2023
1 parent cf288e2 commit e63643b
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/Api/getPortfolio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: GET');
header('Access-Control-Allow-Credentials: true');
header('Content-Type: application/json');

include 'db_connection.php';

$jwtArray = include 'jwtArray.php';
$userId = $jwtArray['userId'];

$success = true;
$message = '';

if ($userId == '') {
$success = false;
$message = 'Error: You need to sign in';
}

$publicActivities = [];
$privateActivities = [];

//Assume we are updating the activity and need the current settings
if ($success) {
$sql = "
SELECT doenetId,
imagePath,
label,
isPublic
FROM course_content
WHERE courseId = (SELECT courseId FROM course WHERE portfolioCourseForUserId = '$userId')
";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$activity = [
'doenetId' => $row['doenetId'],
'imagePath' => $row['imagePath'],
'label' => $row['label'],
'public' => $row['isPublic'],
];
if ($row['isPublic'] == '1') {
array_push($publicActivities, $activity);
} else {
array_push($privateActivities, $activity);
}
}
}
}

$response_arr = [
'success' => $success,
'message' => $message,
'publicActivities' => $publicActivities,
'privateActivities' => $privateActivities,
];

http_response_code(200);

// make it json format
echo json_encode($response_arr);

$conn->close();

?>

0 comments on commit e63643b

Please sign in to comment.