/** * Store a newly created resource in storage. * * @return \Illuminate\Http\Response */ public function store() { if (!Input::get('name') or !Input::get('program_id')) { return $this->respondUnprocessableEntity('Parameters failed validation for a program level.'); } try { $program = Program::findOrFail(Input::get('program_id')); } catch (ModelNotFoundException $e) { return $this->respondNotFound('Program provided does not exist'); } ProgramLevel::create(Input::all()); return $this->respondCreated('Program level successfully created.'); }
/** * Store a newly created resource in storage. * * @return \Illuminate\Http\Response */ public function store() { if (!Input::get('attendee_id') or !Input::get('program_id')) { return $this->respondUnprocessableEntity('Parameters failed validation for an enrollment.'); } try { $attendee = Attendee::findOrFail(Input::get('attendee_id')); } catch (ModelNotFoundException $e) { return $this->respondUnprocessableEntity('Attendee provided does not exist.'); } try { $program = Program::findOrFail(Input::get('program_id')); } catch (ModelNotFoundException $e) { return $this->respondUnprocessableEntity('Program provided does not exist.'); } $existingEnrollment = Enrollment::where('attendee_id', $attendee->id)->where('program_id', $program->id)->whereNull('enrollments.deleted_at')->get(); if (count($existingEnrollment)) { return $this->respondUnprocessableEntity('The enrollment of the attendee to the program already exists.'); } //We pass validation. Now add the enrollment. Enrollment::create(Input::all()); return $this->respondCreated('Enrollment created successfully.'); }
public function getProgramRank($id) { $program = Program::findOrFail($id); $programPoints = $program->points; $programTeams = $program->teams; if ($programPoints->count()) { $teamPoints = []; foreach ($programTeams as $key => $team) { $pointSum = 0; foreach ($programPoints as $key => $points) { if ($team['id'] == $points['team_id']) { $pointSum += $points['amount']; } } $teamPoints[] = ['id' => $team['id'], 'name' => $team['name'], 'points' => $pointSum]; } usort($teamPoints, function ($a, $b) { if ($a['points'] == $b['points']) { return 0; } return $a['points'] < $b['points'] ? 1 : -1; }); return $teamPoints; } else { return 0; } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $program = Program::findOrFail($id); if ($program->delete()) { return Redirect::route('programs.index')->with('message', 'Program Deleted Successfully'); } else { return Redirect::route('programs.index')->with('message', 'Fail to Delete Program'); } }