|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \Wicked\Timely\Entities\Booking |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Bernhard Wick <[email protected]> |
|
15
|
|
|
* @copyright 2016 Bernhard Wick |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/wick-ed/timely |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Wicked\Timely\Entities; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Booking entity |
|
24
|
|
|
* |
|
25
|
|
|
* @author Bernhard Wick <[email protected]> |
|
26
|
|
|
* @copyright 2016 Bernhard Wick |
|
27
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
28
|
|
|
* @link https://github.com/wick-ed/timely |
|
29
|
|
|
*/ |
|
30
|
|
|
class Booking |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Default date format |
|
35
|
|
|
* |
|
36
|
|
|
* @var string DEFAULT_DATE_FORMAT |
|
37
|
|
|
*/ |
|
38
|
|
|
const DEFAULT_DATE_FORMAT = 'Y-m-d H:i:s'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Id of a potential ticket the booking is for |
|
42
|
|
|
* |
|
43
|
|
|
* @var string|null $ticketId |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $ticketId; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Comment regarding the current booking |
|
49
|
|
|
* |
|
50
|
|
|
* @var string $comment |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $comment; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Time this booking was made |
|
56
|
|
|
* |
|
57
|
|
|
* @var string $time |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $time; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* A list of special ticket IDs which identify a meta ticket |
|
63
|
|
|
* |
|
64
|
|
|
* @var string[] $metaTicketIds |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $metaTicketIds = array(); |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Getter for the default date format |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getDefaultDateFormat() |
|
74
|
|
|
{ |
|
75
|
|
|
return self::DEFAULT_DATE_FORMAT; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Getter for the booking time |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getTime() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->time; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Getter for the booked ticket id |
|
90
|
|
|
* |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getTicketId() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->ticketId; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Getter for the booking comment |
|
100
|
|
|
* |
|
101
|
|
|
* @return string |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getComment() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->comment; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Whether or not this booking is a meta booking used |
|
110
|
|
|
* to either create workflows or groupings of bookings and time durations |
|
111
|
|
|
* |
|
112
|
|
|
* @return boolean |
|
113
|
|
|
*/ |
|
114
|
|
|
public function isMetaBooking() |
|
115
|
|
|
{ |
|
116
|
|
|
return in_array($this->getTicketId(), $this->getMetaTicketIds()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Getter for the meta ticket IDs |
|
121
|
|
|
* |
|
122
|
|
|
* @return string[] |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getMetaTicketIds() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->metaTicketIds; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Default constructor |
|
131
|
|
|
* |
|
132
|
|
|
* @param string $comment Comment for the booking |
|
133
|
|
|
* @param string $ticketId [optional] Optional ticket ID. Defaults to an empty string |
|
134
|
|
|
* @param null|string|integer $time [optional] Time of this booking. Defaults to NULL |
|
135
|
|
|
*/ |
|
136
|
|
|
public function __construct($comment, $ticketId = '', $time = null) |
|
137
|
|
|
{ |
|
138
|
|
|
// get the arguments |
|
139
|
|
|
$this->ticketId = trim($ticketId); |
|
140
|
|
|
$this->comment = trim($comment); |
|
141
|
|
|
|
|
142
|
|
|
// get the current date and time (if not given) |
|
143
|
|
|
if (is_null($time)) { |
|
144
|
|
|
$this->time = date(self::DEFAULT_DATE_FORMAT); |
|
145
|
|
|
} elseif (is_integer($time)) { |
|
146
|
|
|
$this->time = date(self::DEFAULT_DATE_FORMAT, $time); |
|
147
|
|
|
} else { |
|
148
|
|
|
$this->time = trim($time); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Whether or not this booking can be the start of a task |
|
154
|
|
|
* |
|
155
|
|
|
* @return boolean |
|
156
|
|
|
*/ |
|
157
|
|
|
public function canStartTask() |
|
158
|
|
|
{ |
|
159
|
|
|
return true; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Whether or not this booking can be the end of a task |
|
164
|
|
|
* |
|
165
|
|
|
* @return boolean |
|
166
|
|
|
*/ |
|
167
|
|
|
public function canEndTask() |
|
168
|
|
|
{ |
|
169
|
|
|
return true; |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|