Completed
Push — add-day-types ( 6f4108...648dae )
by
unknown
02:04
created

Booking::getLogType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace JhFlexiTime\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use ZfcUser\Entity\UserInterface;
7
use JhFlexiTime\DateTime\DateTime;
8
use JsonSerializable;
9
10
/**
11
 * Class Booking
12
 * @package JhFlexiTime\Entity
13
 * @author Ben Lill <[email protected]>
14
 *
15
 * @ORM\Entity
16
 * @ORM\Table(name="booking")
17
 */
18
class Booking implements JsonSerializable
19
{
20
21
    /**
22
     * @ORM\Id
23
     * @ORM\ManyToOne(targetEntity="JhUser\Entity\User")
24
     */
25
    protected $user = null;
26
27
    /**
28
     * @var DateTime
29
     *
30
     * @ORM\Id
31
     * @ORM\Column(type="date", name="date", nullable=false)
32
     */
33
    protected $date;
34
35
    /**
36
     * @var DateTime
37
     *
38
     * @ORM\Column(type="time", name="start_time", nullable=false)
39
     */
40
    protected $startTime;
41
42
    /**
43
     * @var DateTime
44
     *
45
     * @ORM\Column(type="time", name="end_time", nullable=false)
46
     */
47
    protected $endTime;
48
49
    /**
50
     * @var int
51
     *
52
     * @ORM\Column(type="string", length=255, nullable=false)
53
     */
54
    protected $total = 0;
55
56
    /**
57
     * @var int
58
     *
59
     * @ORM\Column(type="string", length=255, nullable=false)
60
     */
61
    protected $balance = 0;
62
63
    /** @var string
64
     *
65
     * @ORM\Column(type="string", name="log_type", length=255, nullable=false)
66
     */
67
    protected $logType;
68
69
    /** @var string
70
     *
71
     * @ORM\Column(type="string", length=512, nullable=true)
72
     */
73
    protected $notes = null;
74
75
    /**
76
     * Set Defaults
77
     */
78
    public function __construct()
79
    {
80
        $this->date         = new DateTime("today");
81
        $this->startTime    = new DateTime('09:00:00');
82
        $this->endTime      = new DateTime('17:30:00');
83
        $this->logType      = "workingDay";
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getId()
90
    {
91
        if (!$this->user) {
92
            throw new \RuntimeException("No User is set. Needed to generate ID");
93
        }
94
95
        return $this->date->format('U') . "-" . $this->user->getId();
96
    }
97
98
    /**
99
     *
100
     * @param \ZfcUser\Entity\UserInterface $user
101
     * @return \JhFlexiTime\Entity\Booking
102
     */
103
    public function setUser(UserInterface $user)
104
    {
105
        $this->user = $user;
106
        return $this;
107
    }
108
109
    /**
110
     * @return \ZfcUser\Entity\UserInterface
111
     */
112
    public function getUser()
113
    {
114
        return $this->user;
115
    }
116
117
    /**
118
     * @param DateTime $date
119
     * @return \JhFlexiTime\Entity\Booking
120
     */
121
    public function setDate(DateTime $date)
122
    {
123
        $this->date = $date;
124
        return $this;
125
    }
126
127
    /**
128
     * @return DateTime
129
     */
130
    public function getDate()
131
    {
132
        return $this->date;
133
    }
134
135
    /**
136
     * @param DateTime $startTime
137
     * @return \JhFlexiTime\Entity\Booking
138
     */
139
    public function setStartTime(DateTime $startTime)
140
    {
141
        $this->startTime = $startTime;
142
        return $this;
143
    }
144
145
    /**
146
     * @return DateTime
147
     */
148
    public function getStartTime()
149
    {
150
        return $this->startTime;
151
    }
152
153
    /**
154
     * @param DateTime $endTime
155
     * @return \JhFlexiTime\Entity\Booking
156
     */
157
    public function setEndTime(DateTime $endTime)
158
    {
159
        $this->endTime = $endTime;
160
        return $this;
161
    }
162
163
    /**
164
     * @return DateTime
165
     */
166
    public function getEndTime()
167
    {
168
        return $this->endTime;
169
    }
170
171
    /**
172
     * @param string $total
173
     * @return \JhFlexiTime\Entity\Booking
174
     */
175
    public function setTotal($total)
176
    {
177
        $this->total = $total;
0 ignored issues
show
Documentation Bug introduced by
The property $total was declared of type integer, but $total is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
178
        return $this;
179
    }
180
181
    /**
182
     * @return string
183
     */
184
    public function getTotal()
185
    {
186
        return $this->total;
187
    }
188
189
    /**
190
     * @param int $balance
191
     * @return \JhFlexiTime\Entity\Booking
192
     */
193
    public function setBalance($balance)
194
    {
195
        $this->balance = $balance;
196
        return $this;
197
    }
198
199
    /**
200
     * @return int
201
     */
202
    public function getBalance()
203
    {
204
        return $this->balance;
205
    }
206
207
    /**
208
     * @param string $notes
209
     * @return \JhFlexiTime\Entity\Booking
210
     */
211
    public function setNotes($notes)
212
    {
213
        $this->notes = $notes;
214
        return $this;
215
    }
216
217
    /**
218
     * @return string
219
     */
220
    public function getNotes()
221
    {
222
        return $this->notes;
223
    }
224
225
    /**
226
     * @param string $logType
227
     * @return \JhFlexiTime\Entity\Booking
228
     */
229
    public function setLogType($logType)
230
    {
231
        $this->logType = $logType;
232
        return $this;
233
    }
234
235
    /**
236
     * @return string
237
     */
238
    public function getLogType()
239
    {
240
        return $this->logType;
241
    }
242
243
    /**
244
     * @return array
245
     */
246
    public function jsonSerialize()
247
    {
248
        return [
249
            'id'        => $this->getId(),
250
            'user'      => $this->user->getId(),
251
            'date'      => $this->date->format('d-m-Y'),
252
            'startTime' => $this->startTime->format('H:i'),
253
            'endTime'   => $this->endTime->format('H:i'),
254
            'total'     => $this->total,
255
            'balance'   => $this->balance,
256
            'logType'   => $this->logType,
257
            'notes'     => $this->notes,
258
        ];
259
    }
260
}
261