WebPresenter.php 1.33 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

namespace Source\UseCases\Entries;

use Source\Entities\Entry;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;

class WebPresenter extends BasePresenter implements Presenter
{
    use Paginates;

    protected array $entries = [];

    /** @inheritDoc */
    public function present(ResponseModel $responseModel): void
    {
        $this->entries = array_map(static function (Entry $entry): array {
            return  [
                'id' => $entry->getId(),
                'user_id' => $entry->getUserId(),
22
                'door_id' => $entry->getDoorId(),
Jacob Priddy's avatar
Jacob Priddy committed
23
                'success' => $entry->wasSuccessful() ? 'Allowed' : 'Denied',
Jacob Priddy's avatar
Jacob Priddy committed
24
                'reason' => $entry->getReason(),
25
                'created_at' => self::formatDateTime($entry->getCreatedAt(), self::HUMAN_DATE_FORMAT) ?? 'Unknown',
Jacob Priddy's avatar
Jacob Priddy committed
26
27
28
29
30
31
32
33
34
35
36
37
            ];
        }, $responseModel->getEntries());
    }

    /** @inheritDoc */
    public function getViewModel(array $appends = []): array
    {
        return [
            'entries' => $this->webPaginate($this->entries, $appends),
            'headers' => [
                'ID' => 'id',
                'User' => 'user_id',
38
                'Door' => 'door_id',
Jacob Priddy's avatar
Jacob Priddy committed
39
                'Status' => 'success',
Jacob Priddy's avatar
Jacob Priddy committed
40
                'Reason' => 'reason',
Jacob Priddy's avatar
Jacob Priddy committed
41
42
43
44
45
                'Entry Time' => 'created_at',
            ],
        ];
    }
}