Add $nestedLevel to elements
This commit is contained in:
parent
022cdeb570
commit
e7540c079e
@ -65,9 +65,18 @@ abstract class AbstractContainer extends AbstractElement
|
||||
$reflection = new \ReflectionClass($elementClass);
|
||||
$elementArgs = $args;
|
||||
array_shift($elementArgs); // Shift an element off the beginning of array: the $elementName
|
||||
|
||||
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
|
||||
$element = $reflection->newInstanceArgs($elementArgs);
|
||||
|
||||
// Set nested level
|
||||
if ($this->container == 'Cell') {
|
||||
$element->setNestedLevel($this->getNestedLevel() + 1);
|
||||
} else {
|
||||
$element->setNestedLevel($this->getNestedLevel());
|
||||
}
|
||||
|
||||
|
||||
// Set relation Id for media collection
|
||||
$mediaContainer = $this->getMediaContainer();
|
||||
if (in_array($elementName, array('Link', 'Image', 'Object'))) {
|
||||
@ -143,32 +152,6 @@ abstract class AbstractContainer extends AbstractElement
|
||||
return $this->addElement('TextRun', $paragraphStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add field element
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $properties
|
||||
* @param array $options
|
||||
* @return \PhpOffice\PhpWord\Element\Field
|
||||
*/
|
||||
public function addField($type = null, $properties = array(), $options = array())
|
||||
{
|
||||
return $this->addElement('Field', $type, $properties, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add line element
|
||||
*
|
||||
* @param mixed $lineStyle
|
||||
* @return \PhpOffice\PhpWord\Element\Line
|
||||
*/
|
||||
public function addLine($lineStyle = null)
|
||||
{
|
||||
return $this->addElement('Line', $lineStyle);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add link element
|
||||
*
|
||||
@ -323,6 +306,31 @@ abstract class AbstractContainer extends AbstractElement
|
||||
return $this->addElement('TextBox', $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add field element
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $properties
|
||||
* @param array $options
|
||||
* @return \PhpOffice\PhpWord\Element\Field
|
||||
*/
|
||||
public function addField($type = null, $properties = array(), $options = array())
|
||||
{
|
||||
return $this->addElement('Field', $type, $properties, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add line element
|
||||
*
|
||||
* @param mixed $lineStyle
|
||||
* @return \PhpOffice\PhpWord\Element\Line
|
||||
*/
|
||||
public function addLine($lineStyle = null)
|
||||
{
|
||||
return $this->addElement('Line', $lineStyle);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a method is allowed for the current container
|
||||
*
|
||||
|
||||
@ -84,6 +84,15 @@ abstract class AbstractElement
|
||||
*/
|
||||
protected $relationId;
|
||||
|
||||
/**
|
||||
* Depth of table container nested level; Primarily used for RTF writer/reader
|
||||
*
|
||||
* 0 = Not in a table; 1 = in a table; 2 = in a table inside another table, etc.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $nestedLevel = 0;
|
||||
|
||||
/**
|
||||
* Get PhpWord
|
||||
*
|
||||
@ -197,11 +206,31 @@ abstract class AbstractElement
|
||||
/**
|
||||
* Set relation Id
|
||||
*
|
||||
* @param int $rId
|
||||
* @param int $value
|
||||
*/
|
||||
public function setRelationId($rId)
|
||||
public function setRelationId($value)
|
||||
{
|
||||
$this->relationId = $rId;
|
||||
$this->relationId = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nested level
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNestedLevel()
|
||||
{
|
||||
return $this->nestedLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set nested level
|
||||
*
|
||||
* @param int $value
|
||||
*/
|
||||
public function setNestedLevel($value)
|
||||
{
|
||||
$this->nestedLevel = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -71,6 +71,7 @@ class Row extends AbstractElement
|
||||
$cell = new Cell($width, $style);
|
||||
$cell->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$cell->setPhpWord($this->phpWord);
|
||||
$cell->setNestedLevel($this->getNestedLevel());
|
||||
$this->cells[] = $cell;
|
||||
|
||||
return $cell;
|
||||
|
||||
@ -45,7 +45,6 @@ class Table extends AbstractElement
|
||||
*/
|
||||
private $width = null;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new table
|
||||
*
|
||||
@ -68,6 +67,7 @@ class Table extends AbstractElement
|
||||
$row = new Row($height, $style);
|
||||
$row->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$row->setPhpWord($this->phpWord);
|
||||
$row->setNestedLevel($this->getNestedLevel());
|
||||
$this->rows[] = $row;
|
||||
|
||||
return $row;
|
||||
@ -109,16 +109,6 @@ class Table extends AbstractElement
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table width
|
||||
*
|
||||
* @param int $width
|
||||
*/
|
||||
public function setWidth($width)
|
||||
{
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table width
|
||||
*
|
||||
@ -129,6 +119,16 @@ class Table extends AbstractElement
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table width
|
||||
*
|
||||
* @param int $width
|
||||
*/
|
||||
public function setWidth($width)
|
||||
{
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column count
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user