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
|
|
|
/** @var bool */ |
70
|
|
|
private $pushed; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
|
|
public function isPushed() |
76
|
|
|
{ |
77
|
|
|
return $this->pushed; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param bool $pushed |
82
|
|
|
*/ |
83
|
|
|
public function setPushed($pushed) |
84
|
|
|
{ |
85
|
|
|
$this->pushed = $pushed; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Getter for the default date format |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function getDefaultDateFormat() |
94
|
|
|
{ |
95
|
|
|
return self::DEFAULT_DATE_FORMAT; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Getter for the booking time |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getTime() |
104
|
|
|
{ |
105
|
|
|
return $this->time; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Getter for the booked ticket id |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getTicketId() |
114
|
|
|
{ |
115
|
|
|
return $this->ticketId; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Getter for the booking comment |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getComment() |
124
|
|
|
{ |
125
|
|
|
return $this->comment; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Whether or not this booking is a meta booking used |
130
|
|
|
* to either create workflows or groupings of bookings and time durations |
131
|
|
|
* |
132
|
|
|
* @return boolean |
133
|
|
|
*/ |
134
|
|
|
public function isMetaBooking() |
135
|
|
|
{ |
136
|
|
|
return in_array($this->getTicketId(), $this->getMetaTicketIds()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Getter for the meta ticket IDs |
141
|
|
|
* |
142
|
|
|
* @return string[] |
143
|
|
|
*/ |
144
|
|
|
public function getMetaTicketIds() |
145
|
|
|
{ |
146
|
|
|
return $this->metaTicketIds; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Default constructor |
151
|
|
|
* |
152
|
|
|
* @param string $comment Comment for the booking |
153
|
|
|
* @param string $ticketId [optional] Optional ticket ID. Defaults to an empty string |
154
|
|
|
* @param null|string|integer $time [optional] Time of this booking. Defaults to NULL |
155
|
|
|
* @param bool $pushed [optional] If pushed to jira worklog |
156
|
|
|
*/ |
157
|
|
|
public function __construct($comment, $ticketId = '', $time = null, $pushed=false) |
158
|
|
|
{ |
159
|
|
|
// get the arguments |
160
|
|
|
$this->ticketId = trim($ticketId); |
161
|
|
|
$this->comment = trim($comment); |
162
|
|
|
$this->pushed = $pushed; |
163
|
|
|
|
164
|
|
|
// get the current date and time (if not given) |
165
|
|
|
if (is_null($time)) { |
166
|
|
|
$this->time = date(self::DEFAULT_DATE_FORMAT); |
167
|
|
|
} elseif (is_integer($time)) { |
168
|
|
|
$this->time = date(self::DEFAULT_DATE_FORMAT, $time); |
169
|
|
|
} else { |
170
|
|
|
$this->time = date(self::DEFAULT_DATE_FORMAT, strtotime($time)); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Whether or not this booking can be the start of a task |
176
|
|
|
* |
177
|
|
|
* @return boolean |
178
|
|
|
*/ |
179
|
|
|
public function canStartTask() |
180
|
|
|
{ |
181
|
|
|
return true; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Whether or not this booking can be the end of a task |
186
|
|
|
* |
187
|
|
|
* @return boolean |
188
|
|
|
*/ |
189
|
|
|
public function canEndTask() |
190
|
|
|
{ |
191
|
|
|
return true; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|