Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LogsController
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Controllers\Admin;
6
7use Engelsystem\Controllers\BaseController;
8use Engelsystem\Helpers\Authenticator;
9use Engelsystem\Http\Request;
10use Engelsystem\Http\Response;
11use Engelsystem\Models\LogEntry;
12use Engelsystem\Models\User\User;
13use Illuminate\Support\Collection;
14
15class LogsController extends BaseController
16{
17    /** @var array<string> */
18    protected array $permissions = [
19        'admin_log',
20    ];
21
22    public function __construct(protected LogEntry $log, protected Response $response, protected Authenticator $auth)
23    {
24    }
25
26    public function index(Request $request): Response
27    {
28        $searchUserId = (int) $request->input('search_user_id') ?: null;
29        $search = $request->input('search');
30        $userId = $this->auth->user()?->id;
31
32        if ($this->auth->can('logs.all')) {
33            $userId = $searchUserId;
34        }
35
36        $entries = $this->log->filter($search, $userId);
37
38        /** @var Collection $users */
39        $users = User::with('personalData')
40            ->orderBy('name')
41            ->get()
42            ->mapWithKeys(function (User $u) {
43                return [$u->id => $u->displayName];
44            });
45
46        return $this->response->withView(
47            'admin/log.twig',
48            ['entries' => $entries, 'search' => $search, 'users' => $users, 'search_user_id' => $searchUserId]
49        );
50    }
51}