Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hbiede committed Dec 31, 2020
1 parent 1cea7f4 commit 83c007a
Show file tree
Hide file tree
Showing 33 changed files with 441 additions and 218 deletions.
8 changes: 1 addition & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,7 @@
]
}
],
"react/sort-prop-types": [
"error",
{
"callbacksLast": true,
"requiredFirst": false
}
],
"react/jsx-props-no-spreading": "off",
"button-label-required/button-label-required": ["error"]
},
"settings": {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "la-feedback-system",
"version": "1.7.0",
"version": "2.0.0",
"private": true,
"license": "Apache-2.0",
"description": "A website to gather feedback from students after interactions with LAs",
Expand All @@ -10,6 +10,7 @@
"easymde": "^2.11.0",
"react": "^16.13.1",
"react-bootstrap": "^1.3.0",
"react-bootstrap-typeahead": "^5.1.4",
"react-dom": "^16.13.1",
"react-markdown": "^4.3.1",
"react-modal": "^3.11.2",
Expand All @@ -26,6 +27,7 @@
"@types/nodemailer-smtp-transport": "^2.7.4",
"@types/react": "^16.9.41",
"@types/react-bootstrap": "^1.0.1",
"@types/react-bootstrap-typeahead": "^5.1.1",
"@types/react-dom": "^16.9.8",
"@types/react-modal": "^3.10.6",
"@types/react-transition-group": "^4.4.0",
Expand All @@ -52,7 +54,7 @@
"ts-node": "^8.10.2",
"tsconfig-paths-webpack-plugin": "^3.3.0",
"typescript": "^3.9.7",
"webpack": "^4.42.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
},
"scripts": {
Expand Down
20 changes: 14 additions & 6 deletions public/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,22 @@ function get_ratings($la_username) {
'LEFT JOIN interactions i on feedback.interaction_key = i.interaction_key WHERE ' .
'feedback.interaction_key IN (SELECT interaction_key FROM interactions WHERE la_username_key = ' .
'(SELECT username_key FROM cse_usernames WHERE username = ?)) ORDER BY rating DESC;');
$ps->bind_param('s', $la_username);
$ps->execute();
$result = $ps->get_result();
$returnVal = [];
while ($row = $result->fetch_assoc()) {
array_push($returnVal, $row);
if ($ps) {
$ps->bind_param('s', $la_username);
$ps->execute();
if ($ps->error) {
error_log($ps->error);
} else {
$result = $ps->get_result();
while ($row = $result->fetch_assoc()) {
array_push($returnVal, $row);
}
$ps->close();
}
} else {
error_log("Failed to build PS to get ratings for $la_username");
}
$ps->close();
$conn->close();
return $returnVal;
}
Expand Down
2 changes: 1 addition & 1 deletion public/announcements.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function get_announcements($course = 'all') {
clear_announcements();
} else if (isset($obj) && isset($obj->{'body'})) {
set_announcements($obj->{'course'}, $obj->{'body'}, $obj->{'class'});
} else {
} else if (isset($obj->{'course'})) {
$response = get_announcements($obj->{'course'});
}
echo json_encode($response);
35 changes: 0 additions & 35 deletions public/data/lib/vader/example-results.txt

This file was deleted.

22 changes: 11 additions & 11 deletions public/data/tableSetup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

drop table if exists feedback;
drop table if exists interactions;
drop table if exists logins;
drop table if exists cse_usernames;
drop table if exists announcements;
drop view if exists course_interactions;
Expand All @@ -19,14 +20,15 @@ drop view if exists interaction_type_readable;

CREATE TABLE cse_usernames
(
username_key int auto_increment unique primary key,
username varchar(20) not null,
name varchar(70),
course varchar(10),
constraint cse_usernames_username_key_uindex
unique (username_key),
constraint cse_usernames_username_uindex
unique (username)
username_key int auto_increment unique primary key,

# Not unique due to potential for students to appear multiple times in the future
username varchar(20),
canvas_username varchar(20),

name varchar(70),
course varchar(10),
email varchar(100)
);

CREATE TABLE interactions
Expand Down Expand Up @@ -54,9 +56,7 @@ CREATE TABLE logins
login_key int auto_increment unique primary key,
la_username_key int not null,
time_of_interaction timestamp default current_timestamp() not null,
constraint interactions_interaction_key_uindex
unique (login_key),
constraint interactions_la_fk
constraint interactions_la_login_fk
foreign key (la_username_key) references cse_usernames (username_key)
on delete cascade
);
Expand Down
36 changes: 36 additions & 0 deletions public/getStudents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

