@@ -131,18 +131,18 @@ abstract class AbstractElement
131
131
protected $ collectionRelation = false ;
132
132
133
133
/**
134
- * The start position for the linked comment.
134
+ * The start position for the linked comments
135
135
*
136
- * @var Comment
136
+ * @var \PHPOffice\PHPWord\Collection\Comments
137
137
*/
138
- protected $ commentRangeStart ;
138
+ protected $ commentsRangeStart ;
139
139
140
140
/**
141
- * The end position for the linked comment.
141
+ * The end position for the linked comments
142
142
*
143
- * @var Comment
143
+ * @var \PHPOffice\PHPWord\Collection\Comments
144
144
*/
145
- protected $ commentRangeEnd ;
145
+ protected $ commentsRangeEnd ;
146
146
147
147
/**
148
148
* Get PhpWord.
@@ -288,13 +288,27 @@ public function getNestedLevel()
288
288
}
289
289
290
290
/**
291
- * Get comment start.
291
+ * Get comments start
292
+ *
293
+ * @return \PhpOffice\PhpWord\Collection\Comments
294
+ */
295
+ public function getCommentsRangeStart ()
296
+ {
297
+ return $ this ->commentsRangeStart ;
298
+ }
299
+
300
+ /**
301
+ * Get comment start
292
302
*
293
303
* @return Comment
294
304
*/
295
305
public function getCommentRangeStart ()
296
306
{
297
- return $ this ->commentRangeStart ;
307
+ if ($ this ->commentsRangeStart != null ) {
308
+ return $ this ->commentsRangeStart ->getItem ($ this ->commentsRangeStart ->countItems ());
309
+ }
310
+
311
+ return null ;
298
312
}
299
313
300
314
/**
@@ -305,8 +319,30 @@ public function setCommentRangeStart(Comment $value): void
305
319
if ($ this instanceof Comment) {
306
320
throw new InvalidArgumentException ('Cannot set a Comment on a Comment ' );
307
321
}
308
- $ this ->commentRangeStart = $ value ;
309
- $ this ->commentRangeStart ->setStartElement ($ this );
322
+ if ($ this ->commentsRangeStart == null ) {
323
+ $ this ->commentsRangeStart = new \PhpOffice \PhpWord \Collection \Comments ();
324
+ }
325
+ // Set ID early to avoid duplicates.
326
+ if ($ value ->getElementId () == null ) {
327
+ $ value ->setElementId ();
328
+ }
329
+ foreach ($ this ->commentsRangeStart ->getItems () as $ comment ) {
330
+ if ($ value ->getElementId () == $ comment ->getElementId ()) {
331
+ return ;
332
+ }
333
+ }
334
+ $ this ->commentsRangeStart ->addItem ($ value );
335
+ $ this ->commentsRangeStart ->getItem ($ this ->commentsRangeStart ->countItems ())->setStartElement ($ this );
336
+ }
337
+
338
+ /**
339
+ * Get comments end
340
+ *
341
+ * @return \PhpOffice\PhpWord\Collection\Comments
342
+ */
343
+ public function getCommentsRangeEnd ()
344
+ {
345
+ return $ this ->commentsRangeEnd ;
310
346
}
311
347
312
348
/**
@@ -316,7 +352,11 @@ public function setCommentRangeStart(Comment $value): void
316
352
*/
317
353
public function getCommentRangeEnd ()
318
354
{
319
- return $ this ->commentRangeEnd ;
355
+ if ($ this ->commentsRangeEnd != null ) {
356
+ return $ this ->commentsRangeEnd ->getItem ($ this ->commentsRangeEnd ->countItems ());
357
+ }
358
+
359
+ return null ;
320
360
}
321
361
322
362
/**
@@ -327,8 +367,20 @@ public function setCommentRangeEnd(Comment $value): void
327
367
if ($ this instanceof Comment) {
328
368
throw new InvalidArgumentException ('Cannot set a Comment on a Comment ' );
329
369
}
330
- $ this ->commentRangeEnd = $ value ;
331
- $ this ->commentRangeEnd ->setEndElement ($ this );
370
+ if ($ this ->commentsRangeEnd == null ) {
371
+ $ this ->commentsRangeEnd = new \PhpOffice \PhpWord \Collection \Comments ();
372
+ }
373
+ // Set ID early to avoid duplicates.
374
+ if ($ value ->getElementId () == null ) {
375
+ $ value ->setElementId ();
376
+ }
377
+ foreach ($ this ->commentsRangeEnd ->getItems () as $ comment ) {
378
+ if ($ value ->getElementId () == $ comment ->getElementId ()) {
379
+ return ;
380
+ }
381
+ }
382
+ $ this ->commentsRangeEnd ->addItem ($ value );
383
+ $ this ->commentsRangeEnd ->getItem ($ this ->commentsRangeEnd ->countItems ())->setEnd ($ this );
332
384
}
333
385
334
386
/**
0 commit comments