Refactor elements to move set relation Id from container to element
This commit is contained in:
parent
01853f7aac
commit
893843969f
|
|
@ -4,6 +4,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
||||||
|
|
||||||
## 0.12.0 - Not yet released
|
## 0.12.0 - Not yet released
|
||||||
|
|
||||||
|
This release added drawing shapes (arc, curve, line, polyline, rect, oval) element and some new styles.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Element: Ability to add drawing shapes (arc, curve, line, polyline, rect, oval) using new `Shape` element - @ivanlanin GH-123
|
- Element: Ability to add drawing shapes (arc, curve, line, polyline, rect, oval) using new `Shape` element - @ivanlanin GH-123
|
||||||
|
|
@ -18,13 +20,14 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
None yet.
|
- `Element\Link::getTarget()` replaced by `Element\Link::getSource()`
|
||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
- Docs: Add known issue on `README` about requirement for temporary folder to be writable and update `samples/index.php` for this requirement check - @ivanlanin GH-238
|
- Docs: Add known issue on `README` about requirement for temporary folder to be writable and update `samples/index.php` for this requirement check - @ivanlanin GH-238
|
||||||
- PclZip: Remove temporary file after used - @andrew-kzoo GH-265
|
- PclZip: Remove temporary file after used - @andrew-kzoo GH-265
|
||||||
- Autoloader: Add the ability to set the autoloader options - @bskrtich GH-267
|
- Autoloader: Add the ability to set the autoloader options - @bskrtich GH-267
|
||||||
|
- Element: Refactor elements to move set relation Id from container to element - @ivanlanin
|
||||||
|
|
||||||
## 0.11.1 - 2 June 2014
|
## 0.11.1 - 2 June 2014
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,6 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Media;
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container abstract class
|
* Container abstract class
|
||||||
*
|
*
|
||||||
|
|
@ -33,6 +30,10 @@ use PhpOffice\PhpWord\PhpWord;
|
||||||
* @method Footnote addFootnote(mixed $pStyle = null)
|
* @method Footnote addFootnote(mixed $pStyle = null)
|
||||||
* @method Endnote addEndnote(mixed $pStyle = null)
|
* @method Endnote addEndnote(mixed $pStyle = null)
|
||||||
* @method CheckBox addCheckBox(string $name, $text, mixed $fStyle = null, mixed $pStyle = null)
|
* @method CheckBox addCheckBox(string $name, $text, mixed $fStyle = null, mixed $pStyle = null)
|
||||||
|
* @method Title addTitle(string $text, int $depth = 1)
|
||||||
|
* @method TOC addTOC(mixed $fontStyle = null, mixed $tocStyle = null, int $minDepth = 1, int $maxDepth = 9)
|
||||||
|
*
|
||||||
|
* @method PageBreak addPageBreak()
|
||||||
* @method Table addTable(mixed $style = null)
|
* @method Table addTable(mixed $style = null)
|
||||||
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false)
|
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false)
|
||||||
* @method Object addObject(string $source, mixed $style = null)
|
* @method Object addObject(string $source, mixed $style = null)
|
||||||
|
|
@ -125,10 +126,6 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
if ($withoutP && ($elementName == 'Text' || $elementName == 'PreserveText')) {
|
if ($withoutP && ($elementName == 'Text' || $elementName == 'PreserveText')) {
|
||||||
$args[3] = null; // Remove paragraph style for texts in textrun
|
$args[3] = null; // Remove paragraph style for texts in textrun
|
||||||
}
|
}
|
||||||
$source = '';
|
|
||||||
if (count($args) > 1) {
|
|
||||||
$source = $args[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create element using reflection
|
// Create element using reflection
|
||||||
$reflection = new \ReflectionClass($elementClass);
|
$reflection = new \ReflectionClass($elementClass);
|
||||||
|
|
@ -138,15 +135,10 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
|
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
|
||||||
$element = $reflection->newInstanceArgs($elementArgs);
|
$element = $reflection->newInstanceArgs($elementArgs);
|
||||||
|
|
||||||
// Set nested level and relation Id
|
// Set parent container
|
||||||
$this->setElementNestedLevel($element);
|
$element->setParentContainer($this);
|
||||||
$this->setElementRelationId($element, $elementName, $source);
|
|
||||||
|
|
||||||
// Set other properties and add element into collection
|
|
||||||
$element->setDocPart($this->getDocPart(), $this->getDocPartId());
|
|
||||||
$element->setElementIndex($this->countElements() + 1);
|
$element->setElementIndex($this->countElements() + 1);
|
||||||
$element->setElementId();
|
$element->setElementId();
|
||||||
$element->setPhpWord($this->phpWord);
|
|
||||||
|
|
||||||
$this->elements[] = $element;
|
$this->elements[] = $element;
|
||||||
|
|
||||||
|
|
@ -173,55 +165,6 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
return count($this->elements);
|
return count($this->elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set element nested level based on container; add one when it's inside a cell
|
|
||||||
*/
|
|
||||||
private function setElementNestedLevel(AbstractElement $element)
|
|
||||||
{
|
|
||||||
if ($this->container == 'Cell') {
|
|
||||||
$element->setNestedLevel($this->getNestedLevel() + 1);
|
|
||||||
} else {
|
|
||||||
$element->setNestedLevel($this->getNestedLevel());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set relation Id
|
|
||||||
*
|
|
||||||
* @param \PhpOffice\PhpWord\Element\AbstractElement $element
|
|
||||||
* @param string $elementName
|
|
||||||
* @param string $source
|
|
||||||
*/
|
|
||||||
private function setElementRelationId(AbstractElement $element, $elementName, $source)
|
|
||||||
{
|
|
||||||
$mediaContainer = $this->getMediaContainer();
|
|
||||||
$hasMediaRelation = in_array($elementName, array('Link', 'Image', 'Object'));
|
|
||||||
$hasOtherRelation = in_array($elementName, array('Footnote', 'Endnote', 'Title'));
|
|
||||||
|
|
||||||
// Set relation Id for media elements (link, image, object; legacy of OOXML)
|
|
||||||
// Only Image that needs to be passed to Media class
|
|
||||||
if ($hasMediaRelation) {
|
|
||||||
/** @var \PhpOffice\PhpWord\Element\Image $element Type hint */
|
|
||||||
$image = ($elementName == 'Image') ? $element : null;
|
|
||||||
$rId = Media::addElement($mediaContainer, strtolower($elementName), $source, $image);
|
|
||||||
$element->setRelationId($rId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set relation Id for icon of object element
|
|
||||||
if ($elementName == 'Object') {
|
|
||||||
/** @var \PhpOffice\PhpWord\Element\Object $element Type hint */
|
|
||||||
$rIdIcon = Media::addElement($mediaContainer, 'image', $element->getIcon(), new Image($element->getIcon()));
|
|
||||||
$element->setImageRelationId($rIdIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set relation Id for elements that will be registered in the Collection subnamespaces
|
|
||||||
if ($hasOtherRelation && $this->phpWord instanceof PhpWord) {
|
|
||||||
$addMethod = "add{$elementName}";
|
|
||||||
$rId = $this->phpWord->$addMethod($element);
|
|
||||||
$element->setRelationId($rId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a method is allowed for the current container
|
* Check if a method is allowed for the current container
|
||||||
*
|
*
|
||||||
|
|
@ -254,6 +197,9 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
'Footnote' => array('Section', 'TextRun', 'Cell'),
|
'Footnote' => array('Section', 'TextRun', 'Cell'),
|
||||||
'Endnote' => array('Section', 'TextRun', 'Cell'),
|
'Endnote' => array('Section', 'TextRun', 'Cell'),
|
||||||
'PreserveText' => array('Header', 'Footer', 'Cell'),
|
'PreserveText' => array('Header', 'Footer', 'Cell'),
|
||||||
|
'Title' => array('Section'),
|
||||||
|
'TOC' => array('Section'),
|
||||||
|
'PageBreak' => array('Section'),
|
||||||
);
|
);
|
||||||
// Special condition, e.g. preservetext can only exists in cell when
|
// Special condition, e.g. preservetext can only exists in cell when
|
||||||
// the cell is located in header or footer
|
// the cell is located in header or footer
|
||||||
|
|
@ -284,24 +230,6 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return media element (image, object, link) container name
|
|
||||||
*
|
|
||||||
* @return string section|headerx|footerx|footnote|endnote
|
|
||||||
*/
|
|
||||||
private function getMediaContainer()
|
|
||||||
{
|
|
||||||
$partName = $this->container;
|
|
||||||
if (in_array($partName, array('Cell', 'TextRun', 'TextBox', 'ListItemRun'))) {
|
|
||||||
$partName = $this->getDocPart();
|
|
||||||
}
|
|
||||||
if ($partName == 'Header' || $partName == 'Footer') {
|
|
||||||
$partName .= $this->getDocPartId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtolower($partName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add memory image element
|
* Add memory image element
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Media;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
|
@ -42,7 +43,7 @@ abstract class AbstractElement
|
||||||
protected $sectionId;
|
protected $sectionId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document part type: section|header|footer
|
* Document part type: Section|Header|Footer|Footnote|Endnote
|
||||||
*
|
*
|
||||||
* Used by textrun and cell container to determine where the element is
|
* Used by textrun and cell container to determine where the element is
|
||||||
* located because it will affect the availability of other element,
|
* located because it will affect the availability of other element,
|
||||||
|
|
@ -93,6 +94,27 @@ abstract class AbstractElement
|
||||||
*/
|
*/
|
||||||
private $nestedLevel = 0;
|
private $nestedLevel = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent container type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $parentContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is part of collection; true for Title, Footnote, and Endnote
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get PhpWord
|
* Get PhpWord
|
||||||
*
|
*
|
||||||
|
|
@ -155,6 +177,21 @@ abstract class AbstractElement
|
||||||
return $this->docPartId;
|
return $this->docPartId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return media element (image, object, link) container name
|
||||||
|
*
|
||||||
|
* @return string section|headerx|footerx|footnote|endnote
|
||||||
|
*/
|
||||||
|
private function getMediaPart()
|
||||||
|
{
|
||||||
|
$mediaPart = $this->docPart;
|
||||||
|
if ($mediaPart == 'Header' || $mediaPart == 'Footer') {
|
||||||
|
$mediaPart .= $this->docPartId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strtolower($mediaPart);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get element index
|
* Get element index
|
||||||
*
|
*
|
||||||
|
|
@ -224,13 +261,74 @@ abstract class AbstractElement
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set nested level
|
* Set parent container
|
||||||
*
|
*
|
||||||
* @param int $value
|
* Passed parameter should be a container, except for Table (contain Row) and Row (contain Cell)
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\AbstractElement $container
|
||||||
*/
|
*/
|
||||||
public function setNestedLevel($value)
|
public function setParentContainer(AbstractElement $container)
|
||||||
{
|
{
|
||||||
$this->nestedLevel = $value;
|
$this->parentContainer = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
|
||||||
|
|
||||||
|
// Set nested level
|
||||||
|
$this->nestedLevel = $container->getNestedLevel();
|
||||||
|
if ($this->parentContainer == 'Cell') {
|
||||||
|
$this->nestedLevel++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set phpword
|
||||||
|
$phpWord = $container->getPhpWord();
|
||||||
|
$this->setPhpWord($phpWord);
|
||||||
|
|
||||||
|
// Set doc part
|
||||||
|
if (!$this instanceof Footnote) {
|
||||||
|
$this->setDocPart($container->getDocPart(), $container->getDocPartId());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setMediaRelation();
|
||||||
|
$this->setCollectionRelation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set relation Id for media elements (link, image, object; legacy of OOXML)
|
||||||
|
*
|
||||||
|
* - Image element needs to be passed to Media object
|
||||||
|
* - Icon needs to be set for Object element
|
||||||
|
*/
|
||||||
|
private function setMediaRelation()
|
||||||
|
{
|
||||||
|
if ($this->mediaRelation === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mediaPart = $this->getMediaPart();
|
||||||
|
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
|
||||||
|
|
||||||
|
/** @var \PhpOffice\PhpWord\Element\Image $this Type hint */
|
||||||
|
$source = $this->getSource();
|
||||||
|
$image = ($elementName == 'Image') ? $this : null;
|
||||||
|
$rId = Media::addElement($mediaPart, strtolower($elementName), $source, $image);
|
||||||
|
$this->setRelationId($rId);
|
||||||
|
|
||||||
|
if ($elementName == 'Object') {
|
||||||
|
/** @var \PhpOffice\PhpWord\Element\Object $this Type hint */
|
||||||
|
$rId = Media::addElement($mediaPart, 'image', $this->getIcon(), new Image($this->getIcon()));
|
||||||
|
$this->setImageRelationId($rId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set relation Id for elements that will be registered in the Collection subnamespaces
|
||||||
|
*/
|
||||||
|
private function setCollectionRelation()
|
||||||
|
{
|
||||||
|
if ($this->collectionRelation === true && $this->phpWord instanceof PhpWord) {
|
||||||
|
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
|
||||||
|
$addMethod = "add{$elementName}";
|
||||||
|
$rId = $this->phpWord->$addMethod($this);
|
||||||
|
$this->setRelationId($rId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,13 @@ class Footnote extends AbstractContainer
|
||||||
*/
|
*/
|
||||||
protected $paragraphStyle;
|
protected $paragraphStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is part of collection; true for Title, Footnote, and Endnote
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new instance
|
* Create new instance
|
||||||
*
|
*
|
||||||
|
|
@ -44,6 +51,7 @@ class Footnote extends AbstractContainer
|
||||||
public function __construct($paragraphStyle = null)
|
public function __construct($paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||||
|
$this->setDocPart($this->container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,13 @@ class Image extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private $mediaIndex;
|
private $mediaIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new image element
|
* Create new image element
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
class Link extends AbstractElement
|
class Link extends AbstractElement
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Link target
|
* Link source
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $target;
|
private $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link text
|
* Link text
|
||||||
|
|
@ -54,19 +54,25 @@ class Link extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private $paragraphStyle;
|
private $paragraphStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Link Element
|
* Create a new Link Element
|
||||||
*
|
*
|
||||||
* @param string $target
|
* @param string $source
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param mixed $fontStyle
|
* @param mixed $fontStyle
|
||||||
* @param mixed $paragraphStyle
|
* @param mixed $paragraphStyle
|
||||||
*/
|
*/
|
||||||
public function __construct($target, $text = null, $fontStyle = null, $paragraphStyle = null)
|
public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->target = String::toUTF8($target);
|
$this->source = String::toUTF8($source);
|
||||||
$this->text = is_null($text) ? $this->target : String::toUTF8($text);
|
$this->text = is_null($text) ? $this->source : String::toUTF8($text);
|
||||||
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
|
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||||
|
|
||||||
|
|
@ -74,13 +80,13 @@ class Link extends AbstractElement
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get link target
|
* Get link source
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTarget()
|
public function getSource()
|
||||||
{
|
{
|
||||||
return $this->target;
|
return $this->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,6 +119,18 @@ class Link extends AbstractElement
|
||||||
return $this->paragraphStyle;
|
return $this->paragraphStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get link target
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function getTarget()
|
||||||
|
{
|
||||||
|
return $this->source;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Link source
|
* Get Link source
|
||||||
*
|
*
|
||||||
|
|
@ -122,7 +140,7 @@ class Link extends AbstractElement
|
||||||
*/
|
*/
|
||||||
public function getLinkSrc()
|
public function getLinkSrc()
|
||||||
{
|
{
|
||||||
return $this->getTarget();
|
return $this->getSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,13 @@ class Object extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private $imageRelationId;
|
private $imageRelationId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Ole-Object Element
|
* Create a new Ole-Object Element
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,7 @@ class Row extends AbstractElement
|
||||||
public function addCell($width = null, $style = null)
|
public function addCell($width = null, $style = null)
|
||||||
{
|
{
|
||||||
$cell = new Cell($width, $style);
|
$cell = new Cell($width, $style);
|
||||||
$cell->setDocPart($this->getDocPart(), $this->getDocPartId());
|
$cell->setParentContainer($this);
|
||||||
$cell->setPhpWord($this->phpWord);
|
|
||||||
$cell->setNestedLevel($this->getNestedLevel());
|
|
||||||
$this->cells[] = $cell;
|
$this->cells[] = $cell;
|
||||||
|
|
||||||
return $cell;
|
return $cell;
|
||||||
|
|
|
||||||
|
|
@ -92,40 +92,6 @@ class Section extends AbstractContainer
|
||||||
return $this->settings;
|
return $this->settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a Title Element
|
|
||||||
*
|
|
||||||
* @param string $text
|
|
||||||
* @param int $depth
|
|
||||||
* @return \PhpOffice\PhpWord\Element\Title
|
|
||||||
*/
|
|
||||||
public function addTitle($text, $depth = 1)
|
|
||||||
{
|
|
||||||
return $this->addElement('Title', $text, $depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a PageBreak Element
|
|
||||||
*/
|
|
||||||
public function addPageBreak()
|
|
||||||
{
|
|
||||||
return $this->addElement('PageBreak');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a Table-of-Contents Element
|
|
||||||
*
|
|
||||||
* @param mixed $fontStyle
|
|
||||||
* @param mixed $tocStyle
|
|
||||||
* @param integer $minDepth
|
|
||||||
* @param integer $maxDepth
|
|
||||||
* @return \PhpOffice\PhpWord\Element\TOC
|
|
||||||
*/
|
|
||||||
public function addTOC($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
|
|
||||||
{
|
|
||||||
return $this->addElement('TOC', $fontStyle, $tocStyle, $minDepth, $maxDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add header
|
* Add header
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,7 @@ class Table extends AbstractElement
|
||||||
public function addRow($height = null, $style = null)
|
public function addRow($height = null, $style = null)
|
||||||
{
|
{
|
||||||
$row = new Row($height, $style);
|
$row = new Row($height, $style);
|
||||||
$row->setDocPart($this->getDocPart(), $this->getDocPartId());
|
$row->setParentContainer($this);
|
||||||
$row->setPhpWord($this->phpWord);
|
|
||||||
$row->setNestedLevel($this->getNestedLevel());
|
|
||||||
$this->rows[] = $row;
|
$this->rows[] = $row;
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,13 @@ class Title extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private $style;
|
private $style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is part of collection; true for Title, Footnote, and Endnote
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Title Element
|
* Create a new Title Element
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -483,8 +483,8 @@ abstract class AbstractPart
|
||||||
$style = true;
|
$style = true;
|
||||||
} elseif ($method == self::READ_FALSE) {
|
} elseif ($method == self::READ_FALSE) {
|
||||||
$style = false;
|
$style = false;
|
||||||
} elseif ($method == self::READ_EQUAL && $attributeValue == $expected) {
|
} elseif ($method == self::READ_EQUAL) {
|
||||||
$style = true;
|
$style = $attributeValue == $expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $style;
|
return $style;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class Link extends Text
|
||||||
|
|
||||||
$content = '';
|
$content = '';
|
||||||
$content .= $this->writeOpening();
|
$content .= $this->writeOpening();
|
||||||
$content .= "<a href=\"{$this->element->getTarget()}\">{$this->element->getText()}</a>";
|
$content .= "<a href=\"{$this->element->getSource()}\">{$this->element->getText()}</a>";
|
||||||
$content .= $this->writeClosing();
|
$content .= $this->writeClosing();
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class Link extends AbstractElement
|
||||||
|
|
||||||
$xmlWriter->startElement('text:a');
|
$xmlWriter->startElement('text:a');
|
||||||
$xmlWriter->writeAttribute('xlink:type', 'simple');
|
$xmlWriter->writeAttribute('xlink:type', 'simple');
|
||||||
$xmlWriter->writeAttribute('xlink:href', $element->getTarget());
|
$xmlWriter->writeAttribute('xlink:href', $element->getSource());
|
||||||
$xmlWriter->writeRaw($element->getText());
|
$xmlWriter->writeRaw($element->getText());
|
||||||
$xmlWriter->endElement(); // text:a
|
$xmlWriter->endElement(); // text:a
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class Link extends AbstractElement
|
||||||
|
|
||||||
$content = '';
|
$content = '';
|
||||||
$content .= $this->writeOpening();
|
$content .= $this->writeOpening();
|
||||||
$content .= '{\field {\*\fldinst {HYPERLINK "' . $this->element->getTarget() . '"}}{\\fldrslt {';
|
$content .= '{\field {\*\fldinst {HYPERLINK "' . $this->element->getSource() . '"}}{\\fldrslt {';
|
||||||
$content .= $this->writeFontStyle();
|
$content .= $this->writeFontStyle();
|
||||||
$content .= $this->writeText($this->element->getText());
|
$content .= $this->writeText($this->element->getText());
|
||||||
$content .= '}}}';
|
$content .= '}}}';
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,10 @@ class Font extends AbstractStyle
|
||||||
$xmlWriter->startElement('w:rPr');
|
$xmlWriter->startElement('w:rPr');
|
||||||
|
|
||||||
// Style name
|
// Style name
|
||||||
$styleName = $style->getStyleName();
|
if ($this->isInline === true) {
|
||||||
$xmlWriter->writeElementIf(!is_null($styleName), 'w:rStyle', 'w:val', $styleName);
|
$styleName = $style->getStyleName();
|
||||||
|
$xmlWriter->writeElementIf($styleName !== null, 'w:rStyle', 'w:val', $styleName);
|
||||||
|
}
|
||||||
|
|
||||||
// Font name/family
|
// Font name/family
|
||||||
$font = $style->getName();
|
$font = $style->getName();
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,9 @@ class Paragraph extends AbstractStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
// Style name
|
// Style name
|
||||||
$xmlWriter->writeElementIf($styles['name'] !== null, 'w:pStyle', 'w:val', $styles['name']);
|
if ($this->isInline === true) {
|
||||||
|
$xmlWriter->writeElementIf($styles['name'] !== null, 'w:pStyle', 'w:val', $styles['name']);
|
||||||
|
}
|
||||||
|
|
||||||
// Alignment
|
// Alignment
|
||||||
$styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $styles['alignment'])));
|
$styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $styles['alignment'])));
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
||||||
$oLink = new Link('http://www.google.com');
|
$oLink = new Link('http://www.google.com');
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
|
||||||
$this->assertEquals($oLink->getTarget(), 'http://www.google.com');
|
$this->assertEquals($oLink->getSource(), 'http://www.google.com');
|
||||||
$this->assertEquals($oLink->getText(), $oLink->getTarget());
|
$this->assertEquals($oLink->getText(), $oLink->getSource());
|
||||||
$this->assertEquals($oLink->getFontStyle(), null);
|
$this->assertEquals($oLink->getFontStyle(), null);
|
||||||
$this->assertEquals($oLink->getParagraphStyle(), null);
|
$this->assertEquals($oLink->getParagraphStyle(), null);
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +55,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
|
||||||
$this->assertEquals($oLink->getTarget(), 'http://www.google.com');
|
$this->assertEquals($oLink->getSource(), 'http://www.google.com');
|
||||||
$this->assertEquals($oLink->getText(), 'Search Engine');
|
$this->assertEquals($oLink->getText(), 'Search Engine');
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle());
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
||||||
$this->assertCount(1, $oListItemRun->getElements());
|
$this->assertCount(1, $oListItemRun->getElements());
|
||||||
$this->assertEquals($element->getTarget(), 'http://www.google.fr');
|
$this->assertEquals($element->getSource(), 'http://www.google.fr');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -144,7 +144,7 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
||||||
$this->assertCount(1, $oListItemRun->getElements());
|
$this->assertCount(1, $oListItemRun->getElements());
|
||||||
$this->assertEquals($element->getTarget(), 'http://www.google.fr');
|
$this->assertEquals($element->getSource(), 'http://www.google.fr');
|
||||||
$this->assertEquals($element->getText(), 'ééé');
|
$this->assertEquals($element->getText(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
||||||
$this->assertCount(1, $oTextRun->getElements());
|
$this->assertCount(1, $oTextRun->getElements());
|
||||||
$this->assertEquals($element->getTarget(), 'http://www.google.fr');
|
$this->assertEquals($element->getSource(), 'http://www.google.fr');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,7 +112,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
|
||||||
$this->assertCount(1, $oTextRun->getElements());
|
$this->assertCount(1, $oTextRun->getElements());
|
||||||
$this->assertEquals($element->getTarget(), 'http://www.google.fr');
|
$this->assertEquals($element->getSource(), 'http://www.google.fr');
|
||||||
$this->assertEquals($element->getText(), 'ééé');
|
$this->assertEquals($element->getText(), 'ééé');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals('portrait', $oSettings->getOrientation());
|
$this->assertEquals('portrait', $oSettings->getOrientation());
|
||||||
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW());
|
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW());
|
||||||
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH());
|
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH());
|
||||||
|
$this->assertEquals('A4', $oSettings->getPaperSize());
|
||||||
|
|
||||||
$oSettings->setSettingValue('orientation', 'landscape');
|
$oSettings->setSettingValue('orientation', 'landscape');
|
||||||
$this->assertEquals('landscape', $oSettings->getOrientation());
|
$this->assertEquals('landscape', $oSettings->getOrientation());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue