PHPWord/src/PhpWord/Style/Table.php

435 lines
8.9 KiB
PHP
Raw Normal View History

<?php
/**
* PHPWord
*
2014-03-27 23:55:06 +07:00
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Style;
/**
* Table style
*/
class Table extends Border
{
2014-03-24 11:33:20 +07:00
/**
* Style for first row
*
* @var \PhpOffice\PhpWord\Style\Table
*/
private $firstRow = null;
2014-03-24 11:33:20 +07:00
/**
* Cell margin top
*
* @var int
*/
private $cellMarginTop = null;
/**
* Cell margin left
*
* @var int
*/
private $cellMarginLeft = null;
/**
* Cell margin right
*
* @var int
*/
private $cellMarginRight = null;
/**
* Cell margin bottom
*
* @var int
*/
private $cellMarginBottom = null;
2014-03-24 11:33:20 +07:00
/**
* Border size inside horizontal
*
* @var int
*/
private $borderInsideHSize;
2014-03-24 11:33:20 +07:00
/**
* Border color inside horizontal
*
* @var string
*/
private $borderInsideHColor;
2014-03-24 11:33:20 +07:00
/**
* Border size inside vertical
*
* @var int
*/
private $borderInsideVSize;
2014-03-24 11:33:20 +07:00
/**
* Border color inside vertical
*
* @var string
*/
private $borderInsideVColor;
2014-03-24 11:33:20 +07:00
/**
* Shading
*
* @var \PhpOffice\PhpWord\Style\Shading
*/
private $shading;
/**
* Create new table style
2014-03-24 11:33:20 +07:00
*
* @param mixed $styleTable
* @param mixed $styleFirstRow
*/
2014-03-24 11:33:20 +07:00
public function __construct($styleTable = null, $styleFirstRow = null)
{
2014-03-24 11:33:20 +07:00
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->firstRow = clone $this;
unset($this->firstRow->firstRow);
unset($this->firstRow->cellMarginBottom);
unset($this->firstRow->cellMarginTop);
unset($this->firstRow->cellMarginLeft);
unset($this->firstRow->cellMarginRight);
unset($this->firstRow->borderInsideVColor);
unset($this->firstRow->borderInsideVSize);
unset($this->firstRow->borderInsideHColor);
unset($this->firstRow->borderInsideHSize);
2014-03-24 11:33:20 +07:00
foreach ($styleFirstRow as $key => $value) {
$this->firstRow->setStyleValue($key, $value);
2014-03-24 11:33:20 +07:00
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
$this->setStyleValue($key, $value);
}
}
}
2014-03-24 11:33:20 +07:00
/**
* Get First Row Style
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getFirstRow()
{
return $this->firstRow;
2014-03-24 11:33:20 +07:00
}
/**
* Get background
*
2014-04-03 10:13:13 +07:00
* @return string
2014-03-24 11:33:20 +07:00
*/
public function getBgColor()
{
if (!is_null($this->shading)) {
return $this->shading->getFill();
}
2014-03-24 11:33:20 +07:00
}
/**
* Set background
*
* @param string $value
2014-03-24 11:33:20 +07:00
* @return \PhpOffice\PhpWord\Style\Table
*/
public function setBgColor($value = null)
2014-03-24 11:33:20 +07:00
{
$this->setShading(array('fill' => $value));
2014-03-24 11:33:20 +07:00
}
/**
* Set TLRBHV Border Size
2014-03-24 11:33:20 +07:00
*
* @param int $value Border size in eighths of a point (1/8 point)
* @return self
2014-03-24 11:33:20 +07:00
*/
public function setBorderSize($value = null)
2014-03-24 11:33:20 +07:00
{
$this->setBorderTopSize($value);
$this->setBorderLeftSize($value);
$this->setBorderRightSize($value);
$this->setBorderBottomSize($value);
$this->setBorderInsideHSize($value);
$this->setBorderInsideVSize($value);
return $this;
2014-03-24 11:33:20 +07:00
}
/**
* Get TLRBHV Border Size
2014-03-24 11:33:20 +07:00
*
2014-05-02 01:15:28 +07:00
* @return int[]
2014-03-24 11:33:20 +07:00
*/
public function getBorderSize()
{
return array(
$this->getBorderTopSize(),
$this->getBorderLeftSize(),
$this->getBorderRightSize(),
$this->getBorderBottomSize(),
$this->getBorderInsideHSize(),
$this->getBorderInsideVSize(),
);
2014-03-24 11:33:20 +07:00
}
/**
* Set TLRBHV Border Color
*
* @param string $value
* @return self
2014-03-24 11:33:20 +07:00
*/
public function setBorderColor($value = null)
2014-03-24 11:33:20 +07:00
{
$this->setBorderTopColor($value);
$this->setBorderLeftColor($value);
$this->setBorderRightColor($value);
$this->setBorderBottomColor($value);
$this->setBorderInsideHColor($value);
$this->setBorderInsideVColor($value);
return $this;
2014-03-24 11:33:20 +07:00
}
/**
* Get TLRBHV Border Color
2014-03-24 11:33:20 +07:00
*
2014-05-02 01:15:28 +07:00
* @return string[]
2014-03-24 11:33:20 +07:00
*/
public function getBorderColor()
{
return array(
$this->getBorderTopColor(),
$this->getBorderLeftColor(),
$this->getBorderRightColor(),
$this->getBorderBottomColor(),
$this->getBorderInsideHColor(),
$this->getBorderInsideVColor(),
);
2014-03-24 11:33:20 +07:00
}
/**
* Set border size inside horizontal
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @param int $value
2014-03-24 11:33:20 +07:00
*/
public function setBorderInsideHSize($value = null)
2014-03-24 11:33:20 +07:00
{
$this->borderInsideHSize = $value;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size inside horizontal
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @return int
2014-03-24 11:33:20 +07:00
*/
public function getBorderInsideHSize()
2014-03-24 11:33:20 +07:00
{
return (isset($this->borderInsideHSize)) ? $this->borderInsideHSize : null;
2014-03-24 11:33:20 +07:00
}
/**
* Set border size inside vertical
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @param int $value
2014-03-24 11:33:20 +07:00
*/
public function setBorderInsideVSize($value = null)
2014-03-24 11:33:20 +07:00
{
$this->borderInsideVSize = $value;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size inside vertical
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @return int
2014-03-24 11:33:20 +07:00
*/
public function getBorderInsideVSize()
2014-03-24 11:33:20 +07:00
{
return (isset($this->borderInsideVSize)) ? $this->borderInsideVSize : null;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color inside horizontal
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @param string $value
2014-03-24 11:33:20 +07:00
*/
public function setBorderInsideHColor($value = null)
2014-03-24 11:33:20 +07:00
{
$this->borderInsideHColor = $value;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color inside horizontal
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @return string
2014-03-24 11:33:20 +07:00
*/
public function getBorderInsideHColor()
2014-03-24 11:33:20 +07:00
{
return (isset($this->borderInsideHColor)) ? $this->borderInsideHColor : null;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color inside vertical
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @param string $value
2014-03-24 11:33:20 +07:00
*/
public function setBorderInsideVColor($value = null)
2014-03-24 11:33:20 +07:00
{
$this->borderInsideVColor = $value;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color inside vertical
2014-03-24 11:33:20 +07:00
*
2014-05-04 15:13:31 +07:00
* @return string
2014-03-24 11:33:20 +07:00
*/
public function getBorderInsideVColor()
2014-03-24 11:33:20 +07:00
{
return (isset($this->borderInsideVColor)) ? $this->borderInsideVColor : null;
}
/**
* Set cell margin top
*
* @param int $value
*/
public function setCellMarginTop($value = null)
{
$this->cellMarginTop = $value;
}
/**
* Get cell margin top
*
* @return int
*/
public function getCellMarginTop()
{
return $this->cellMarginTop;
}
/**
* Set cell margin left
*
* @param int $value
*/
public function setCellMarginLeft($value = null)
{
$this->cellMarginLeft = $value;
}
/**
* Get cell margin left
*
* @return int
*/
public function getCellMarginLeft()
{
return $this->cellMarginLeft;
}
/**
* Set cell margin right
*
* @param int $value
*/
public function setCellMarginRight($value = null)
{
$this->cellMarginRight = $value;
}
/**
* Get cell margin right
*
* @return int
*/
public function getCellMarginRight()
{
return $this->cellMarginRight;
}
/**
* Set cell margin bottom
*
* @param int $value
*/
public function setCellMarginBottom($value = null)
{
$this->cellMarginBottom = $value;
}
/**
* Get cell margin bottom
*
* @return int
*/
public function getCellMarginBottom()
{
return $this->cellMarginBottom;
}
/**
* Set TLRB cell margin
*
* @param int $value Margin in twips
*/
public function setCellMargin($value = null)
{
$this->setCellMarginTop($value);
$this->setCellMarginLeft($value);
$this->setCellMarginRight($value);
$this->setCellMarginBottom($value);
}
/**
* Get cell margin
*
2014-05-02 01:15:28 +07:00
* @return int[]
*/
public function getCellMargin()
{
return array($this->cellMarginTop, $this->cellMarginLeft, $this->cellMarginRight, $this->cellMarginBottom);
}
/**
* Get shading
*
* @return \PhpOffice\PhpWord\Style\Shading
*/
public function getShading()
{
return $this->shading;
}
/**
* Set shading
*
* @param array $value
* @return self
*/
public function setShading($value = null)
{
if (is_array($value)) {
if (!$this->shading instanceof Shading) {
$this->shading = new Shading();
}
$this->shading->setStyleByArray($value);
} else {
$this->shading = null;
}
return $this;
}
}