Entry.php 2.71 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 string
22
     */
23
    protected string $doorLocation;
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;

40
41
42
    public function __construct(
        int $id,
        int $userId,
43
        string $doorLocation,
44
        bool $success,
45
46
47
48
49
        ?Carbon $createdAt = null,
        ?Carbon $updatedAt = null
    ) {
        $this->id = $id;
        $this->userId = $userId;
50
        $this->doorLocation = $doorLocation;
51
        $this->success = $success;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
        $this->createdAt = $createdAt;
        $this->updatedAt = $updatedAt;
    }

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

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

    /**
73
     * @return string
74
     */
75
    public function getDoorLocation(): string
76
    {
77
        return $this->doorLocation;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    }

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

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

96
97
98
99
100
101
102
103
    /**
     * @return bool
     */
    public function wasSuccessful(): bool
    {
        return $this->success;
    }

104
105
106
107
108
    /**
     * @param \Carbon\Carbon $begin
     * @param \Carbon\Carbon $end
     * @return bool
     */
Jacob Priddy's avatar
Jacob Priddy committed
109
    public function isBetween(?Carbon $begin, ?Carbon $end): bool
110
    {
111
112
113
114
        if (!$this->createdAt) {
            return true;
        }

Jacob Priddy's avatar
Jacob Priddy committed
115
116
117
118
119
120
121
122
123
124
125
126
127
        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;
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    }

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

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

    /**
144
     * @param string|null $doorLocation
145
146
     * @return bool
     */
147
    public function hasDoorLocationLike(?string $doorLocation): bool
148
    {
149
        if (!$doorLocation) {
150
151
152
            return false;
        }

153
        return stripos($this->getDoorLocation(), $doorLocation) !== false;
154
155
    }
}