| Code Coverage
| Lines | Functions and Methods | Classes and Traits
Total | 18.75% covered (danger) | 18.75% | 6 / 32 | 0.00% covered (danger) | 0.00% | 0 / 6 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 1
CoachesController | 18.75% covered (danger) | 18.75% | 6 / 32 | 0.00% covered (danger) | 0.00% | 0 / 6 | 75.90 | 0.00% covered (danger) | 0.00% | 0 / 1
index | 0.00% covered (danger) | 0.00% | 0 / 2 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
new | 0.00% covered (danger) | 0.00% | 0 / 2 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
create | 30.00% covered (danger) | 30.00% | 3 / 10 | 0.00% covered (danger) | 0.00% | 0 / 1 | 3.37 |
show | 75.00% covered (warning) | 75.00% | 3 / 4 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.06 |
edit | 0.00% covered (danger) | 0.00% | 0 / 4 | 0.00% covered (danger) | 0.00% | 0 / 1 | 12 |
update | 0.00% covered (danger) | 0.00% | 0 / 10 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |

1 | <?php
2 |
3 | namespace App\Controllers;
4 |
5 | class CoachesController extends BaseController
6 | {
7 | public function index(): string
8 | {
9 | $data = service('coaches')->getIndexData($this->request->getGet(), auth()->user());
10 |
11 | return view('coaches/index', $data);
12 | }
13 |
14 | public function new(): string
15 | {
16 | $data = service('coaches')->getFormData(auth()->user());
17 |
18 | return view('coaches/form', $data);
19 | }
20 |
21 | public function create()
22 | {
23 | $result = service('coaches')->save($this->request->getPost(), auth()->user());
24 |
25 | if (! $result['success']) {
26 | $data = service('coaches')->getFormData(
27 | auth()->user(),
28 | null,
29 | $this->request->getPost(),
30 | $result['errors'] ?? [],
31 | );
32 |
33 | return view('coaches/form', $data);
34 | }
35 |
36 | return redirect()->to(url_to('coaches.show', $result['coach_id']))->with('message', 'Antrenorul a fost creat cu succes.');
37 | }
38 |
39 | public function show(int $coachId)
40 | {
41 | $data = service('coaches')->getProfileData($coachId, auth()->user());
42 |
43 | if ($data === null) {
44 | return $this->forbidden('Nu ai acces la acest profil de antrenor.');
45 | }
46 |
47 | return view('coaches/show', $data);
48 | }
49 |
50 | public function edit(int $coachId)
51 | {
52 | $data = service('coaches')->getFormData(auth()->user(), $coachId);
53 |
54 | if ($data === null || $data['coach'] === null) {
55 | return $this->forbidden('Profilul antrenorului nu a fost gasit.');
56 | }
57 |
58 | return view('coaches/form', $data);
59 | }
60 |
61 | public function update(int $coachId)
62 | {
63 | $result = service('coaches')->save($this->request->getPost(), auth()->user(), $coachId);
64 |
65 | if (! $result['success']) {
66 | $data = service('coaches')->getFormData(
67 | auth()->user(),
68 | $coachId,
69 | $this->request->getPost(),
70 | $result['errors'] ?? [],
71 | );
72 |
73 | return view('coaches/form', $data);
74 | }
75 |
76 | return redirect()->to(url_to('coaches.show', $coachId))->with('message', 'Profilul antrenorului a fost actualizat.');
77 | }
78 | }