Create new Element abstract class
This commit is contained in:
parent
04e6dbc86a
commit
637c9fce6f
|
|
@ -33,6 +33,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
||||||
- `createHeader` replaced by `addHeader`
|
- `createHeader` replaced by `addHeader`
|
||||||
- `createFooter` replaced by `addFooter`
|
- `createFooter` replaced by `addFooter`
|
||||||
- `createSection` replaced by `addSection`
|
- `createSection` replaced by `addSection`
|
||||||
|
- `Element\Footnote::getReferenceId` replaced by `Container\Container::getRelationId`
|
||||||
|
- `Element\Footnote::setReferenceId` replaced by `Container\Container::setRelationId`
|
||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
|
|
@ -40,8 +42,9 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
||||||
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
|
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
|
||||||
- Reader: Rename AbstractReader > Reader - @ivanlanin
|
- Reader: Rename AbstractReader > Reader - @ivanlanin
|
||||||
- General: Refactor folders: Element, Container, and Exception - @ivanlanin GH-187
|
- General: Refactor folders: Element, Container, and Exception - @ivanlanin GH-187
|
||||||
- Container: Create new Container abstract class - @ivanlanin GH-187
|
|
||||||
- General: Remove legacy HashTable and all related properties/methods - @ivanlanin GH-187
|
- General: Remove legacy HashTable and all related properties/methods - @ivanlanin GH-187
|
||||||
|
- Container: Create new Container abstract class - @ivanlanin GH-187
|
||||||
|
- Element: Create new Element abstract class - @ivanlanin GH-187
|
||||||
|
|
||||||
## 0.9.1 - 27 Mar 2014
|
## 0.9.1 - 27 Mar 2014
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -385,7 +385,7 @@ abstract class Container
|
||||||
|
|
||||||
$footnote = new FootnoteElement($paragraphStyle);
|
$footnote = new FootnoteElement($paragraphStyle);
|
||||||
$refID = FootnoteCollection::addFootnoteElement($footnote);
|
$refID = FootnoteCollection::addFootnoteElement($footnote);
|
||||||
$footnote->setReferenceId($refID);
|
$footnote->setRelationId($refID);
|
||||||
$this->elements[] = $footnote;
|
$this->elements[] = $footnote;
|
||||||
|
|
||||||
return $footnote;
|
return $footnote;
|
||||||
|
|
@ -487,6 +487,33 @@ abstract class Container
|
||||||
return $this->addFootnote($paragraphStyle);
|
return $this->addFootnote($paragraphStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*
|
||||||
|
* Used by Footnote
|
||||||
|
*
|
||||||
|
* @param mixed $styleObject Style object, could be Font, Paragraph, Cell, Image
|
||||||
|
* @param mixed $styleValue
|
||||||
|
* @param boolean $returnObject Always return object
|
||||||
|
* @todo Remove duplicate with ..\Element\Element
|
||||||
|
*/
|
||||||
|
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
|
||||||
|
{
|
||||||
|
if (!is_null($styleValue) && is_array($styleValue)) {
|
||||||
|
foreach ($styleValue as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$styleObject->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
$style = $styleObject;
|
||||||
|
} else {
|
||||||
|
$style = $returnObject ? $styleObject : $styleValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $style;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a method is allowed for the current container
|
* Check if a method is allowed for the current container
|
||||||
*
|
*
|
||||||
|
|
@ -507,7 +534,7 @@ abstract class Container
|
||||||
'object' => array('section', 'textrun', 'cell', 'footnote'),
|
'object' => array('section', 'textrun', 'cell', 'footnote'),
|
||||||
'footnote' => array('section', 'textrun', 'cell'),
|
'footnote' => array('section', 'textrun', 'cell'),
|
||||||
'preservetext' => array('header', 'footer', 'cell'),
|
'preservetext' => array('header', 'footer', 'cell'),
|
||||||
'relationid' => array('header', 'footer'),
|
'relationid' => array('header', 'footer', 'footnote'),
|
||||||
'title' => array('section'),
|
'title' => array('section'),
|
||||||
);
|
);
|
||||||
$validContainerInContainers = array(
|
$validContainerInContainers = array(
|
||||||
|
|
|
||||||
|
|
@ -45,20 +45,7 @@ class Cell extends Container
|
||||||
$this->docPart = $docPart;
|
$this->docPart = $docPart;
|
||||||
$this->docPartId = $docPartId;
|
$this->docPartId = $docPartId;
|
||||||
$this->width = $width;
|
$this->width = $width;
|
||||||
$this->cellStyle = new CellStyle();
|
$this->cellStyle = $this->setStyle(new CellStyle(), $style, true);
|
||||||
|
|
||||||
if (!is_null($style)) {
|
|
||||||
if (is_array($style)) {
|
|
||||||
foreach ($style as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->cellStyle->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->cellStyle = $style;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
/**
|
/**
|
||||||
* Check box element
|
* Check box element
|
||||||
*/
|
*/
|
||||||
class CheckBox
|
class CheckBox extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Name content
|
* Name content
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHPWord
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2014 PHPWord
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract element class
|
||||||
|
*
|
||||||
|
* @since 0.9.2
|
||||||
|
*/
|
||||||
|
abstract class Element
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Set style value
|
||||||
|
*
|
||||||
|
* @param mixed $styleObject Style object
|
||||||
|
* @param mixed $styleValue Style value
|
||||||
|
* @param boolean $returnObject Always return object
|
||||||
|
*/
|
||||||
|
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
|
||||||
|
{
|
||||||
|
if (!is_null($styleValue) && is_array($styleValue)) {
|
||||||
|
foreach ($styleValue as $key => $value) {
|
||||||
|
if (substr($key, 0, 1) != '_') {
|
||||||
|
$key = '_' . $key;
|
||||||
|
}
|
||||||
|
$styleObject->setStyleValue($key, $value);
|
||||||
|
}
|
||||||
|
$style = $styleObject;
|
||||||
|
} else {
|
||||||
|
$style = $returnObject ? $styleObject : $styleValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,13 +24,6 @@ class Footnote extends Container
|
||||||
*/
|
*/
|
||||||
private $paragraphStyle;
|
private $paragraphStyle;
|
||||||
|
|
||||||
/**
|
|
||||||
* Footnote Reference ID
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $referenceId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new instance
|
* Create new instance
|
||||||
*
|
*
|
||||||
|
|
@ -39,18 +32,7 @@ class Footnote extends Container
|
||||||
public function __construct($paragraphStyle = null)
|
public function __construct($paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->container = 'footnote';
|
$this->container = 'footnote';
|
||||||
// Set paragraph style
|
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||||
if (is_array($paragraphStyle)) {
|
|
||||||
$this->paragraphStyle = new Paragraph();
|
|
||||||
foreach ($paragraphStyle as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->paragraphStyle->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->paragraphStyle = $paragraphStyle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,19 +49,21 @@ class Footnote extends Container
|
||||||
* Get Footnote Reference ID
|
* Get Footnote Reference ID
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
|
* @deprecated 0.9.2
|
||||||
*/
|
*/
|
||||||
public function getReferenceId()
|
public function getReferenceId()
|
||||||
{
|
{
|
||||||
return $this->referenceId;
|
return $this->getRelationId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Footnote Reference ID
|
* Set Footnote Reference ID
|
||||||
*
|
*
|
||||||
* @param int $refId
|
* @param int $refId
|
||||||
|
* @deprecated 0.9.2
|
||||||
*/
|
*/
|
||||||
public function setReferenceId($refId)
|
public function setReferenceId($refId)
|
||||||
{
|
{
|
||||||
$this->referenceId = $refId;
|
$this->setRelationId($refId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,12 @@ namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
||||||
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
||||||
|
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image element
|
* Image element
|
||||||
*/
|
*/
|
||||||
class Image
|
class Image extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Image source
|
* Image source
|
||||||
|
|
@ -27,7 +28,7 @@ class Image
|
||||||
/**
|
/**
|
||||||
* Image style
|
* Image style
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Image
|
* @var ImageStyle
|
||||||
*/
|
*/
|
||||||
private $style;
|
private $style;
|
||||||
|
|
||||||
|
|
@ -131,15 +132,7 @@ class Image
|
||||||
// Set private properties
|
// Set private properties
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
$this->isWatermark = $isWatermark;
|
$this->isWatermark = $isWatermark;
|
||||||
$this->style = new \PhpOffice\PhpWord\Style\Image();
|
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
||||||
if (!is_null($style) && is_array($style)) {
|
|
||||||
foreach ($style as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->style->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($style['wrappingStyle'])) {
|
if (isset($style['wrappingStyle'])) {
|
||||||
$this->style->setWrappingStyle($style['wrappingStyle']);
|
$this->style->setWrappingStyle($style['wrappingStyle']);
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +146,7 @@ class Image
|
||||||
/**
|
/**
|
||||||
* Get Image style
|
* Get Image style
|
||||||
*
|
*
|
||||||
* @return \PhpOffice\PhpWord\Style\Image
|
* @return ImageStyle
|
||||||
*/
|
*/
|
||||||
public function getStyle()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,42 +15,42 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
/**
|
/**
|
||||||
* Link element
|
* Link element
|
||||||
*/
|
*/
|
||||||
class Link
|
class Link extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Link source
|
* Link source
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_linkSrc;
|
private $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link name
|
* Link name
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_linkName;
|
private $name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link Relation ID
|
* Link Relation ID
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_rId;
|
private $relationId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link style
|
* Font style
|
||||||
*
|
*
|
||||||
* @var string|Font
|
* @var string|Font
|
||||||
*/
|
*/
|
||||||
private $_styleFont;
|
private $fontStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paragraph style
|
* Paragraph style
|
||||||
*
|
*
|
||||||
* @var string|Paragraph
|
* @var string|Paragraph
|
||||||
*/
|
*/
|
||||||
private $_styleParagraph;
|
private $paragraphStyle;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,41 +58,15 @@ class Link
|
||||||
*
|
*
|
||||||
* @param string $linkSrc
|
* @param string $linkSrc
|
||||||
* @param string $linkName
|
* @param string $linkName
|
||||||
* @param mixed $styleFont
|
* @param mixed $fontStyle
|
||||||
* @param mixed $styleParagraph
|
* @param mixed $paragraphStyle
|
||||||
*/
|
*/
|
||||||
public function __construct($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
|
public function __construct($linkSrc, $linkName = null, $fontStyle = null, $paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->_linkSrc = $linkSrc;
|
$this->source = $linkSrc;
|
||||||
$this->_linkName = $linkName;
|
$this->name = $linkName;
|
||||||
|
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
|
||||||
// Set font style
|
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||||
if (is_array($styleFont)) {
|
|
||||||
$this->_styleFont = new Font('text');
|
|
||||||
|
|
||||||
foreach ($styleFont as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_styleFont->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->_styleFont = $styleFont;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set paragraph style
|
|
||||||
if (is_array($styleParagraph)) {
|
|
||||||
$this->_styleParagraph = new Paragraph();
|
|
||||||
|
|
||||||
foreach ($styleParagraph as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_styleParagraph->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->_styleParagraph = $styleParagraph;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +78,7 @@ class Link
|
||||||
*/
|
*/
|
||||||
public function getRelationId()
|
public function getRelationId()
|
||||||
{
|
{
|
||||||
return $this->_rId;
|
return $this->relationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -114,7 +88,7 @@ class Link
|
||||||
*/
|
*/
|
||||||
public function setRelationId($rId)
|
public function setRelationId($rId)
|
||||||
{
|
{
|
||||||
$this->_rId = $rId;
|
$this->relationId = $rId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -124,7 +98,7 @@ class Link
|
||||||
*/
|
*/
|
||||||
public function getLinkSrc()
|
public function getLinkSrc()
|
||||||
{
|
{
|
||||||
return $this->_linkSrc;
|
return $this->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -134,7 +108,7 @@ class Link
|
||||||
*/
|
*/
|
||||||
public function getLinkName()
|
public function getLinkName()
|
||||||
{
|
{
|
||||||
return $this->_linkName;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -144,7 +118,7 @@ class Link
|
||||||
*/
|
*/
|
||||||
public function getFontStyle()
|
public function getFontStyle()
|
||||||
{
|
{
|
||||||
return $this->_styleFont;
|
return $this->fontStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -154,6 +128,6 @@ class Link
|
||||||
*/
|
*/
|
||||||
public function getParagraphStyle()
|
public function getParagraphStyle()
|
||||||
{
|
{
|
||||||
return $this->_styleParagraph;
|
return $this->paragraphStyle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,31 +9,33 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List item element
|
* List item element
|
||||||
*/
|
*/
|
||||||
class ListItem
|
class ListItem extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* ListItem Style
|
* ListItem Style
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\ListItem
|
* @var ListItemStyle
|
||||||
*/
|
*/
|
||||||
private $_style;
|
private $style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Textrun
|
* Textrun
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Element\Text
|
* @var \PhpOffice\PhpWord\Element\Text
|
||||||
*/
|
*/
|
||||||
private $_textObject;
|
private $textObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ListItem Depth
|
* ListItem Depth
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_depth;
|
private $depth;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,18 +49,9 @@ class ListItem
|
||||||
*/
|
*/
|
||||||
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
|
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
|
||||||
{
|
{
|
||||||
$this->_style = new \PhpOffice\PhpWord\Style\ListItem();
|
$this->textObject = new Text($text, $styleFont, $styleParagraph);
|
||||||
$this->_textObject = new Text($text, $styleFont, $styleParagraph);
|
$this->depth = $depth;
|
||||||
$this->_depth = $depth;
|
$this->style = $this->setStyle(new ListItemStyle(), $styleList, true);
|
||||||
|
|
||||||
if (!is_null($styleList) && is_array($styleList)) {
|
|
||||||
foreach ($styleList as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_style->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,7 +59,7 @@ class ListItem
|
||||||
*/
|
*/
|
||||||
public function getStyle()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
return $this->_style;
|
return $this->style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -74,7 +67,7 @@ class ListItem
|
||||||
*/
|
*/
|
||||||
public function getTextObject()
|
public function getTextObject()
|
||||||
{
|
{
|
||||||
return $this->_textObject;
|
return $this->textObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -82,6 +75,6 @@ class ListItem
|
||||||
*/
|
*/
|
||||||
public function getDepth()
|
public function getDepth()
|
||||||
{
|
{
|
||||||
return $this->_depth;
|
return $this->depth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,45 +9,47 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object element
|
* Object element
|
||||||
*/
|
*/
|
||||||
class Object
|
class Object extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Ole-Object Src
|
* Ole-Object Src
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_src;
|
private $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image Style
|
* Image Style
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Image
|
* @var \PhpOffice\PhpWord\Style\Image
|
||||||
*/
|
*/
|
||||||
private $_style;
|
private $style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object Relation ID
|
* Object Relation ID
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_rId;
|
private $relationId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image Relation ID
|
* Image Relation ID
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_rIdImg;
|
private $imageRelationId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object ID
|
* Object ID
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_objId;
|
private $objectId;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,22 +60,12 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function __construct($src, $style = null)
|
public function __construct($src, $style = null)
|
||||||
{
|
{
|
||||||
$_supportedObjectTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
|
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
|
||||||
$inf = pathinfo($src);
|
$inf = pathinfo($src);
|
||||||
|
|
||||||
if (\file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
|
if (\file_exists($src) && in_array($inf['extension'], $supportedTypes)) {
|
||||||
$this->_src = $src;
|
$this->source = $src;
|
||||||
$this->_style = new \PhpOffice\PhpWord\Style\Image();
|
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
||||||
|
|
||||||
if (!is_null($style) && is_array($style)) {
|
|
||||||
foreach ($style as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_style->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -87,7 +79,7 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function getStyle()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
return $this->_style;
|
return $this->style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -97,7 +89,7 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function getSource()
|
public function getSource()
|
||||||
{
|
{
|
||||||
return $this->_src;
|
return $this->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -107,7 +99,7 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function getRelationId()
|
public function getRelationId()
|
||||||
{
|
{
|
||||||
return $this->_rId;
|
return $this->relationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -117,7 +109,7 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function setRelationId($rId)
|
public function setRelationId($rId)
|
||||||
{
|
{
|
||||||
$this->_rId = $rId;
|
$this->relationId = $rId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,7 +119,7 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function getImageRelationId()
|
public function getImageRelationId()
|
||||||
{
|
{
|
||||||
return $this->_rIdImg;
|
return $this->imageRelationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -137,7 +129,7 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function setImageRelationId($rId)
|
public function setImageRelationId($rId)
|
||||||
{
|
{
|
||||||
$this->_rIdImg = $rId;
|
$this->imageRelationId = $rId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -147,7 +139,7 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function getObjectId()
|
public function getObjectId()
|
||||||
{
|
{
|
||||||
return $this->_objId;
|
return $this->objectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -157,6 +149,6 @@ class Object
|
||||||
*/
|
*/
|
||||||
public function setObjectId($objId)
|
public function setObjectId($objId)
|
||||||
{
|
{
|
||||||
$this->_objId = $objId;
|
$this->objectId = $objId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Element;
|
||||||
/**
|
/**
|
||||||
* Page break element
|
* Page break element
|
||||||
*/
|
*/
|
||||||
class PageBreak
|
class PageBreak extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create new page break
|
* Create new page break
|
||||||
|
|
|
||||||
|
|
@ -15,28 +15,28 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
/**
|
/**
|
||||||
* Preserve text/field element
|
* Preserve text/field element
|
||||||
*/
|
*/
|
||||||
class PreserveText
|
class PreserveText extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Text content
|
* Text content
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_text;
|
private $text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text style
|
* Text style
|
||||||
*
|
*
|
||||||
* @var string|Font
|
* @var string|Font
|
||||||
*/
|
*/
|
||||||
private $_styleFont;
|
private $fontStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paragraph style
|
* Paragraph style
|
||||||
*
|
*
|
||||||
* @var string|Paragraph
|
* @var string|Paragraph
|
||||||
*/
|
*/
|
||||||
private $_styleParagraph;
|
private $paragraphStyle;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,37 +49,12 @@ class PreserveText
|
||||||
*/
|
*/
|
||||||
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
|
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
|
||||||
{
|
{
|
||||||
// Set font style
|
$this->fontStyle = $this->setStyle(new Font('text'), $styleFont);
|
||||||
if (is_array($styleFont)) {
|
$this->paragraphStyle = $this->setStyle(new Paragraph(), $styleParagraph);
|
||||||
$this->_styleFont = new Font('text');
|
|
||||||
|
|
||||||
foreach ($styleFont as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_styleFont->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->_styleFont = $styleFont;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set paragraph style
|
|
||||||
if (is_array($styleParagraph)) {
|
|
||||||
$this->_styleParagraph = new Paragraph();
|
|
||||||
|
|
||||||
foreach ($styleParagraph as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_styleParagraph->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->_styleParagraph = $styleParagraph;
|
|
||||||
}
|
|
||||||
|
|
||||||
$matches = preg_split('/({.*?})/', $text, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
|
$matches = preg_split('/({.*?})/', $text, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
|
||||||
if (isset($matches[0])) {
|
if (isset($matches[0])) {
|
||||||
$this->_text = $matches;
|
$this->text = $matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -92,7 +67,7 @@ class PreserveText
|
||||||
*/
|
*/
|
||||||
public function getFontStyle()
|
public function getFontStyle()
|
||||||
{
|
{
|
||||||
return $this->_styleFont;
|
return $this->fontStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -102,7 +77,7 @@ class PreserveText
|
||||||
*/
|
*/
|
||||||
public function getParagraphStyle()
|
public function getParagraphStyle()
|
||||||
{
|
{
|
||||||
return $this->_styleParagraph;
|
return $this->paragraphStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,6 +87,6 @@ class PreserveText
|
||||||
*/
|
*/
|
||||||
public function getText()
|
public function getText()
|
||||||
{
|
{
|
||||||
return $this->_text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,73 +9,63 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Row as RowStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table row element
|
* Table row element
|
||||||
*/
|
*/
|
||||||
class Row
|
class Row extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Row height
|
* Row height
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_height = null;
|
private $height = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Row style
|
* Row style
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Row
|
* @var RowStyle
|
||||||
*/
|
*/
|
||||||
private $_style;
|
private $style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Row cells
|
* Row cells
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $_cells = array();
|
private $cells = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table holder
|
* Table holder
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_insideOf;
|
private $docPart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Section/Header/Footer count
|
* Section/Header/Footer count
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_pCount;
|
private $docPartId;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new table row
|
* Create a new table row
|
||||||
*
|
*
|
||||||
* @param string $insideOf
|
* @param string $docPart
|
||||||
* @param int $pCount
|
* @param int $docPartId
|
||||||
* @param int $height
|
* @param int $height
|
||||||
* @param mixed $style
|
* @param mixed $style
|
||||||
*/
|
*/
|
||||||
public function __construct($insideOf, $pCount, $height = null, $style = null)
|
public function __construct($docPart, $docPartId, $height = null, $style = null)
|
||||||
{
|
{
|
||||||
$this->_insideOf = $insideOf;
|
$this->docPart = $docPart;
|
||||||
$this->_pCount = $pCount;
|
$this->docPartId = $docPartId;
|
||||||
$this->_height = $height;
|
$this->height = $height;
|
||||||
$this->_style = new \PhpOffice\PhpWord\Style\Row();
|
$this->style = $this->setStyle(new RowStyle(), $style, true);
|
||||||
|
|
||||||
if (!is_null($style)) {
|
|
||||||
if (is_array($style)) {
|
|
||||||
|
|
||||||
foreach ($style as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_style->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -83,12 +73,11 @@ class Row
|
||||||
*
|
*
|
||||||
* @param int $width
|
* @param int $width
|
||||||
* @param mixed $style
|
* @param mixed $style
|
||||||
* @return \PhpOffice\PhpWord\Element\Cell
|
|
||||||
*/
|
*/
|
||||||
public function addCell($width = null, $style = null)
|
public function addCell($width = null, $style = null)
|
||||||
{
|
{
|
||||||
$cell = new Cell($this->_insideOf, $this->_pCount, $width, $style);
|
$cell = new Cell($this->docPart, $this->docPartId, $width, $style);
|
||||||
$this->_cells[] = $cell;
|
$this->cells[] = $cell;
|
||||||
return $cell;
|
return $cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,17 +88,17 @@ class Row
|
||||||
*/
|
*/
|
||||||
public function getCells()
|
public function getCells()
|
||||||
{
|
{
|
||||||
return $this->_cells;
|
return $this->cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get row style
|
* Get row style
|
||||||
*
|
*
|
||||||
* @return \PhpOffice\PhpWord\Style\Row
|
* @return RowStyle
|
||||||
*/
|
*/
|
||||||
public function getStyle()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
return $this->_style;
|
return $this->style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -119,6 +108,6 @@ class Row
|
||||||
*/
|
*/
|
||||||
public function getHeight()
|
public function getHeight()
|
||||||
{
|
{
|
||||||
return $this->_height;
|
return $this->height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,74 +10,60 @@
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Element\Row;
|
use PhpOffice\PhpWord\Element\Row;
|
||||||
|
use PhpOffice\PhpWord\Style\Table as TableStyle;
|
||||||
/**
|
/**
|
||||||
* Table element
|
* Table element
|
||||||
*/
|
*/
|
||||||
class Table
|
class Table extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Table style
|
* Table style
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Table
|
* @var TableStyle
|
||||||
*/
|
*/
|
||||||
private $_style;
|
private $style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table rows
|
* Table rows
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $_rows = array();
|
private $rows = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table holder
|
* Table holder
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_insideOf = null;
|
private $docPart = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table holder count
|
* Table holder count
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $_pCount;
|
private $docPartId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table width
|
* Table width
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_width = null;
|
private $width = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new table
|
* Create a new table
|
||||||
*
|
*
|
||||||
* @param string $insideOf
|
* @param string $docPart
|
||||||
* @param int $pCount
|
* @param int $docPartId
|
||||||
* @param mixed $style
|
* @param mixed $style
|
||||||
*/
|
*/
|
||||||
public function __construct($insideOf, $pCount, $style = null)
|
public function __construct($docPart, $docPartId, $style = null)
|
||||||
{
|
{
|
||||||
$this->_insideOf = $insideOf;
|
$this->docPart = $docPart;
|
||||||
$this->_pCount = $pCount;
|
$this->docPartId = $docPartId;
|
||||||
|
$this->style = $this->setStyle(new TableStyle(), $style);
|
||||||
if (!is_null($style)) {
|
|
||||||
if (is_array($style)) {
|
|
||||||
$this->_style = new \PhpOffice\PhpWord\Style\Table();
|
|
||||||
|
|
||||||
foreach ($style as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->_style->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->_style = $style;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -88,8 +74,8 @@ class Table
|
||||||
*/
|
*/
|
||||||
public function addRow($height = null, $style = null)
|
public function addRow($height = null, $style = null)
|
||||||
{
|
{
|
||||||
$row = new Row($this->_insideOf, $this->_pCount, $height, $style);
|
$row = new Row($this->docPart, $this->docPartId, $height, $style);
|
||||||
$this->_rows[] = $row;
|
$this->rows[] = $row;
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,8 +88,8 @@ class Table
|
||||||
*/
|
*/
|
||||||
public function addCell($width = null, $style = null)
|
public function addCell($width = null, $style = null)
|
||||||
{
|
{
|
||||||
$i = count($this->_rows) - 1;
|
$i = count($this->rows) - 1;
|
||||||
$cell = $this->_rows[$i]->addCell($width, $style);
|
$cell = $this->rows[$i]->addCell($width, $style);
|
||||||
return $cell;
|
return $cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,17 +100,17 @@ class Table
|
||||||
*/
|
*/
|
||||||
public function getRows()
|
public function getRows()
|
||||||
{
|
{
|
||||||
return $this->_rows;
|
return $this->rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get table style
|
* Get table style
|
||||||
*
|
*
|
||||||
* @return \PhpOffice\PhpWord\Style\Table
|
* @return TableStyle
|
||||||
*/
|
*/
|
||||||
public function getStyle()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
return $this->_style;
|
return $this->style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -134,7 +120,7 @@ class Table
|
||||||
*/
|
*/
|
||||||
public function setWidth($width)
|
public function setWidth($width)
|
||||||
{
|
{
|
||||||
$this->_width = $width;
|
$this->width = $width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -144,6 +130,6 @@ class Table
|
||||||
*/
|
*/
|
||||||
public function getWidth()
|
public function getWidth()
|
||||||
{
|
{
|
||||||
return $this->_width;
|
return $this->width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
/**
|
/**
|
||||||
* Text element
|
* Text element
|
||||||
*/
|
*/
|
||||||
class Text
|
class Text extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Text content
|
* Text content
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
/**
|
/**
|
||||||
* Text break element
|
* Text break element
|
||||||
*/
|
*/
|
||||||
class TextBreak
|
class TextBreak extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Paragraph style
|
* Paragraph style
|
||||||
|
|
|
||||||
|
|
@ -36,18 +36,7 @@ class TextRun extends Container
|
||||||
$this->container = 'textrun';
|
$this->container = 'textrun';
|
||||||
$this->docPart = $docPart;
|
$this->docPart = $docPart;
|
||||||
$this->docPartId = $docPartId;
|
$this->docPartId = $docPartId;
|
||||||
// Set paragraph style
|
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
||||||
if (is_array($paragraphStyle)) {
|
|
||||||
$this->paragraphStyle = new Paragraph();
|
|
||||||
foreach ($paragraphStyle as $key => $value) {
|
|
||||||
if (substr($key, 0, 1) != '_') {
|
|
||||||
$key = '_' . $key;
|
|
||||||
}
|
|
||||||
$this->paragraphStyle->setStyleValue($key, $value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->paragraphStyle = $paragraphStyle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -12,42 +12,42 @@ namespace PhpOffice\PhpWord\Element;
|
||||||
/**
|
/**
|
||||||
* Title element
|
* Title element
|
||||||
*/
|
*/
|
||||||
class Title
|
class Title extends Element
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Title Text content
|
* Title Text content
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_text;
|
private $text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title depth
|
* Title depth
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_depth;
|
private $depth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title anchor
|
* Title anchor
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_anchor;
|
private $anchor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title Bookmark ID
|
* Title Bookmark ID
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $_bookmarkId;
|
private $bookmarkId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title style
|
* Title style
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $_style;
|
private $style;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,11 +60,11 @@ class Title
|
||||||
public function __construct($text, $depth = 1, $style = null)
|
public function __construct($text, $depth = 1, $style = null)
|
||||||
{
|
{
|
||||||
if (!is_null($style)) {
|
if (!is_null($style)) {
|
||||||
$this->_style = $style;
|
$this->style = $style;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_text = $text;
|
$this->text = $text;
|
||||||
$this->_depth = $depth;
|
$this->depth = $depth;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ class Title
|
||||||
*/
|
*/
|
||||||
public function setAnchor($anchor)
|
public function setAnchor($anchor)
|
||||||
{
|
{
|
||||||
$this->_anchor = $anchor;
|
$this->anchor = $anchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -86,7 +86,7 @@ class Title
|
||||||
*/
|
*/
|
||||||
public function getAnchor()
|
public function getAnchor()
|
||||||
{
|
{
|
||||||
return $this->_anchor;
|
return $this->anchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -96,7 +96,7 @@ class Title
|
||||||
*/
|
*/
|
||||||
public function setBookmarkId($bookmarkId)
|
public function setBookmarkId($bookmarkId)
|
||||||
{
|
{
|
||||||
$this->_bookmarkId = $bookmarkId;
|
$this->bookmarkId = $bookmarkId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,7 +106,7 @@ class Title
|
||||||
*/
|
*/
|
||||||
public function getBookmarkId()
|
public function getBookmarkId()
|
||||||
{
|
{
|
||||||
return $this->_bookmarkId;
|
return $this->bookmarkId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -116,7 +116,7 @@ class Title
|
||||||
*/
|
*/
|
||||||
public function getText()
|
public function getText()
|
||||||
{
|
{
|
||||||
return $this->_text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -126,6 +126,6 @@ class Title
|
||||||
*/
|
*/
|
||||||
public function getStyle()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
return $this->_style;
|
return $this->style;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -614,7 +614,7 @@ class Base extends WriterPart
|
||||||
$xmlWriter->endElement(); // w:rStyle
|
$xmlWriter->endElement(); // w:rStyle
|
||||||
$xmlWriter->endElement(); // w:rPr
|
$xmlWriter->endElement(); // w:rPr
|
||||||
$xmlWriter->startElement('w:footnoteReference');
|
$xmlWriter->startElement('w:footnoteReference');
|
||||||
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
|
$xmlWriter->writeAttribute('w:id', $footnote->getRelationId());
|
||||||
$xmlWriter->endElement(); // w:footnoteReference
|
$xmlWriter->endElement(); // w:footnoteReference
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
if (!$withoutP) {
|
if (!$withoutP) {
|
||||||
|
|
@ -1173,13 +1173,16 @@ class Base extends WriterPart
|
||||||
*/
|
*/
|
||||||
protected function writeContainerElements(XMLWriter $xmlWriter, Container $container)
|
protected function writeContainerElements(XMLWriter $xmlWriter, Container $container)
|
||||||
{
|
{
|
||||||
|
// Check allowed elements
|
||||||
|
$elmCommon = array('Text', 'Link', 'TextBreak', 'Image');
|
||||||
|
$elmMainCell = array_merge($elmCommon, array('TextRun', 'ListItem', 'CheckBox'));
|
||||||
$allowedElements = array(
|
$allowedElements = array(
|
||||||
'Section' => array('Text', 'TextRun', 'Link', 'Title', 'TextBreak', 'ListItem', 'Table', 'Image', 'Object', 'CheckBox', 'Footnote', 'TOC'),
|
'Section' => array_merge($elmMainCell, array('Table', 'Footnote', 'Object', 'Title', 'PageBreak', 'TOC')),
|
||||||
'Header' => array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', 'ListItem', 'Image', 'CheckBox'),
|
'Header' => array_merge($elmMainCell, array('Table', 'PreserveText')),
|
||||||
'Footer' => array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', 'ListItem', 'Image', 'CheckBox'),
|
'Footer' => array_merge($elmMainCell, array('Table', 'PreserveText')),
|
||||||
'Cell' => array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', 'ListItem', 'Image', 'Object', 'CheckBox', 'Footnote'),
|
'Cell' => array_merge($elmMainCell, array('Object', 'PreserveText', 'Footnote')),
|
||||||
'TextRun' => array('Text', 'Link', 'TextBreak', 'Image', 'Object', 'Footnote'),
|
'TextRun' => array_merge($elmCommon, array('Object', 'Footnote')),
|
||||||
'Footnote' => array('Text', 'Link', 'TextBreak', 'Image', 'Object'),
|
'Footnote' => array_merge($elmCommon, array('Object')),
|
||||||
);
|
);
|
||||||
$containerName = get_class($container);
|
$containerName = get_class($container);
|
||||||
$containerName = substr($containerName, strrpos($containerName, '\\') + 1);
|
$containerName = substr($containerName, strrpos($containerName, '\\') + 1);
|
||||||
|
|
@ -1189,6 +1192,7 @@ class Base extends WriterPart
|
||||||
throw new Exception('Invalid container.');
|
throw new Exception('Invalid container.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loop through elements
|
||||||
$elements = $container->getElements();
|
$elements = $container->getElements();
|
||||||
if (count($elements) > 0) {
|
if (count($elements) > 0) {
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ class Footnotes extends Base
|
||||||
protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
|
protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
|
||||||
{
|
{
|
||||||
$xmlWriter->startElement('w:footnote');
|
$xmlWriter->startElement('w:footnote');
|
||||||
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
|
$xmlWriter->writeAttribute('w:id', $footnote->getRelationId());
|
||||||
$xmlWriter->startElement('w:p');
|
$xmlWriter->startElement('w:p');
|
||||||
// Paragraph style
|
// Paragraph style
|
||||||
$styleParagraph = $footnote->getParagraphStyle();
|
$styleParagraph = $footnote->getParagraphStyle();
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,8 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
||||||
$oFootnote = new Footnote();
|
$oFootnote = new Footnote();
|
||||||
|
|
||||||
$iVal = rand(1, 1000);
|
$iVal = rand(1, 1000);
|
||||||
$oFootnote->setReferenceId($iVal);
|
$oFootnote->setRelationId($iVal);
|
||||||
$this->assertEquals($oFootnote->getReferenceId(), $iVal);
|
$this->assertEquals($oFootnote->getRelationId(), $iVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue