Create new Element abstract class

This commit is contained in:
Ivan Lanin 2014-04-03 08:44:41 +07:00
parent 04e6dbc86a
commit 637c9fce6f
21 changed files with 228 additions and 290 deletions

View File

@ -33,6 +33,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
- `createHeader` replaced by `addHeader`
- `createFooter` replaced by `addFooter`
- `createSection` replaced by `addSection`
- `Element\Footnote::getReferenceId` replaced by `Container\Container::getRelationId`
- `Element\Footnote::setReferenceId` replaced by `Container\Container::setRelationId`
### 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
- Reader: Rename AbstractReader > Reader - @ivanlanin
- 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
- Container: Create new Container abstract class - @ivanlanin GH-187
- Element: Create new Element abstract class - @ivanlanin GH-187
## 0.9.1 - 27 Mar 2014

View File

@ -385,7 +385,7 @@ abstract class Container
$footnote = new FootnoteElement($paragraphStyle);
$refID = FootnoteCollection::addFootnoteElement($footnote);
$footnote->setReferenceId($refID);
$footnote->setRelationId($refID);
$this->elements[] = $footnote;
return $footnote;
@ -487,6 +487,33 @@ abstract class Container
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
*
@ -507,7 +534,7 @@ abstract class Container
'object' => array('section', 'textrun', 'cell', 'footnote'),
'footnote' => array('section', 'textrun', 'cell'),
'preservetext' => array('header', 'footer', 'cell'),
'relationid' => array('header', 'footer'),
'relationid' => array('header', 'footer', 'footnote'),
'title' => array('section'),
);
$validContainerInContainers = array(

View File

@ -45,20 +45,7 @@ class Cell extends Container
$this->docPart = $docPart;
$this->docPartId = $docPartId;
$this->width = $width;
$this->cellStyle = new CellStyle();
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;
}
}
$this->cellStyle = $this->setStyle(new CellStyle(), $style, true);
}
/**

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Check box element
*/
class CheckBox
class CheckBox extends Element
{
/**
* Name content

View File

@ -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;
}
}

View File

@ -24,13 +24,6 @@ class Footnote extends Container
*/
private $paragraphStyle;
/**
* Footnote Reference ID
*
* @var string
*/
private $referenceId;
/**
* Create new instance
*
@ -39,18 +32,7 @@ class Footnote extends Container
public function __construct($paragraphStyle = null)
{
$this->container = 'footnote';
// Set paragraph style
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;
}
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
}
/**
@ -67,19 +49,21 @@ class Footnote extends Container
* Get Footnote Reference ID
*
* @return int
* @deprecated 0.9.2
*/
public function getReferenceId()
{
return $this->referenceId;
return $this->getRelationId();
}
/**
* Set Footnote Reference ID
*
* @param int $refId
* @deprecated 0.9.2
*/
public function setReferenceId($refId)
{
$this->referenceId = $refId;
$this->setRelationId($refId);
}
}

View File

