1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Wunderlist; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use NotificationChannels\Wunderlist\Exceptions\CouldNotCreateMessage; |
7
|
|
|
|
8
|
|
|
class WunderlistMessage |
9
|
|
|
{ |
10
|
|
|
/** @var string */ |
11
|
|
|
protected $title; |
12
|
|
|
|
13
|
|
|
/** @var bool */ |
14
|
|
|
protected $completed; |
15
|
|
|
|
16
|
|
|
/** @var bool */ |
17
|
|
|
protected $starred; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $recurrenceType; |
21
|
|
|
|
22
|
|
|
/** @var string|null */ |
23
|
|
|
protected $due; |
24
|
|
|
|
25
|
|
|
/** @var int|null */ |
26
|
|
|
protected $assigneeId; |
27
|
|
|
|
28
|
|
|
/** @var int|null */ |
29
|
|
|
protected $recurrenceCount; |
30
|
|
|
|
31
|
|
|
const RECURRENCE_TYPE_DAY = 'day'; |
32
|
|
|
const RECURRENCE_TYPE_WEEK = 'week'; |
33
|
|
|
const RECURRENCE_TYPE_MONTH = 'month'; |
34
|
|
|
const RECURRENCE_TYPE_YEAR = 'year'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $title |
38
|
|
|
* |
39
|
|
|
* @return static |
40
|
|
|
*/ |
41
|
1 |
|
public static function create($title) |
42
|
|
|
{ |
43
|
1 |
|
return new static($title); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $title |
48
|
|
|
*/ |
49
|
16 |
|
public function __construct($title) |
50
|
|
|
{ |
51
|
16 |
|
$this->title = $title; |
52
|
16 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the ticket title. |
56
|
|
|
* |
57
|
|
|
* @param $title |
58
|
|
|
* |
59
|
|
|
* @return $this |
60
|
|
|
*/ |
61
|
1 |
|
public function title($title) |
62
|
|
|
{ |
63
|
1 |
|
$this->title = $title; |
64
|
|
|
|
65
|
1 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Set the ticket assignee_id. |
70
|
|
|
* |
71
|
|
|
* @param int $assigneeId |
72
|
|
|
* |
73
|
|
|
* @return $this |
74
|
|
|
*/ |
75
|
|
|
public function assigneeId($assigneeId) |
76
|
|
|
{ |
77
|
|
|
$this->assigneeId = $assigneeId; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set the ticket recurrence_count. |
84
|
|
|
* |
85
|
|
|
* @param int $recurrenceCount |
86
|
|
|
* |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
|
|
public function recurrenceCount($recurrenceCount) |
90
|
|
|
{ |
91
|
|
|
$this->recurrenceCount = $recurrenceCount; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Set the ticket recurrent_type property. |
98
|
|
|
* |
99
|
|
|
* @param string $recurrenceType |
100
|
|
|
* |
101
|
|
|
* @throws CouldNotCreateMessage |
102
|
|
|
* |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
5 |
|
public function recurrenceType($recurrenceType) |
106
|
|
|
{ |
107
|
|
|
$allowedRecurrenceTypes = [ |
108
|
5 |
|
self::RECURRENCE_TYPE_DAY, |
109
|
5 |
|
self::RECURRENCE_TYPE_WEEK, |
110
|
5 |
|
self::RECURRENCE_TYPE_MONTH, |
111
|
5 |
|
self::RECURRENCE_TYPE_YEAR, |
112
|
5 |
|
]; |
113
|
|
|
|
114
|
5 |
|
if (! in_array($recurrenceType, $allowedRecurrenceTypes)) { |
115
|
1 |
|
throw CouldNotCreateMessage::invalidRecurrenceType($recurrenceType); |
116
|
|
|
} |
117
|
|
|
|
118
|
4 |
|
$this->recurrenceType = $recurrenceType; |
119
|
|
|
|
120
|
4 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Set the ticket as starred. |
125
|
|
|
* |
126
|
|
|
* @return $this |
127
|
|
|
*/ |
128
|
3 |
|
public function starred() |
129
|
|
|
{ |
130
|
3 |
|
$this->starred = true; |
131
|
|
|
|
132
|
3 |
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Set the ticket as completed. |
137
|
|
|
* |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
1 |
|
public function completed() |
141
|
|
|
{ |
142
|
1 |
|
$this->completed = true; |
143
|
|
|
|
144
|
1 |
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Set the card position due date. |
149
|
|
|
* |
150
|
|
|
* @param string|DateTime $due |
151
|
|
|
* |
152
|
|
|
* @return $this |
153
|
|
|
*/ |
154
|
2 |
|
public function due($due) |
155
|
|
|
{ |
156
|
2 |
|
if (! $due instanceof DateTime) { |
157
|
1 |
|
$due = new DateTime($due); |
158
|
1 |
|
} |
159
|
|
|
|
160
|
2 |
|
$this->due = $due->format(DateTime::ATOM); |
161
|
|
|
|
162
|
2 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return array |
167
|
|
|
*/ |
168
|
15 |
|
public function toArray() |
169
|
|
|
{ |
170
|
|
|
return [ |
171
|
15 |
|
'title' => $this->title, |
172
|
15 |
|
'assignee_id' => $this->assigneeId, |
173
|
15 |
|
'completed' => $this->completed, |
174
|
15 |
|
'recurrence_type' => $this->recurrenceType, |
175
|
15 |
|
'recurrence_count' => $this->recurrenceCount, |
176
|
15 |
|
'due_date' => $this->due, |
177
|
15 |
|
'starred' => $this->starred, |
178
|
15 |
|
]; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|