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.
- Loading branch information
1 parent
f7c1380
commit 20f2af2
Showing
3 changed files
with
258 additions
and
66 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,124 @@ | ||
<?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'); | ||
|
||
require 'defineDBAndUserAndCourseInfo.php'; | ||
|
||
$success = TRUE; | ||
$message = ""; | ||
|
||
$q = mysqli_real_escape_string($conn,$_REQUEST["q"]); | ||
|
||
if ($q == ""){ | ||
$success = FALSE; | ||
$message = 'Internal Error: missing search query'; | ||
} | ||
|
||
$matchingUsers = []; | ||
$matchingActivities = []; | ||
//Get Matching Activities | ||
if ($success) { | ||
$sql = " | ||
SELECT cc.doenetId, | ||
CAST(cc.jsonDefinition as CHAR) AS json, | ||
cc.imagePath, | ||
cc.label, | ||
cc.courseId, | ||
p.doenetId AS 'pageDoenetId' | ||
FROM course_content AS cc | ||
LEFT JOIN pages AS p | ||
ON p.containingDoenetId = cc.doenetId | ||
WHERE cc.label LIKE '%$q%' | ||
AND cc.isPublic = 1 | ||
AND cc.isDeleted = 0 | ||
LIMIT 100 | ||
"; | ||
|
||
$result = $conn->query($sql); | ||
if ($result->num_rows > 0) { | ||
while($row = $result->fetch_assoc()){ | ||
$json = json_decode($row['json'], true); | ||
array_push($matchingActivities,[ | ||
'doenetId' => $row['doenetId'], | ||
'courseId' => $row['courseId'], | ||
'version' => $json['version'], | ||
'content' => $json['content'], | ||
'imagePath' => $row['imagePath'], | ||
'label' => $row['label'], | ||
'public' => '1', | ||
'pageDoenetId' => $row['pageDoenetId'], | ||
]); | ||
} | ||
// $courseToOwnerFullName = []; | ||
foreach($matchingActivities as &$activity){ | ||
$courseId = $activity['courseId']; | ||
$sql = " | ||
SELECT u.firstName, | ||
u.lastName | ||
FROM course_role AS cr | ||
LEFT JOIN course_user AS cu | ||
ON cu.roleId = cr.roleId | ||
LEFT JOIN user AS u | ||
ON u.userId = cu.userId | ||
WHERE cr.courseId = '$courseId' | ||
AND cr.isOwner = 1 | ||
LIMIT 1 | ||
"; | ||
$result = $conn->query($sql); | ||
|
||
if ($result->num_rows > 0) { | ||
$row = $result->fetch_assoc(); | ||
$activity['fullName'] = $row['firstName'] . ' ' . $row['lastName']; | ||
} | ||
} | ||
} | ||
|
||
|
||
$sql = " | ||
SELECT c.courseId, | ||
u.firstName, | ||
u.lastName | ||
FROM user AS u | ||
LEFT JOIN course AS c | ||
ON c.portfolioCourseForUserId = u.userId | ||
WHERE c.portfolioCourseForUserId IS NOT NULL | ||
AND CONCAT(u.firstName, ' ', u.lastName) LIKE '%$q%' | ||
LIMIT 100 | ||
"; | ||
|
||
$result = $conn->query($sql); | ||
if ($result->num_rows > 0) { | ||
while($row = $result->fetch_assoc()){ | ||
$json = json_decode($row['json'], true); | ||
array_push($matchingUsers,[ | ||
'courseId' => $row['courseId'], | ||
'firstName' => $row['firstName'], | ||
'lastName' => $row['lastName'], | ||
]); | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
$response_arr = array( | ||
"success"=>$success, | ||
"message"=>$message, | ||
"searchResults"=>["users"=>$matchingUsers,"activities"=>$matchingActivities], | ||
); | ||
|
||
|
||
// 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
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