Skip to content

Commit

Permalink
Improved e-mail layout
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtuallyBookish committed Aug 20, 2017
1 parent e717147 commit 4947e84
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 108 deletions.
40 changes: 34 additions & 6 deletions app/Http/Controllers/SubjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,23 @@ public function destroy(Subject $subject)
/**
* Find the levels for a given subject encoded in Json
*
* @param int $subjectId
* @param string $name optional, if given, find by subject name instead of ID
*/
public function getSubjectLevelsAsJson($subjectId = 1)
public function getSubjectLevelsAsJson($subjectName = null)
{
$subject = Subject::find($subjectId);
$subjectName = urldecode($subjectName);
$subject = Subject::where('name', $subjectName)->get()->first();
$levels = $subject->getAttributes();
unset($levels['id'], $levels['created_at'], $levels['updated_at'], $levels['name']);
return response()->json($levels);
}


$parsedSubjects = array();
foreach($levels as $level => $available) {
if ($available) {
$parsedSubjects[] = $this->parseSubject($level);
}
}
return response()->json($parsedSubjects);
}

/**
* Find the levels for a given subject encoded in Json
Expand All @@ -108,4 +114,26 @@ public function getSubjectsJson()
$subjects = Subject::all();
return response()->json($subjects);
}

private function parseSubject($subject)
{
switch ($subject) {
case "primary":
return "Primary";
case "secondary":
return "Secondary";
case "gcse":
return "GCSE";
case "alevel":
return "A-Level";
case "university_bachelors":
return "University - Bachelor's";
case "university_masters":
return "University - Master's";
case "adult_casual":
return "Adult/Casual Learner";
default:
break;
}
}
}
Loading

0 comments on commit 4947e84

Please sign in to comment.