1
This commit is contained in:
@@ -19,8 +19,10 @@ namespace PhpOffice\PhpWord\Element;
|
||||
|
||||
use DateTime;
|
||||
use InvalidArgumentException;
|
||||
use PhpOffice\PhpWord\Collection\Comments;
|
||||
use PhpOffice\PhpWord\Media;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
|
||||
/**
|
||||
* Element abstract class.
|
||||
@@ -32,7 +34,7 @@ abstract class AbstractElement
|
||||
/**
|
||||
* PhpWord object.
|
||||
*
|
||||
* @var ?\PhpOffice\PhpWord\PhpWord
|
||||
* @var ?PhpWord
|
||||
*/
|
||||
protected $phpWord;
|
||||
|
||||
@@ -131,25 +133,25 @@ abstract class AbstractElement
|
||||
protected $collectionRelation = false;
|
||||
|
||||
/**
|
||||
* The start position for the linked comment.
|
||||
* The start position for the linked comments.
|
||||
*
|
||||
* @var Comment
|
||||
* @var Comments
|
||||
*/
|
||||
protected $commentRangeStart;
|
||||
protected $commentsRangeStart;
|
||||
|
||||
/**
|
||||
* The end position for the linked comment.
|
||||
* The end position for the linked comments.
|
||||
*
|
||||
* @var Comment
|
||||
* @var Comments
|
||||
*/
|
||||
protected $commentRangeEnd;
|
||||
protected $commentsRangeEnd;
|
||||
|
||||
/**
|
||||
* Get PhpWord.
|
||||
*
|
||||
* @return ?\PhpOffice\PhpWord\PhpWord
|
||||
* @return ?PhpWord
|
||||
*/
|
||||
public function getPhpWord()
|
||||
public function getPhpWord(): ?PhpWord
|
||||
{
|
||||
return $this->phpWord;
|
||||
}
|
||||
@@ -287,14 +289,28 @@ abstract class AbstractElement
|
||||
return $this->nestedLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get comments start.
|
||||
*
|
||||
* @return Comments
|
||||
*/
|
||||
public function getCommentsRangeStart(): ?Comments
|
||||
{
|
||||
return $this->commentsRangeStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get comment start.
|
||||
*
|
||||
* @return Comment
|
||||
*/
|
||||
public function getCommentRangeStart()
|
||||
public function getCommentRangeStart(): ?Comment
|
||||
{
|
||||
return $this->commentRangeStart;
|
||||
if ($this->commentsRangeStart != null) {
|
||||
return $this->commentsRangeStart->getItem($this->commentsRangeStart->countItems());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,8 +321,30 @@ abstract class AbstractElement
|
||||
if ($this instanceof Comment) {
|
||||
throw new InvalidArgumentException('Cannot set a Comment on a Comment');
|
||||
}
|
||||
$this->commentRangeStart = $value;
|
||||
$this->commentRangeStart->setStartElement($this);
|
||||
if ($this->commentsRangeStart == null) {
|
||||
$this->commentsRangeStart = new Comments();
|
||||
}
|
||||
// Set ID early to avoid duplicates.
|
||||
if ($value->getElementId() == null) {
|
||||
$value->setElementId();
|
||||
}
|
||||
foreach ($this->commentsRangeStart->getItems() as $comment) {
|
||||
if ($value->getElementId() == $comment->getElementId()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$idxItem = $this->commentsRangeStart->addItem($value);
|
||||
$this->commentsRangeStart->getItem($idxItem)->setStartElement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get comments end.
|
||||
*
|
||||
* @return Comments
|
||||
*/
|
||||
public function getCommentsRangeEnd(): ?Comments
|
||||
{
|
||||
return $this->commentsRangeEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,9 +352,13 @@ abstract class AbstractElement
|
||||
*
|
||||
* @return Comment
|
||||
*/
|
||||
public function getCommentRangeEnd()
|
||||
public function getCommentRangeEnd(): ?Comment
|
||||
{
|
||||
return $this->commentRangeEnd;
|
||||
if ($this->commentsRangeEnd != null) {
|
||||
return $this->commentsRangeEnd->getItem($this->commentsRangeEnd->countItems());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,8 +369,20 @@ abstract class AbstractElement
|
||||
if ($this instanceof Comment) {
|
||||
throw new InvalidArgumentException('Cannot set a Comment on a Comment');
|
||||
}
|
||||
$this->commentRangeEnd = $value;
|
||||
$this->commentRangeEnd->setEndElement($this);
|
||||
if ($this->commentsRangeEnd == null) {
|
||||
$this->commentsRangeEnd = new Comments();
|
||||
}
|
||||
// Set ID early to avoid duplicates.
|
||||
if ($value->getElementId() == null) {
|
||||
$value->setElementId();
|
||||
}
|
||||
foreach ($this->commentsRangeEnd->getItems() as $comment) {
|
||||
if ($value->getElementId() == $comment->getElementId()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$idxItem = $this->commentsRangeEnd->addItem($value);
|
||||
$this->commentsRangeEnd->getItem($idxItem)->setEndElement($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,7 +482,7 @@ abstract class AbstractElement
|
||||
* Set new style value.
|
||||
*
|
||||
* @param mixed $styleObject Style object
|
||||
* @param null|array|\PhpOffice\PhpWord\Style|string $styleValue Style value
|
||||
* @param null|array|string|Style $styleValue Style value
|
||||
* @param bool $returnObject Always return object
|
||||
*
|
||||
* @return mixed
|
||||
|
||||
@@ -83,9 +83,7 @@ class Comment extends TrackChange
|
||||
public function setStartElement(AbstractElement $value): void
|
||||
{
|
||||
$this->startElement = $value;
|
||||
if ($value->getCommentRangeStart() == null) {
|
||||
$value->setCommentRangeStart($this);
|
||||
}
|
||||
$value->setCommentRangeStart($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,9 +102,7 @@ class Comment extends TrackChange
|
||||
public function setEndElement(AbstractElement $value): void
|
||||
{
|
||||
$this->endElement = $value;
|
||||
if ($value->getCommentRangeEnd() == null) {
|
||||
$value->setCommentRangeEnd($this);
|
||||
}
|
||||
$value->setCommentRangeEnd($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -91,6 +91,10 @@ class Field extends AbstractElement
|
||||
],
|
||||
'options' => ['Path', 'PreserveFormat'],
|
||||
],
|
||||
'REF' => [
|
||||
'properties' => ['name' => ''],
|
||||
'options' => ['f', 'h', 'n', 'p', 'r', 't', 'w'],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -386,8 +386,9 @@ class Image extends AbstractElement
|
||||
$imageBinary = $this->source;
|
||||
} else {
|
||||
$fileHandle = fopen($actualSource, 'rb', false);
|
||||
if ($fileHandle !== false) {
|
||||
$imageBinary = fread($fileHandle, filesize($actualSource));
|
||||
$fileSize = filesize($actualSource);
|
||||
if ($fileHandle !== false && $fileSize > 0) {
|
||||
$imageBinary = fread($fileHandle, $fileSize);
|
||||
fclose($fileHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ class TextRun extends AbstractContainer
|
||||
/**
|
||||
* Paragraph style.
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph|string
|
||||
* @var Paragraph|string
|
||||
*/
|
||||
protected $paragraphStyle;
|
||||
|
||||
/**
|
||||
* Create new instance.
|
||||
*
|
||||
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $paragraphStyle
|
||||
* @param array|Paragraph|string $paragraphStyle
|
||||
*/
|
||||
public function __construct($paragraphStyle = null)
|
||||
{
|
||||
@@ -49,7 +49,7 @@ class TextRun extends AbstractContainer
|
||||
/**
|
||||
* Get Paragraph style.
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph|string
|
||||
* @return Paragraph|string
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
@@ -59,9 +59,9 @@ class TextRun extends AbstractContainer
|
||||
/**
|
||||
* Set Paragraph style.
|
||||
*
|
||||
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $style
|
||||
* @param array|Paragraph|string $style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph|string
|
||||
* @return Paragraph|string
|
||||
*/
|
||||
public function setParagraphStyle($style = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user