@ -11,11 +11,12 @@ namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exception\InvalidImageException;
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Image element
*/
class Image
class Image extends Element
{
/**
* Image source
@ -27,7 +28,7 @@ class Image
/**
* Image style
*
* @var \PhpOffice\PhpWord\Style\Image
* @var ImageStyle
*/
private $style;
@ -131,15 +132,7 @@ class Image
// Set private properties
$this->source = $source;
$this->isWatermark = $isWatermark;
$this->style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->style->setStyleValue($key, $value);
}
}
$this->style = $this->setStyle(new ImageStyle(), $style, true);
if (isset($style['wrappingStyle'])) {
$this->style->setWrappingStyle($style['wrappingStyle']);
}
@ -153,7 +146,7 @@ class Image
/**
* Get Image style
*
* @return \PhpOffice\PhpWord\Style\Image
* @return ImageStyle
*/
public function getStyle()
{

View File

@ -15,42 +15,42 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Link element
*/
class Link
class Link extends Element
{
/**
* Link source
*
* @var string
*/
private $_linkSrc;
private $source;
/**
* Link name
*
* @var string
*/
private $_linkName;
private $name;
/**
* Link Relation ID
*
* @var string
*/
private $_rId;
private $relationId;
/**
* Link style
* Font style
*
* @var string|Font
*/
private $_styleFont;
private $fontStyle;
/**
* Paragraph style
*
* @var string|Paragraph
*/
private $_styleParagraph;
private $paragraphStyle;
/**
@ -58,41 +58,15 @@ class Link
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @param mixed $styleParagraph
* @param mixed $fontStyle
* @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->_linkName = $linkName;
// Set font style
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;
}
$this->source = $linkSrc;
$this->name = $linkName;
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
return $this;
}
@ -104,7 +78,7 @@ class Link
*/
public function getRelationId()
{
return $this->_rId;
return $this->relationId;
}
/**
@ -114,7 +88,7 @@ class Link
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
$this->relationId = $rId;
}
/**
@ -124,7 +98,7 @@ class Link
*/
public function getLinkSrc()
{
return $this->_linkSrc;
return $this->source;
}
/**
@ -134,7 +108,7 @@ class Link
*/
public function getLinkName()
{
return $this->_linkName;
return $this->name;
}
/**
@ -144,7 +118,7 @@ class Link
*/
public function getFontStyle()
{
return $this->_styleFont;
return $this->fontStyle;
}
/**
@ -154,6 +128,6 @@ class Link
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
return $this->paragraphStyle;
}
}

View File

@ -9,31 +9,33 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
* List item element
*/
class ListItem
class ListItem extends Element
{
/**
* ListItem Style
*
* @var \PhpOffice\PhpWord\Style\ListItem
* @var ListItemStyle
*/
private $_style;
private $style;
/**
* Textrun
*
* @var \PhpOffice\PhpWord\Element\Text
*/
private $_textObject;
private $textObject;
/**
* ListItem Depth
*
* @var int
*/
private $_depth;
private $depth;
/**
@ -47,18 +49,9 @@ class ListItem
*/
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->_depth = $depth;
if (!is_null($styleList) && is_array($styleList)) {
foreach ($styleList as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
$this->textObject = new Text($text, $styleFont, $styleParagraph);
$this->depth = $depth;
$this->style = $this->setStyle(new ListItemStyle(), $styleList, true);
}
/**
@ -66,7 +59,7 @@ class ListItem
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
/**
@ -74,7 +67,7 @@ class ListItem
*/
public function getTextObject()
{
return $this->_textObject;
return $this->textObject;
}
/**
@ -82,6 +75,6 @@ class ListItem
*/
public function getDepth()
{
return $this->_depth;
return $this->depth;
}
}

View File

@ -9,45 +9,47 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Object element
*/
class Object
class Object extends Element
{
/**
* Ole-Object Src
*
* @var string
*/
private $_src;
private $source;
/**
* Image Style
*
* @var \PhpOffice\PhpWord\Style\Image
*/
private $_style;
private $style;
/**
* Object Relation ID
*
* @var int
*/
private $_rId;
private $relationId;
/**
* Image Relation ID
*
* @var int
*/
private $_rIdImg;
private $imageRelationId;
/**
* Object ID
*
* @var int
*/
private $_objId;
private $objectId;
/**
@ -58,22 +60,12 @@ class Object
*/
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);
if (\file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
$this->_src = $src;
$this->_style = new \PhpOffice\PhpWord\Style\Image();
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 (\file_exists($src) && in_array($inf['extension'], $supportedTypes)) {
$this->source = $src;
$this->style = $this->setStyle(new ImageStyle(), $style, true);
return $this;
} else {
return false;
@ -87,7 +79,7 @@ class Object
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
/**
@ -97,7 +89,7 @@ class Object
*/
public function getSource()
{
return $this->_src;
return $this->source;
}
/**
@ -107,7 +99,7 @@ class Object
*/
public function getRelationId()
{
return $this->_rId;
return $this->relationId;
}
/**
@ -117,7 +109,7 @@ class Object
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
$this->relationId = $rId;
}
/**
@ -127,7 +119,7 @@ class Object
*/
public function getImageRelationId()
{
return $this->_rIdImg;
return $this->imageRelationId;
}
/**
@ -137,7 +129,7 @@ class Object
*/
public function setImageRelationId($rId)
{
$this->_rIdImg = $rId;
$this->imageRelationId = $rId;
}
/**
@ -147,7 +139,7 @@ class Object
*/
public function getObjectId()
{
return $this->_objId;
return $this->objectId;
}
/**
@ -157,6 +149,6 @@ class Object
*/
public function setObjectId($objId)
{
$this->_objId = $objId;
$this->objectId = $objId;
}
}

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Element;
/**
* Page break element
*/
class PageBreak
class PageBreak extends Element
{
/**
* Create new page break

View File

@ -15,28 +15,28 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Preserve text/field element
*/
class PreserveText
class PreserveText extends Element
{
/**
* Text content
*
* @var string
*/
private $_text;
private $text;
/**
* Text style
*
* @var string|Font
*/
private $_styleFont;
private $fontStyle;
/**
* Paragraph style
*
* @var string|Paragraph
*/
private $_styleParagraph;
private $paragraphStyle;
/**
@ -49,37 +49,12 @@ class PreserveText
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{
// Set font style
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;
}
$this->fontStyle = $this->setStyle(new Font('text'), $styleFont);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $styleParagraph);
$matches = preg_split('/({.*?})/', $text, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) {
$this->_text = $matches;
$this->text = $matches;
}
return $this;
@ -92,7 +67,7 @@ class PreserveText
*/
public function getFontStyle()
{
return $this->_styleFont;
return $this->fontStyle;
}
/**
@ -102,7 +77,7 @@ class PreserveText
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
return $this->paragraphStyle;
}
/**
@ -112,6 +87,6 @@ class PreserveText
*/
public function getText()
{
return $this->_text;
return $this->text;
}
}

View File

@ -9,73 +9,63 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Row as RowStyle;
/**
* Table row element
*/
class Row
class Row extends Element
{
/**
* Row height
*
* @var int
*/
private $_height = null;
private $height = null;
/**
* Row style
*
* @var \PhpOffice\PhpWord\Style\Row
* @var RowStyle
*/
private $_style;
private $style;
/**
* Row cells
*
* @var array
*/
private $_cells = array();
private $cells = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf;
private $docPart;
/**
* Section/Header/Footer count
*
* @var int
*/
private $_pCount;
private $docPartId;
/**
* Create a new table row
*
* @param string $insideOf
* @param int $pCount
* @param string $docPart
* @param int $docPartId
* @param int $height
* @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->_pCount = $pCount;
$this->_height = $height;
$this->_style = new \PhpOffice\PhpWord\Style\Row();
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);
}
}
}
$this->docPart = $docPart;
$this->docPartId = $docPartId;
$this->height = $height;
$this->style = $this->setStyle(new RowStyle(), $style, true);
}
/**
@ -83,12 +73,11 @@ class Row
*
* @param int $width
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Cell
*/
public function addCell($width = null, $style = null)
{
$cell = new Cell($this->_insideOf, $this->_pCount, $width, $style);
$this->_cells[] = $cell;
$cell = new Cell($this->docPart, $this->docPartId, $width, $style);
$this->cells[] = $cell;
return $cell;
}
@ -99,17 +88,17 @@ class Row
*/
public function getCells()
{
return $this->_cells;
return $this->cells;
}
/**
* Get row style
*
* @return \PhpOffice\PhpWord\Style\Row
* @return RowStyle
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
/**
@ -119,6 +108,6 @@ class Row
*/
public function getHeight()
{
return $this->_height;
return $this->height;
}
}

View File

@ -10,74 +10,60 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Element\Row;
use PhpOffice\PhpWord\Style\Table as TableStyle;
/**
* Table element
*/
class Table
class Table extends Element
{
/**
* Table style
*
* @var \PhpOffice\PhpWord\Style\Table
* @var TableStyle
*/
private $_style;
private $style;
/**
* Table rows
*
* @var array
*/
private $_rows = array();
private $rows = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf = null;
private $docPart = null;
/**
* Table holder count
*
* @var array
*/
private $_pCount;
private $docPartId;
/**
* Table width
*
* @var int
*/
private $_width = null;
private $width = null;
/**
* Create a new table
*
* @param string $insideOf
* @param int $pCount
* @param string $docPart
* @param int $docPartId
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $style = null)
public function __construct($docPart, $docPartId, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
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;
}
}
$this->docPart = $docPart;
$this->docPartId = $docPartId;
$this->style = $this->setStyle(new TableStyle(), $style);
}
/**
@ -88,8 +74,8 @@ class Table
*/
public function addRow($height = null, $style = null)
{
$row = new Row($this->_insideOf, $this->_pCount, $height, $style);
$this->_rows[] = $row;
$row = new Row($this->docPart, $this->docPartId, $height, $style);
$this->rows[] = $row;
return $row;
}
@ -102,8 +88,8 @@ class Table
*/
public function addCell($width = null, $style = null)
{
$i = count($this->_rows) - 1;
$cell = $this->_rows[$i]->addCell($width, $style);
$i = count($this->rows) - 1;
$cell = $this->rows[$i]->addCell($width, $style);
return $cell;
}
@ -114,17 +100,17 @@ class Table
*/
public function getRows()
{
return $this->_rows;
return $this->rows;
}
/**
* Get table style
*
* @return \PhpOffice\PhpWord\Style\Table
* @return TableStyle
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
/**
@ -134,7 +120,7 @@ class Table
*/
public function setWidth($width)
{
$this->_width = $width;
$this->width = $width;
}
/**
@ -144,6 +130,6 @@ class Table
*/
public function getWidth()
{
return $this->_width;
return $this->width;
}
}

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text element
*/
class Text
class Text extends Element
{
/**
* Text content

View File

@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text break element
*/
class TextBreak
class TextBreak extends Element
{
/**
* Paragraph style

View File

@ -36,18 +36,7 @@ class TextRun extends Container
$this->container = 'textrun';
$this->docPart = $docPart;
$this->docPartId = $docPartId;
// Set paragraph style
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;
}
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
}
/**

View File

@ -12,42 +12,42 @@ namespace PhpOffice\PhpWord\Element;
/**
* Title element
*/
class Title
class Title extends Element
{
/**
* Title Text content
*
* @var string
*/
private $_text;
private $text;
/**
* Title depth
*
* @var int
*/
private $_depth;
private $depth;
/**
* Title anchor
*
* @var int
*/
private $_anchor;
private $anchor;
/**
* Title Bookmark ID
*
* @var int
*/
private $_bookmarkId;
private $bookmarkId;
/**
* Title style
*
* @var string
*/
private $_style;
private $style;
/**
@ -60,11 +60,11 @@ class Title
public function __construct($text, $depth = 1, $style = null)
{
if (!is_null($style)) {
$this->_style = $style;
$this->style = $style;
}
$this->_text = $text;
$this->_depth = $depth;
$this->text = $text;
$this->depth = $depth;
return $this;
}
@ -76,7 +76,7 @@ class Title
*/
public function setAnchor($anchor)
{
$this->_anchor = $anchor;
$this->anchor = $anchor;
}
/**
@ -86,7 +86,7 @@ class Title
*/
public function getAnchor()
{
return $this->_anchor;
return $this->anchor;
}
/**
@ -96,7 +96,7 @@ class Title
*/
public function setBookmarkId($bookmarkId)
{
$this->_bookmarkId = $bookmarkId;
$this->bookmarkId = $bookmarkId;
}
/**
@ -106,7 +106,7 @@ class Title
*/
public function getBookmarkId()
{
return $this->_bookmarkId;
return $this->bookmarkId;
}
/**
@ -116,7 +116,7 @@ class Title
*/
public function getText()
{
return $this->_text;
return $this->text;
}
/**
@ -126,6 +126,6 @@ class Title
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
}

View File

@ -614,7 +614,7 @@ class Base extends WriterPart
$xmlWriter->endElement(); // w:rStyle
$xmlWriter->endElement(); // w:rPr
$xmlWriter->startElement('w:footnoteReference');
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
$xmlWriter->writeAttribute('w:id', $footnote->getRelationId());
$xmlWriter->endElement(); // w:footnoteReference
$xmlWriter->endElement(); // w:r
if (!$withoutP) {
@ -1173,13 +1173,16 @@ class Base extends WriterPart
*/
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(
'Section' => array('Text', 'TextRun', 'Link', 'Title', 'TextBreak', 'ListItem', 'Table', 'Image', 'Object', 'CheckBox', 'Footnote', 'TOC'),
'Header' => array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', 'ListItem', 'Image', 'CheckBox'),
'Footer' => array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', 'ListItem', 'Image', 'CheckBox'),
'Cell' => array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak', 'ListItem', 'Image', 'Object', 'CheckBox', 'Footnote'),
'TextRun' => array('Text', 'Link', 'TextBreak', 'Image', 'Object', 'Footnote'),
'Footnote' => array('Text', 'Link', 'TextBreak', 'Image', 'Object'),
'Section' => array_merge($elmMainCell, array('Table', 'Footnote', 'Object', 'Title', 'PageBreak', 'TOC')),
'Header' => array_merge($elmMainCell, array('Table', 'PreserveText')),
'Footer' => array_merge($elmMainCell, array('Table', 'PreserveText')),
'Cell' => array_merge($elmMainCell, array('Object', 'PreserveText', 'Footnote')),
'TextRun' => array_merge($elmCommon, array('Object', 'Footnote')),
'Footnote' => array_merge($elmCommon, array('Object')),
);
$containerName = get_class($container);
$containerName = substr($containerName, strrpos($containerName, '\\') + 1);
@ -1189,6 +1192,7 @@ class Base extends WriterPart
throw new Exception('Invalid container.');
}
// Loop through elements
$elements = $container->getElements();
if (count($elements) > 0) {
foreach ($elements as $element) {

View File

@ -89,7 +89,7 @@ class Footnotes extends Base
protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
{
$xmlWriter->startElement('w:footnote');
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
$xmlWriter->writeAttribute('w:id', $footnote->getRelationId());
$xmlWriter->startElement('w:p');
// Paragraph style
$styleParagraph = $footnote->getParagraphStyle();

View File

@ -96,8 +96,8 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
$oFootnote = new Footnote();
$iVal = rand(1, 1000);
$oFootnote->setReferenceId($iVal);
$this->assertEquals($oFootnote->getReferenceId(), $iVal);
$oFootnote->setRelationId($iVal);
$this->assertEquals($oFootnote->getRelationId(), $iVal);
}
/**