// Returns a JSON encoded object formatted as follows:
//{
// students: Student[]
//}
//
// Where Student is defined as follows:
//{
// canvas_username: string,
// course: string,
// id: int,
// name: string
//}

include_once 'sqlManager.php';


function get_students() {
$conn = get_connection();
$ps = $conn->prepare('SELECT username_key AS id, name, course, canvas_username FROM cse_usernames;');
$ps->execute();
$result = $ps->get_result();
$returnVal = [];
while ($row = $result->fetch_assoc()) {
array_push($returnVal, $row);
}
$ps->close();
$conn->close();
return $returnVal;
}

$response = [
'students' => get_students(),
];
echo json_encode($response);
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
<script src="./feedback.js"></script>
<link rel="stylesheet" href="https://unpkg.com/easymde/dist/easymde.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">
<link rel="stylesheet" href="https://unpkg.com/react-bootstrap-typeahead/css/Typeahead.css">
</body>
</html>
16 changes: 7 additions & 9 deletions public/sendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// Call with a POST call with a JSON body as follows:
//{
// studentCSE: string,
// studentID: string,
// laCSE: string,
// course: string,
// interactionType: string | null
Expand All @@ -37,7 +37,8 @@ function send_email($obj, $interaction_id) {
$subject = shell_exec('grep "<title>" form.php | sed "s/\s*<\/*title>//gi"');
$body = shell_exec('cat ./data/emailBody.html | sed "s/INTERACTION_ID/' . $interaction_id .
'/gi" | sed "s/LA_NAME/' . $name . '/gi"');
if ($body && mail($obj->{'studentCSE'} . '@cse.unl.edu', $subject, $body, $headers)) {
$address = get_email($obj->{'studentID'});
if ($body && $address && mail($address, $subject, $body, $headers)) {
update_interaction_for_feedback($interaction_id);

header('Status: 200 OK');
Expand All @@ -56,15 +57,12 @@ function send_email($obj, $interaction_id) {
}

$obj = json_decode(file_get_contents('php://input'));
if (isset($obj) && isset($obj->{'laCSE'}) && isset($obj->{'studentCSE'}) && isset($obj->{'course'})
&& $obj->{'studentCSE'} !== $obj->{'laCSE'}) {
$student_username = str_replace('@cse.unl.edu', '',$obj->{'studentCSE'});
$interaction_id = add_interaction($obj->{'laCSE'}, $student_username, $obj->{'course'}, $obj->{'interactionType'});
if (isset($obj) && isset($obj->{'laCSE'}) && isset($obj->{'studentID'}) && isset($obj->{'course'})) {
$interaction_id = add_interaction($obj->{'laCSE'}, $obj->{'studentID'}, $obj->{'course'}, $obj->{'interactionType'});

if ($interaction_id !== null && $interaction_id > 0 &&
($obj->{'interactionType'} === 'cohort meeting' || has_been_a_week($obj->{'laCSE'}) ||
mt_rand() / mt_getrandmax() < FEEDBACK_RATE) &&
!received_email_today($obj->{'studentCSE'})) {
(has_been_a_week($obj->{'laCSE'}) || mt_rand() / mt_getrandmax() < FEEDBACK_RATE) &&
!received_email_today($obj->{'studentID'})) {
send_email($obj, $interaction_id);
} else {
echo json_encode([
Expand Down
83 changes: 55 additions & 28 deletions public/sqlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,32 +157,35 @@ function add_cse($username) {
return null;
}

function add_interaction($la_cse, $student_cse, $course, $interaction_type) {
function add_interaction($la_cse, $student_id, $course, $interaction_type) {
$la_id = get_username_id($la_cse);
$student_id = get_username_id($student_cse);
if ($la_id === $student_id) return null;
$conn = get_connection();
if ($conn !== null && is_int($la_id) && is_int($student_id)) {
$conn->begin_transaction();
$ps = $conn->prepare("INSERT INTO interactions (la_username_key, student_username_key, course, " .
"interaction_type) VALUE ((SELECT username_key FROM cse_usernames WHERE username=?), " .
"(SELECT username_key FROM cse_usernames WHERE username=?), ?, ?);");
"interaction_type) VALUE (?, ?, ?, ?);");
if ($ps) {
$ps->bind_param("ssss", $la_cse, $student_cse, $course, $interaction_type);
$ps->bind_param("siss", $la_id, $student_id, $course, $interaction_type);
$ps->execute();
$conn->commit();
$returnVal = $ps->insert_id;
if ($ps->error) {
error_log($ps->error);
} else {
$conn->commit();
$returnVal = $ps->insert_id;

$ps->close();
$conn->close();
$ps->close();
$conn->close();

return $returnVal;
return $returnVal;
}
} else {
$conn->close();
error_log("Failed to build prepped statement to add interaction between $la_cse and $student_cse");
error_log("Failed to build prepped statement to add interaction between $la_cse and $student_id");
}
} else {
error_log('Failed to add interaction for { la: ' . $la_cse . ', student: ' . $student_cse . ' }');
error_log('Failed to add interaction for { la: ' . $la_cse . ', student: ' . $student_id . ' }');
}
$conn->close();
return null;
}

Expand Down Expand Up @@ -233,14 +236,14 @@ function has_been_a_week($username) {
return false;
}

function received_email_today($student_cse) {
function received_email_today($student_id) {
$conn = get_connection();
if ($conn !== null && $student_cse !== null) {
if ($conn !== null && $student_id !== null) {
$ps = $conn->prepare("SELECT time_of_interaction AS time FROM interactions WHERE seeking_feedback = 1 " .
"AND student_username_key = (SELECT username_key FROM cse_usernames WHERE username=?) " .
"AND student_username_key = ? " .
"ORDER BY time_of_interaction DESC LIMIT 1;");
if ($ps) {
$ps->bind_param("s", $student_cse);
$ps->bind_param("s", $student_id);
$ps->execute();

$result = $ps->get_result()->fetch_assoc()['time'];
Expand All @@ -259,7 +262,7 @@ function received_email_today($student_cse) {
return false;
}
} else {
error_log("Failed to build prepped statement for checking if $student_cse received an email");
error_log("Failed to build prepped statement for checking if $student_id received an email");
$ps->close();
$conn->close();
return false;
Expand All @@ -280,19 +283,17 @@ function get_username_id($username) {
return null;
}

$id = -1;
$ps->bind_param("s", $username);
$ps->execute();
if ($ps->num_rows() > 0) {
$ps->bind_result($id);
$ps->fetch();
$ps->close();
$conn->close();
return $id;
} else {
$ps->close();
$conn->close();
return add_cse($username);
$ps->bind_result($id);
$ps->fetch();
if ($ps->num_rows() == -1) {
$id = add_cse($username);
}
$ps->close();
$conn->close();
return $id;
}
return null;
}
Expand All @@ -314,3 +315,29 @@ function get_course_counts() {
return [];
}
}

function get_email($student_id) {
if ($student_id === null) return null;

$conn = get_connection();
$result = null;
if ($conn !== null) {
$ps = $conn->prepare("SELECT IFNULL(email, CONCAT(username, '@cse.unl.edu')) AS 'email' " .
"FROM cse_usernames WHERE username_key=?;");
if ($ps) {
$ps->bind_param("i", $student_id);
$ps->execute();
$assoc = $ps->get_result()->fetch_assoc();
if ($assoc) {
$result = $assoc['email'];
} else if ($ps->error) {
error_log($ps->error);
}
$ps->close();
} else {
error_log("Failed to build prepped statement for getting email for $student_id");
}
}
$conn->close();
return $result;
}
Loading

0 comments on commit 83c007a

Please sign in to comment.