| Code Coverage
| Lines | Functions and Methods | Classes and Traits
Total | 40.00% covered (danger) | 40.00% | 10 / 25 | 20.00% covered (danger) | 20.00% | 1 / 5 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 1
AttendanceController | 40.00% covered (danger) | 40.00% | 10 / 25 | 20.00% covered (danger) | 20.00% | 1 / 5 | 31.60 | 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 | 27.27% covered (danger) | 27.27% | 3 / 11 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.46 |
show | 100.00% covered (success) | 100.00% | 4 / 4 | 100.00% covered (success) | 100.00% | 1 / 1 | 2 |
saveCheckIn | 50.00% covered (danger) | 50.00% | 3 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 4.12 |

1 | <?php
2 |
3 | namespace App\Controllers;
4 |
5 | class AttendanceController extends BaseController
6 | {
7 | public function index(): string
8 | {
9 | $data = service('attendance')->getIndexData($this->request->getGet(), auth()->user());
10 |
11 | return view('attendance/index', $data);
12 | }
13 |
14 | public function new(): string
15 | {
16 | $data = service('attendance')->getFormData(auth()->user());
17 |
18 | return view('attendance/form', $data);
19 | }
20 |
21 | public function create()
22 | {
23 | $result = service('attendance')->saveSession($this->request->getPost(), auth()->user());
24 |
25 | if (! $result['success']) {
26 | if (! empty($result['forbidden'])) {
27 | return $this->forbidden('Nu poti crea sesiuni pentru aceasta grupa.');
28 | }
29 |
30 | $data = service('attendance')->getFormData(
31 | auth()->user(),
32 | $this->request->getPost(),
33 | $result['errors'] ?? [],
34 | );
35 |
36 | return view('attendance/form', $data);
37 | }
38 |
39 | return redirect()->to(url_to('attendance.show', $result['session_id']))->with('message', 'Sesiunea a fost creata.');
40 | }
41 |
42 | public function show(int $sessionId)
43 | {
44 | $data = service('attendance')->getSessionData($sessionId, auth()->user());
45 |
46 | if ($data === null) {
47 | return $this->forbidden('Nu ai acces la aceasta sesiune.');
48 | }
49 |
50 | return view('attendance/show', $data);
51 | }
52 |
53 | public function saveCheckIn(int $sessionId)
54 | {
55 | $result = service('attendance')->saveCheckIn($sessionId, $this->request->getPost(), auth()->user());
56 |
57 | if (! $result['success']) {
58 | if (! empty($result['forbidden'])) {
59 | return $this->forbidden('Nu ai acces la aceasta sesiune.');
60 | }
61 |
62 | return redirect()->to(url_to('attendance.show', $sessionId))->with('error', $result['errors']['general'] ?? 'Check-in-ul nu a putut fi salvat.');
63 | }
64 |
65 | return redirect()->to(url_to('attendance.show', $sessionId))->with('message', 'Check-in-ul a fost salvat.');
66 | }
67 | }