1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
6
|
|
|
|
7
|
|
|
class Comment implements IComparable |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Author. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $author; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Rich text comment. |
18
|
|
|
* |
19
|
|
|
* @var RichText |
20
|
|
|
*/ |
21
|
|
|
private $text; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Comment width (CSS style, i.e. XXpx or YYpt). |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $width = '96pt'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Left margin (CSS style, i.e. XXpx or YYpt). |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $marginLeft = '59.25pt'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Top margin (CSS style, i.e. XXpx or YYpt). |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $marginTop = '1.5pt'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Visible. |
46
|
|
|
* |
47
|
|
|
* @var bool |
48
|
|
|
*/ |
49
|
|
|
private $visible = false; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Comment height (CSS style, i.e. XXpx or YYpt). |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private $height = '55.5pt'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Comment fill color. |
60
|
|
|
* |
61
|
|
|
* @var Style\Color |
62
|
|
|
*/ |
63
|
|
|
private $fillColor; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Alignment. |
67
|
|
|
* |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
private $alignment; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Create a new Comment. |
74
|
|
|
*/ |
75
|
27 |
|
public function __construct() |
76
|
|
|
{ |
77
|
|
|
// Initialise variables |
78
|
27 |
|
$this->author = 'Author'; |
79
|
27 |
|
$this->text = new RichText(); |
80
|
27 |
|
$this->fillColor = new Style\Color('FFFFFFE1'); |
81
|
27 |
|
$this->alignment = Style\Alignment::HORIZONTAL_GENERAL; |
82
|
27 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get Author. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
9 |
|
public function getAuthor() |
90
|
|
|
{ |
91
|
9 |
|
return $this->author; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set Author. |
96
|
|
|
* |
97
|
|
|
* @param string $author |
98
|
|
|
* |
99
|
|
|
* @return Comment |
100
|
|
|
*/ |
101
|
17 |
|
public function setAuthor($author) |
102
|
|
|
{ |
103
|
17 |
|
$this->author = $author; |
104
|
|
|
|
105
|
17 |
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get Rich text comment. |
110
|
|
|
* |
111
|
|
|
* @return RichText |
112
|
|
|
*/ |
113
|
22 |
|
public function getText() |
114
|
|
|
{ |
115
|
22 |
|
return $this->text; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Set Rich text comment. |
120
|
|
|
* |
121
|
|
|
* @param RichText $pValue |
122
|
|
|
* |
123
|
|
|
* @return Comment |
124
|
|
|
*/ |
125
|
17 |
|
public function setText(RichText $pValue) |
126
|
|
|
{ |
127
|
17 |
|
$this->text = $pValue; |
128
|
|
|
|
129
|
17 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get comment width (CSS style, i.e. XXpx or YYpt). |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
9 |
|
public function getWidth() |
138
|
|
|
{ |
139
|
9 |
|
return $this->width; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Set comment width (CSS style, i.e. XXpx or YYpt). |
144
|
|
|
* |
145
|
|
|
* @param string $width |
146
|
|
|
* |
147
|
|
|
* @return Comment |
148
|
|
|
*/ |
149
|
12 |
|
public function setWidth($width) |
150
|
|
|
{ |
151
|
12 |
|
$this->width = $width; |
152
|
|
|
|
153
|
12 |
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get comment height (CSS style, i.e. XXpx or YYpt). |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
9 |
|
public function getHeight() |
162
|
|
|
{ |
163
|
9 |
|
return $this->height; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set comment height (CSS style, i.e. XXpx or YYpt). |
168
|
|
|
* |
169
|
|
|
* @param string $value |
170
|
|
|
* |
171
|
|
|
* @return Comment |
172
|
|
|
*/ |
173
|
12 |
|
public function setHeight($value) |
174
|
|
|
{ |
175
|
12 |
|
$this->height = $value; |
176
|
|
|
|
177
|
12 |
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Get left margin (CSS style, i.e. XXpx or YYpt). |
182
|
|
|
* |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
9 |
|
public function getMarginLeft() |
186
|
|
|
{ |
187
|
9 |
|
return $this->marginLeft; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Set left margin (CSS style, i.e. XXpx or YYpt). |
192
|
|
|
* |
193
|
|
|
* @param string $value |
194
|
|
|
* |
195
|
|
|
* @return Comment |
196
|
|
|
*/ |
197
|
12 |
|
public function setMarginLeft($value) |
198
|
|
|
{ |
199
|
12 |
|
$this->marginLeft = $value; |
200
|
|
|
|
201
|
12 |
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get top margin (CSS style, i.e. XXpx or YYpt). |
206
|
|
|
* |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
9 |
|
public function getMarginTop() |
210
|
|
|
{ |
211
|
9 |
|
return $this->marginTop; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set top margin (CSS style, i.e. XXpx or YYpt). |
216
|
|
|
* |
217
|
|
|
* @param string $value |
218
|
|
|
* |
219
|
|
|
* @return Comment |
220
|
|
|
*/ |
221
|
2 |
|
public function setMarginTop($value) |
222
|
|
|
{ |
223
|
2 |
|
$this->marginTop = $value; |
224
|
|
|
|
225
|
2 |
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Is the comment visible by default? |
230
|
|
|
* |
231
|
|
|
* @return bool |
232
|
|
|
*/ |
233
|
9 |
|
public function getVisible() |
234
|
|
|
{ |
235
|
9 |
|
return $this->visible; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Set comment default visibility. |
240
|
|
|
* |
241
|
|
|
* @param bool $value |
242
|
|
|
* |
243
|
|
|
* @return Comment |
244
|
|
|
*/ |
245
|
2 |
|
public function setVisible($value) |
246
|
|
|
{ |
247
|
2 |
|
$this->visible = $value; |
248
|
|
|
|
249
|
2 |
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Get fill color. |
254
|
|
|
* |
255
|
|
|
* @return Style\Color |
256
|
|
|
*/ |
257
|
16 |
|
public function getFillColor() |
258
|
|
|
{ |
259
|
16 |
|
return $this->fillColor; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Set Alignment. |
264
|
|
|
* |
265
|
|
|
* @param string $alignment see Style\Alignment::HORIZONTAL_* |
266
|
|
|
* |
267
|
|
|
* @return Comment |
268
|
|
|
*/ |
269
|
|
|
public function setAlignment($alignment) |
270
|
|
|
{ |
271
|
|
|
$this->alignment = $alignment; |
272
|
|
|
|
273
|
|
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Get Alignment. |
278
|
|
|
* |
279
|
|
|
* @return string |
280
|
|
|
*/ |
281
|
|
|
public function getAlignment() |
282
|
|
|
{ |
283
|
|
|
return $this->alignment; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Get hash code. |
288
|
|
|
* |
289
|
|
|
* @return string Hash code |
290
|
|
|
*/ |
291
|
|
|
public function getHashCode() |
292
|
|
|
{ |
293
|
|
|
return md5( |
294
|
|
|
$this->author . |
295
|
|
|
$this->text->getHashCode() . |
296
|
|
|
$this->width . |
297
|
|
|
$this->height . |
298
|
|
|
$this->marginLeft . |
299
|
|
|
$this->marginTop . |
300
|
|
|
($this->visible ? 1 : 0) . |
301
|
|
|
$this->fillColor->getHashCode() . |
302
|
|
|
$this->alignment . |
303
|
|
|
__CLASS__ |
304
|
|
|
); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
309
|
|
|
*/ |
310
|
|
|
public function __clone() |
311
|
|
|
{ |
312
|
|
|
$vars = get_object_vars($this); |
313
|
|
|
foreach ($vars as $key => $value) { |
314
|
|
|
if (is_object($value)) { |
315
|
|
|
$this->$key = clone $value; |
316
|
|
|
} else { |
317
|
|
|
$this->$key = $value; |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Convert to string. |
324
|
|
|
* |
325
|
|
|
* @return string |
326
|
|
|
*/ |
327
|
|
|
public function __toString() |
328
|
|
|
{ |
329
|
|
|
return $this->text->getPlainText(); |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|