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