Skip to content

Commit 572cf34

Browse files
committed
Style fixes and linting
1 parent 79f1474 commit 572cf34

File tree

12 files changed

+776
-688
lines changed

12 files changed

+776
-688
lines changed

api/entity.php

Lines changed: 145 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
// REQUIRED FILES //////////////////////////////////////////////////////////
1313
if (file_exists('../inc/config.php')) {
14-
require_once "../inc/config.php";
14+
include_once "../inc/config.php";
1515
} else {
16-
require_once "../inc/config.env.php";
16+
include_once "../inc/config.env.php";
1717
}
1818
require_once "../inc/databaseConn.php";
1919
require_once "../inc/timeFunctions.php";
@@ -28,19 +28,19 @@
2828
// MAIN EXECUTION //////////////////////////////////////////////////////////
2929

3030
// Switch on the action
31-
switch(getAction()) {
32-
case "getCourses":
33-
// Query for the courses in this department
34-
35-
// Verify that we have department to get courses for and a quarter
36-
if(empty($_POST['department']) || !is_numeric($_POST['department'])) {
37-
die(json_encode(array("error" => "argument", "msg" => "You must provide a valid department")));
38-
} elseif(empty($_POST['term']) || !is_numeric($_POST['term'])) {
39-
die(json_encode(array("error" => "argument", "msg" => "You must provide a valid term")));
40-
}
41-
42-
// Do the query
43-
$query = "SELECT c.title, c.course, c.description, c.id, d.number, d.code
31+
switch (getAction()) {
32+
case "getCourses":
33+
// Query for the courses in this department
34+
35+
// Verify that we have department to get courses for and a quarter
36+
if (empty($_POST['department']) || !is_numeric($_POST['department'])) {
37+
die(json_encode(["error" => "argument", "msg" => "You must provide a valid department"]));
38+
} elseif (empty($_POST['term']) || !is_numeric($_POST['term'])) {
39+
die(json_encode(["error" => "argument", "msg" => "You must provide a valid term"]));
40+
}
41+
42+
// Do the query
43+
$query = "SELECT c.title, c.course, c.description, c.id, d.number, d.code
4444
FROM sections AS s
4545
JOIN courses AS c ON s.course = c.id
4646
JOIN departments AS d ON d.id = c.department
@@ -49,43 +49,43 @@
4949
AND s.status != 'X'
5050
GROUP BY c.id
5151
ORDER BY course";
52-
$result = $dbConn->query($query);
53-
if(!$result) {
54-
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
55-
}
56-
57-
// Collect the courses and turn it into a json
58-
$courses = array();
59-
while($course = $result->fetch_assoc()) {
60-
$courses[] = array(
52+
$result = $dbConn->query($query);
53+
if (!$result) {
54+
die(json_encode(["error" => "mysql", "msg" => $dbConn->error]));
55+
}
56+
57+
// Collect the courses and turn it into a json
58+
$courses = [];
59+
while ($course = $result->fetch_assoc()) {
60+
$courses[] = [
6161
"id" => $course['id'],
6262
"course" => $course['course'],
63-
"department" => array("code" => $course['code'], "number" =>$course['number']),
63+
"department" => ["code" => $course['code'], "number" => $course['number']],
6464
"title" => $course['title'],
6565
"description" => htmlentities($course['description'])
66-
);
67-
}
66+
];
67+
}
6868

69-
echo json_encode(array("courses" => $courses));
69+
echo json_encode(["courses" => $courses]);
70+
71+
break;
7072

71-
break;
73+
case "getDepartments":
74+
// Query for the departments of the school
7275

73-
case "getDepartments":
74-
// Query for the departments of the school
75-
76-
// Verify that we have a school to get departments for
77-
if(empty($_POST['school']) || !is_numeric($_POST['school'])) {
78-
die(json_encode(array("error" => "argument", "msg" => "You must provide a school")));
79-
}
76+
// Verify that we have a school to get departments for
77+
if (empty($_POST['school']) || !is_numeric($_POST['school'])) {
78+
die(json_encode(["error" => "argument", "msg" => "You must provide a school"]));
79+
}
8080

81-
// Verify that we have a quarter to make sure there are
82-
// courses in the department.
83-
if(empty($_POST['term']) || !is_numeric($_POST['term'])) {
84-
die(json_encode(array("error" => "argument", "msg" => "You must provide a term")));
85-
}
81+
// Verify that we have a quarter to make sure there are
82+
// courses in the department.
83+
if (empty($_POST['term']) || !is_numeric($_POST['term'])) {
84+
die(json_encode(["error" => "argument", "msg" => "You must provide a term"]));
85+
}
8686

87-
// Do the query
88-
if($_POST['term'] > 20130) {
87+
// Do the query
88+
if ($_POST['term'] > 20130) {
8989
// Get the department code and concat the numbers
9090
$query = "SELECT id, title, code, GROUP_CONCAT(number, ', ') AS number
9191
FROM departments AS d
@@ -102,169 +102,169 @@
102102
AND number IS NOT NULL
103103
ORDER BY id";
104104
}
105-
$result = $dbConn->query($query);
106-
if(!$result) {
107-
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
108-
}
109-
110-
// Collect the departments and turn it into a json
111-
$departments = array();
112-
while($department = $result->fetch_assoc()) {
113-
$departments[] = array(
105+
$result = $dbConn->query($query);
106+
if (!$result) {
107+
die(json_encode(["error" => "mysql", "msg" => $dbConn->error]));
108+
}
109+
110+
// Collect the departments and turn it into a json
111+
$departments = [];
112+
while ($department = $result->fetch_assoc()) {
113+
$departments[] = [
114114
"id" => $department['id'],
115115
"title" => $department['title'],
116-
"code" => isset($department['code']) ? $department['code'] : NULL,
116+
"code" => isset($department['code']) ? $department['code'] : null,
117117
"number" => trim($department['number'], " ,")
118-
);
119-
}
118+
];
119+
}
120120

121-
echo json_encode(array("departments" => $departments));
121+
echo json_encode(["departments" => $departments]);
122122

123-
break;
123+
break;
124124

125125
case "getSchools":
126126
// REQUEST FOR LIST OF SCHOOLS /////////////////////////////////////
127127
// Query for the schools
128128
$query = "SELECT `id`, `number`, `code`, `title` FROM schools";
129129
$result = $dbConn->query($query);
130-
if(!$result) {
131-
die(json_encode(array("error" => "database", "msg" => "The list of schools could not be retrieved at this time.")));
130+
if (!$result) {
131+
die(json_encode(["error" => "database", "msg" => "The list of schools could not be retrieved at this time."]));
132132
}
133133

134134
// Build an array of schools
135-
$schools = array();
136-
while($school = $result->fetch_assoc()) {
135+
$schools = [];
136+
while ($school = $result->fetch_assoc()) {
137137
$schools[] = $school;
138138
}
139139

140140
// Return it to the user
141141
echo(json_encode($schools));
142142
break;
143-
143+
144144
case "getSchoolsForTerm":
145145
// REQUEST FOR LIST OF SCHOOLS FOR TERM ////////////////////////////
146-
if(empty($_POST['term'])) {
147-
die(json_encode(array("error" => "argument", "msg" => "You must provide a term")));
148-
}
149-
150-
$term = (int) $_POST['term'];
151-
152-
// Determine if term was before quarters
153-
if ($term > 20130) {
154-
// School codes
155-
$query = "SELECT id, code AS code, title FROM schools WHERE code IS NOT NULL ORDER BY code";
156-
} else {
157-
// School numbers
158-
$query = "SELECT id, number AS code, title FROM schools WHERE number IS NOT NULL ORDER BY number";
159-
}
160-
// Query for the schools
146+
if (empty($_POST['term'])) {
147+
die(json_encode(["error" => "argument", "msg" => "You must provide a term"]));
148+
}
149+
150+
$term = (int)$_POST['term'];
151+
152+
// Determine if term was before quarters
153+
if ($term > 20130) {
154+
// School codes
155+
$query = "SELECT id, code AS code, title FROM schools WHERE code IS NOT NULL ORDER BY code";
156+
} else {
157+
// School numbers
158+
$query = "SELECT id, number AS code, title FROM schools WHERE number IS NOT NULL ORDER BY number";
159+
}
160+
// Query for the schools
161161
$result = $dbConn->query($query);
162-
if(!$result) {
163-
die(json_encode(array("error" => "database", "msg" => "The list of schools could not be retrieved at this time.")));
162+
if (!$result) {
163+
die(json_encode(["error" => "database", "msg" => "The list of schools could not be retrieved at this time."]));
164164
}
165-
165+
166166
// Build an array of schools
167-
$schools = array();
168-
while($school = $result->fetch_assoc()) {
169-
$schools[] = $school;
167+
$schools = [];
168+
while ($school = $result->fetch_assoc()) {
169+
$schools[] = $school;
170170
}
171-
171+
172172
// Return it to the user
173173
echo(json_encode($schools));
174174
break;
175175

176-
case "getSections":
177-
// Query for the sections and times of a given course
178-
179-
// Verify that we have a course to get sections for
180-
if(empty($_POST['course']) || !is_numeric($_POST['course'])) {
181-
die(json_encode(array("error" => "argument", "msg" => "You must provide a course")));
182-
}
176+
case "getSections":
177+
// Query for the sections and times of a given course
183178

184-
// Do the query
185-
$query = "SELECT c.title AS coursetitle, c.course, d.number, d.code, s.section,
179+
// Verify that we have a course to get sections for
180+
if (empty($_POST['course']) || !is_numeric($_POST['course'])) {
181+
die(json_encode(["error" => "argument", "msg" => "You must provide a course"]));
182+
}
183+
184+
// Do the query
185+
$query = "SELECT c.title AS coursetitle, c.course, d.number, d.code, s.section,
186186
s.instructor, s.id, s.type, s.maxenroll, s.curenroll, s.title AS sectiontitle
187187
FROM sections AS s
188188
JOIN courses AS c ON s.course = c.id
189189
JOIN departments AS d ON d.id = c.department
190190
WHERE s.course = '{$_POST['course']}'
191191
AND s.status != 'X'
192192
ORDER BY c.course, s.section";
193-
$sectionResult = $dbConn->query($query);
194-
if(!$sectionResult) {
195-
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
196-
}
197-
198-
// Collect the sections and their times, modify the section inline
199-
$sections = array();
200-
while($section = $sectionResult->fetch_assoc()) {
201-
$section['times'] = array();
202-
203-
// Set the course title depending on its section title
193+
$sectionResult = $dbConn->query($query);
194+
if (!$sectionResult) {
195+
die(json_encode(["error" => "mysql", "msg" => $dbConn->error]));
196+
}
197+
198+
// Collect the sections and their times, modify the section inline
199+
$sections = [];
200+
while ($section = $sectionResult->fetch_assoc()) {
201+
$section['times'] = [];
202+
203+
// Set the course title depending on its section title
204204
// @TODO: Replace this with a conditional column in the query
205-
if($section['sectiontitle'] != NULL) {
206-
$section['title'] = $section['sectiontitle'];
207-
} else {
208-
$section['title'] = $section['coursetitle'];
209-
}
210-
unset($section['sectiontitle']);
211-
unset($section['coursetitle']);
212-
213-
// If it's online, don't bother looking up the times
214-
if($section['type'] == "OL") {
215-
$section['online'] = true;
216-
} else {
205+
if ($section['sectiontitle'] != null) {
206+
$section['title'] = $section['sectiontitle'];
207+
} else {
208+
$section['title'] = $section['coursetitle'];
209+
}
210+
unset($section['sectiontitle']);
211+
unset($section['coursetitle']);
212+
213+
// If it's online, don't bother looking up the times
214+
if ($section['type'] == "OL") {
215+
$section['online'] = true;
216+
} else {
217217
// Look up the times the section meets
218218
$query = "SELECT day, start, end, b.code, b.number, b.off_campus AS off, room
219219
FROM times AS t
220220
JOIN buildings AS b ON b.number=t.building
221221
WHERE t.section = '{$section['id']}'
222222
ORDER BY day, start";
223223
$timeResult = $dbConn->query($query);
224-
if(!$timeResult) {
225-
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
224+
if (!$timeResult) {
225+
die(json_encode(["error" => "mysql", "msg" => $dbConn->error]));
226226
}
227227

228-
while($time = $timeResult->fetch_assoc()) {
229-
$timeOutput = array(
230-
'start' => $time['start'],
231-
'end' => $time['end'],
232-
'day' => $time['day'],
233-
'bldg' => array(
234-
'code' => $time['code'],
235-
'number' => $time['number'],
228+
while ($time = $timeResult->fetch_assoc()) {
229+
$timeOutput = [
230+
'start' => $time['start'],
231+
'end' => $time['end'],
232+
'day' => $time['day'],
233+
'bldg' => [
234+
'code' => $time['code'],
235+
'number' => $time['number'],
236236
'off_campus' => $time['off'] == '1'
237-
),
238-
'room' => $time['room']
239-
);
237+
],
238+
'room' => $time['room']
239+
];
240240
$section['times'][] = $timeOutput;
241241
}
242242
}
243243

244244
// Add the section to the result set
245-
$sections[] = array(
246-
"id" => $section['id'],
247-
"department" => array("code" => $section['code'], "number" => $section['number']),
248-
"course" => $section['course'],
249-
"section" => $section['section'],
250-
"title" => $section['title'],
245+
$sections[] = [
246+
"id" => $section['id'],
247+
"department" => ["code" => $section['code'], "number" => $section['number']],
248+
"course" => $section['course'],
249+
"section" => $section['section'],
250+
"title" => $section['title'],
251251
"instructor" => $section['instructor'],
252-
"type" => $section['type'],
253-
"maxenroll" => $section['maxenroll'],
254-
"curenroll" => $section['curenroll'],
255-
"times" => $section['times']
256-
);
257-
}
252+
"type" => $section['type'],
253+
"maxenroll" => $section['maxenroll'],
254+
"curenroll" => $section['curenroll'],
255+
"times" => $section['times']
256+
];
257+
}
258258

259-
// Spit out the json
260-
echo json_encode(array("sections" => $sections));
261-
break;
259+
// Spit out the json
260+
echo json_encode(["sections" => $sections]);
261+
break;
262262

263263
case "courseForSection":
264264
echo json_encode(getCourseBySectionId($_POST['id'], true));
265265
break;
266266

267267
default:
268-
die(json_encode(array("error" => "argument", "msg" => "You must provide a valid action.")));
268+
die(json_encode(["error" => "argument", "msg" => "You must provide a valid action."]));
269269

270270
}

0 commit comments

Comments
 (0)