| Conditions | 1 |
| Paths | 1 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function show($id, ExchangeRegistry $exchangeLogger) |
||
| 20 | { |
||
| 21 | $data = DB::transaction(function () use ($id, $exchangeLogger) { |
||
| 22 | $data = []; |
||
| 23 | $student = Student::findOrFail($id); |
||
| 24 | $data['student'] = $student; |
||
| 25 | $data['enrollments'] = $student |
||
| 26 | ->enrollments() |
||
| 27 | ->orderByCourse() |
||
| 28 | ->withCount('exchangesAsSource') |
||
| 29 | ->get(); |
||
| 30 | $data['requestedExchanges'] = $student->requestedExchanges()->get(); |
||
| 31 | $data['proposedExchanges'] = $student->proposedExchanges()->get(); |
||
| 32 | $data['historyExchanges'] = $exchangeLogger->historyOfStudent($student); |
||
| 33 | |||
| 34 | return $data; |
||
| 35 | }); |
||
| 36 | |||
| 37 | // Group all enrollments by the year of their associated course, so |
||
| 38 | // the enrollments listing is organized by year. This will allow |
||
| 39 | // a better experience, since it matches the official order. |
||
| 40 | $data['enrollments'] = $data['enrollments']->groupBy(function ($enrollment) { |
||
| 41 | return $enrollment->course->present()->getOrdinalYear(); |
||
| 42 | }); |
||
| 43 | |||
| 44 | return view('students.show', $data); |
||
| 45 | } |
||
| 47 |