Entry.php 2.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php


namespace Source\Entities;

use Carbon\Carbon;

class Entry
{
    /**
     * @var int
     */
    protected int $id;

    /**
     * @var int
     */
    protected int $userId;

    /**
21
     * @var int
22
     */
23
    protected int $doorId;
24
25
26
27
28
29
30
31
32
33
34

    /**
     * @var \Carbon\Carbon|null
     */
    protected ?Carbon $createdAt;

    /**
     * @var \Carbon\Carbon|null
     */
    protected ?Carbon $updatedAt;

35
36
37
38
39
    /**
     * @var bool
     */
    protected bool $success;

Jacob Priddy's avatar
Jacob Priddy committed
40
41
42
43
44
    /**
     * @var string
     */
    protected string $reason;

45
46
47
    public function __construct(
        int $id,
        int $userId,
48
        int $doorId,
49
        bool $success,
Jacob Priddy's avatar
Jacob Priddy committed
50
        string $reason,
51
52
53
54
55
        ?Carbon $createdAt = null,
        ?Carbon $updatedAt = null
    ) {
        $this->id = $id;
        $this->userId = $userId;
56
        $this->doorId = $doorId;
Jacob Priddy's avatar
Jacob Priddy committed
57
        $this->reason = $reason;
58
        $this->success = $success;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        $this->createdAt = $createdAt;
        $this->updatedAt = $updatedAt;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return int
     */
    public function getUserId(): int
    {
        return $this->userId;
    }

    /**
80
     * @return int
81
     */
82
    public function getDoorId(): int
83
    {
84
        return $this->doorId;
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    }

    /**
     * @return \Carbon\Carbon|null
     */
    public function getCreatedAt(): ?Carbon
    {
        return $this->createdAt;
    }

    /**
     * @return \Carbon\Carbon|null
     */
    public function getUpdatedAt(): ?Carbon
    {
        return $this->updatedAt;
    }

103
104
105
106
107
108
109
110
    /**
     * @return bool
     */
    public function wasSuccessful(): bool
    {
        return $this->success;
    }

111
    /**
Jacob Priddy's avatar
Jacob Priddy committed
112
113
     * @param \Carbon\Carbon|null $begin
     * @param \Carbon\Carbon|null $end
114
115
     * @return bool
     */
Jacob Priddy's avatar
Jacob Priddy committed
116
    public function isBetween(?Carbon $begin, ?Carbon $end): bool
117
    {
118
119
120
121
        if (!$this->createdAt) {
            return true;
        }

Jacob Priddy's avatar
Jacob Priddy committed
122
123
124
125
126
127
128
129
130
131
132
133
134
        if ($begin && $end) {
            return $this->createdAt->isBetween($begin, $end);
        }

        if ($begin) {
            return $this->createdAt->greaterThan($begin);
        }

        if ($end) {
            return $this->createdAt->lessThan($end);
        }

        return true;
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    }

    /**
     * @param string|null $userId
     * @return bool
     */
    public function hasUserIdOf(?string $userId): bool
    {
        if (!$userId) {
            return false;
        }

        return $this->getUserId() === (int)$userId;
    }

    /**
151
     * @param string|null $doorId
152
153
     * @return bool
     */
154
    public function hasDoorIdOf(?string $doorId): bool
155
    {
156
        if (!$doorId) {
157
158
159
            return false;
        }

160
        return $this->getDoorId() === (int)$doorId;
161
    }
Jacob Priddy's avatar
Jacob Priddy committed
162
163
164
165
166
167
168
169

    /**
     * @return string
     */
    public function getReason(): string
    {
        return $this->reason;
    }
170
}