Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
30.30% |
10 / 33 |
|
33.33% |
2 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ChildrenController | |
30.30% |
10 / 33 |
|
33.33% |
2 / 6 |
43.86 | |
0.00% |
0 / 1 |
| index | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| new | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
30.00% |
3 / 10 |
|
0.00% |
0 / 1 |
3.37 | |||
| show | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| edit | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| update | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Controllers; |
| 4 | |
| 5 | class ChildrenController extends BaseController |
| 6 | { |
| 7 | public function index(): string |
| 8 | { |
| 9 | $data = service('children')->getIndexData($this->request->getGet(), auth()->user()); |
| 10 | |
| 11 | return view('children/index', $data); |
| 12 | } |
| 13 | |
| 14 | public function new(): string |
| 15 | { |
| 16 | $data = service('children')->getFormData(auth()->user()); |
| 17 | |
| 18 | return view('children/form', $data); |
| 19 | } |
| 20 | |
| 21 | public function create() |
| 22 | { |
| 23 | $result = service('children')->save($this->request->getPost(), auth()->user()); |
| 24 | |
| 25 | if (! $result['success']) { |
| 26 | $data = service('children')->getFormData( |
| 27 | auth()->user(), |
| 28 | null, |
| 29 | $this->request->getPost(), |
| 30 | $result['errors'] ?? [], |
| 31 | ); |
| 32 | |
| 33 | return view('children/form', $data); |
| 34 | } |
| 35 | |
| 36 | return redirect()->to(url_to('children.show', $result['child_id']))->with('message', 'Copilul a fost adaugat cu succes.'); |
| 37 | } |
| 38 | |
| 39 | public function show(int $childId) |
| 40 | { |
| 41 | $tab = (string) ($this->request->getGet('tab') ?? 'overview'); |
| 42 | $data = service('children')->getProfileData($childId, auth()->user(), $tab); |
| 43 | |
| 44 | if ($data === null) { |
| 45 | return $this->forbidden('Nu ai acces la acest profil de copil.'); |
| 46 | } |
| 47 | |
| 48 | return view('children/show', $data); |
| 49 | } |
| 50 | |
| 51 | public function edit(int $childId) |
| 52 | { |
| 53 | $data = service('children')->getFormData(auth()->user(), $childId); |
| 54 | |
| 55 | if ($data['child'] === null) { |
| 56 | return $this->forbidden('Profilul copilului nu a fost gasit.'); |
| 57 | } |
| 58 | |
| 59 | return view('children/form', $data); |
| 60 | } |
| 61 | |
| 62 | public function update(int $childId) |
| 63 | { |
| 64 | $result = service('children')->save($this->request->getPost(), auth()->user(), $childId); |
| 65 | |
| 66 | if (! $result['success']) { |
| 67 | $data = service('children')->getFormData( |
| 68 | auth()->user(), |
| 69 | $childId, |
| 70 | $this->request->getPost(), |
| 71 | $result['errors'] ?? [], |
| 72 | ); |
| 73 | |
| 74 | return view('children/form', $data); |
| 75 | } |
| 76 | |
| 77 | return redirect()->to(url_to('children.show', $childId))->with('message', 'Profilul copilului a fost actualizat.'); |
| 78 | } |
| 79 | } |