forked from Doenet/DoenetTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loader sign in test and create portfolio courseId
- Loading branch information
1 parent
e63643b
commit 44181aa
Showing
6 changed files
with
172 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: POST'); | ||
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'; | ||
} | ||
|
||
$portfolioCourseId = ''; | ||
//Test if user already has a portfolio course UserId Course | ||
if ($success) { | ||
//Test if the user has a portfolio course | ||
//If they don't then make one. | ||
$sql = " | ||
SELECT courseId | ||
FROM course | ||
WHERE portfolioCourseForUserId = '$userId' | ||
"; | ||
$result = $conn->query($sql); | ||
|
||
if ($result->num_rows > 0) { | ||
$row = $result->fetch_assoc(); | ||
$portfolioCourseId = $row['courseId']; | ||
} else { | ||
//Make the portfolio course as the user doesn't have one | ||
$portfolioCourseId = include 'randomId.php'; | ||
$defaultRoleId = include 'randomId.php'; | ||
|
||
$sql = " | ||
INSERT INTO course | ||
(courseId,label,isPublic,defaultRoleId,portfolioCourseForUserId) | ||
VALUES | ||
('$portfolioCourseId','Portfolio Course',1,'$defaultRoleId','$userId') | ||
"; | ||
$conn->query($sql); | ||
|
||
$sql = " | ||
INSERT INTO course_role | ||
(courseId,roleId,label,isIncludedInGradebook,canViewCourse,canViewUnassignedContent, | ||
canViewContentSource,canEditContent,canPublishContent,canProctor,canViewAndModifyGrades, | ||
canViewActivitySettings,canModifyActivitySettings,canModifyCourseSettings,canViewUsers, | ||
canManageUsers,isAdmin,isOwner) | ||
VALUES | ||
('$portfolioCourseId','$defaultRoleId','Owner',0,1,1,1,1,1,1,1,1,1,1,1,1,1,1) | ||
"; | ||
$conn->query($sql); | ||
|
||
$sql = " | ||
INSERT INTO course_user | ||
(courseId,userId,dateEnrolled,roleId) | ||
VALUES | ||
('$portfolioCourseId','$userId',NOW(),'$defaultRoleId') | ||
"; | ||
$conn->query($sql); | ||
} | ||
} | ||
|
||
$response_arr = [ | ||
'success' => $success, | ||
'message' => $message, | ||
'portfolioCourseId' => $portfolioCourseId, | ||
]; | ||
|
||
// set response code - 200 OK | ||
http_response_code(200); | ||
|
||
// make it json format | ||
echo json_encode($response_arr); | ||
$conn->close(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?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'; | ||
} | ||
|
||
$portfolioCourseId = ''; | ||
|
||
//Assume we are updating the activity and need the current settings | ||
if ($success) { | ||
$sql = " | ||
SELECT courseId FROM course WHERE portfolioCourseForUserId = '$userId' | ||
"; | ||
$result = $conn->query($sql); | ||
|
||
if ($result->num_rows > 0) { | ||
$row = $result->fetch_assoc(); | ||
$portfolioCourseId = $row['courseId']; | ||
} | ||
} | ||
|
||
$response_arr = [ | ||
'success' => $success, | ||
'message' => $message, | ||
'portfolioCourseId' => $portfolioCourseId, | ||
]; | ||
|
||
http_response_code(200); | ||
|
||
// make it json format | ||
echo json_encode($response_arr); | ||
|
||
$conn->close(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters