Skip to content

Commit

Permalink
half done with viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharles committed Mar 23, 2023
1 parent 36a76b9 commit 29a857c
Show file tree
Hide file tree
Showing 7 changed files with 629 additions and 15 deletions.
46 changes: 41 additions & 5 deletions src/Api/getPortfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,50 @@
$success = true;
$message = '';

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

$publicActivities = [];
$privateActivities = [];
$fullName = '';
$notMe = false;

//Assume we are updating the activity and need the current settings
if ($success) {
$courseId = mysqli_real_escape_string($conn, $_REQUEST['courseId']);

$sql = "
SELECT courseId
FROM course
WHERE portfolioCourseForUserId='$userId'
";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if ($courseId != $row['courseId']) {
$notMe = true;
}
} else {
$notMe = true; //If not signed it then it's definitly not you
}
}

if ($success && !$notMe) {
$sql = "
SELECT firstName,
lastName
FROM user
WHERE userId='$userId'
";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$fullName = $row['firstName'] . ' ' . $row['lastName'];
}

$sql = "
SELECT cc.doenetId,
cc.imagePath,
Expand Down Expand Up @@ -59,6 +93,8 @@
'message' => $message,
'publicActivities' => $publicActivities,
'privateActivities' => $privateActivities,
'fullName' => $fullName,
'notMe' => $notMe,
];

http_response_code(200);
Expand Down
83 changes: 83 additions & 0 deletions src/Api/getPublicPortfolio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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 = [];
$fullName = '';

$courseId = mysqli_real_escape_string($conn, $_REQUEST['courseId']);

//Assume we are updating the activity and need the current settings
if ($success) {
$sql = "
SELECT u.firstName,
u.lastName
FROM user AS u
LEFT JOIN course AS c
ON u.userId = c.portfolioCourseForUserId
WHERE c.courseId = '$courseId'
";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$fullName = $row['firstName'] . ' ' . $row['lastName'];
}

$sql = "
SELECT cc.doenetId,
cc.imagePath,
cc.label,
p.doenetId AS 'pageDoenetId'
FROM course_content AS cc
LEFT JOIN pages AS p
ON p.containingDoenetId = cc.doenetId
WHERE cc.courseId = '$courseId'
AND cc.isPublic = '1'
";
$result = $conn->query($sql);

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

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

http_response_code(200);

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

$conn->close();

?>
12 changes: 6 additions & 6 deletions src/Tools/_framework/Paths/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { useRecoilState, useSetRecoilState } from 'recoil';
import { Carousel } from '../../../_reactComponents/PanelHeaderComponents/Carousel';
// import RouterLogo from '../RouterLogo';

export async function loader(){
const response = await fetch('/api/getHPCarouselData.php');
const data = await response.json();
return data;
}

const HomeIntroVideo = lazy(() => import('./HomeIntroVideo'));

const SectionText = styled.div`
Expand Down Expand Up @@ -211,12 +217,6 @@ const BarMenu = styled.div`
column-gap: 20px;
`

export async function loader(){
const response = await fetch('/api/getHPCarouselData.php');
const data = await response.json();
return data;
}

export function Home() {
let context = useOutletContext();
const loaderData = useLoaderData();
Expand Down
15 changes: 11 additions & 4 deletions src/Tools/_framework/Paths/Portfolio.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ export async function loader({params}){
return redirect(`/portfolio/${data.portfolioCourseId}`)
}

const response = await fetch('/api/getPortfolio.php');
const response = await fetch(`/api/getPortfolio.php?courseId=${params.courseId}`);
const data = await response.json();
return {publicActivities:data.publicActivities,
privateActivities:data.privateActivities};
if (data.notMe){
return redirect(`/portfolio/${params.courseId}/public`);
}

return {
fullName:data.fullName,
publicActivities:data.publicActivities,
privateActivities:data.privateActivities,
};
}

const SecondHeader = styled.header`
Expand Down Expand Up @@ -176,7 +183,7 @@ export function Portfolio(){
<SecondHeader>
<h1 style={{
lineHeight: '0.1em'
}}>Name Here</h1>
}}>{data.fullName}</h1>
<h4 style={{
lineHeight: '0.1em'
}}>Portfolio</h4>
Expand Down
Loading

0 comments on commit 29a857c

Please sign in to comment.