PHPWord/src/PhpWord/Style/Table.php

634 lines
12 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
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Shared\String;
/**
* Table style
*/
class Table extends AbstractStyle
{
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
/**
* Background color
*
* @var string
*/
private $bgColor;
2014-03-24 11:33:20 +07:00
/**
* Border size top
*
* @var int
*/
private $borderTopSize;
2014-03-24 11:33:20 +07:00
/**
* Border color
*
* @var string top
*/
private $borderTopColor;
2014-03-24 11:33:20 +07:00
/**
* Border size left
*
* @var int
*/
private $borderLeftSize;
2014-03-24 11:33:20 +07:00
/**
* Border color left
*
* @var string
*/
private $borderLeftColor;
2014-03-24 11:33:20 +07:00
/**
* Border size right
*
* @var int
*/
private $borderRightSize;
2014-03-24 11:33:20 +07:00
/**
* Border color right
*
* @var string
*/
private $borderRightColor;
2014-03-24 11:33:20 +07:00
/**
* Border size bottom
*
* @var int
*/
private $borderBottomSize;
2014-03-24 11:33:20 +07:00
/**
* Border color bottom
*
* @var string
*/
private $borderBottomColor;
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
/**
* 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);
}
}
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
$key = String::removeUnderscorePrefix($key);
if ($key == 'borderSize') {
2014-03-24 11:33:20 +07:00
$this->setBorderSize($value);
} elseif ($key == 'borderColor') {
2014-03-24 11:33:20 +07:00
$this->setBorderColor($value);
} elseif ($key == 'cellMargin') {
2014-03-24 11:33:20 +07:00
$this->setCellMargin($value);
} else {
$this->$key = $value;
}
}
/**
* 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()
{
return $this->bgColor;
2014-03-24 11:33:20 +07:00
}
/**
* Set background
*
* @param string $pValue
* @return \PhpOffice\PhpWord\Style\Table
*/
public function setBgColor($pValue = null)
{
$this->bgColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Set TLRBVH Border Size
*
* @param int $pValue Border size in eighths of a point (1/8 point)
*/
public function setBorderSize($pValue = null)
{
$this->borderTopSize = $pValue;
$this->borderLeftSize = $pValue;
$this->borderRightSize = $pValue;
$this->borderBottomSize = $pValue;
$this->borderInsideHSize = $pValue;
$this->borderInsideVSize = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get TLRBVH Border Size
*
* @return array
*/
public function getBorderSize()
{
$top = $this->getBorderTopSize();
$left = $this->getBorderLeftSize();
$right = $this->getBorderRightSize();
$bottom = $this->getBorderBottomSize();
$insideH = $this->getBorderInsideHSize();
$insideV = $this->getBorderInsideVSize();
return array($top, $left, $right, $bottom, $insideH, $insideV);
2014-03-24 11:33:20 +07:00
}
/**
* Set TLRBVH Border Color
* @param string $pValue
*/
public function setBorderColor($pValue = null)
{
$this->borderTopColor = $pValue;
$this->borderLeftColor = $pValue;
$this->borderRightColor = $pValue;
$this->borderBottomColor = $pValue;
$this->borderInsideHColor = $pValue;
$this->borderInsideVColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get TLRB Border Color
*
* @return array
*/
public function getBorderColor()
{
$top = $this->getBorderTopColor();
$left = $this->getBorderLeftColor();
$right = $this->getBorderRightColor();
$bottom = $this->getBorderBottomColor();
$insideH = $this->getBorderInsideHColor();
$insideV = $this->getBorderInsideVColor();
return array($top, $left, $right, $bottom, $insideH, $insideV);
2014-03-24 11:33:20 +07:00
}
/**
* Set border size top
*
* @param $pValue
*/
public function setBorderTopSize($pValue = null)
{
$this->borderTopSize = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size top
*
* @return
*/
public function getBorderTopSize()
{
return $this->borderTopSize;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color top
*
* @param $pValue
*/
public function setBorderTopColor($pValue = null)
{
$this->borderTopColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color top
*
* @return
*/
public function getBorderTopColor()
{
return $this->borderTopColor;
2014-03-24 11:33:20 +07:00
}
/**
* Set border size left
*
* @param $pValue
*/
public function setBorderLeftSize($pValue = null)
{
$this->borderLeftSize = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size left
*
* @return
*/
public function getBorderLeftSize()
{
return $this->borderLeftSize;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color left
*
* @param $pValue
*/
public function setBorderLeftColor($pValue = null)
{
$this->borderLeftColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color left
*
* @return
*/
public function getBorderLeftColor()
{
return $this->borderLeftColor;
2014-03-24 11:33:20 +07:00
}
/**
* Set border size right
*
* @param $pValue
*/
public function setBorderRightSize($pValue = null)
{
$this->borderRightSize = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size right
*
* @return
*/
public function getBorderRightSize()
{
return $this->borderRightSize;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color right
*
* @param $pValue
*/
public function setBorderRightColor($pValue = null)
{
$this->borderRightColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color right
*
* @return
*/
public function getBorderRightColor()
{
return $this->borderRightColor;
2014-03-24 11:33:20 +07:00
}
/**
* Set border size bottom
*
* @param $pValue
*/
public function setBorderBottomSize($pValue = null)
{
$this->borderBottomSize = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size bottom
*
* @return
*/
public function getBorderBottomSize()
{
return $this->borderBottomSize;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color bottom
*
* @param $pValue
*/
public function setBorderBottomColor($pValue = null)
{
$this->borderBottomColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color bottom
*
* @return
*/
public function getBorderBottomColor()
{
return $this->borderBottomColor;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHColor($pValue = null)
{
$this->borderInsideHColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color inside horizontal
*
* @return
*/
public function getBorderInsideHColor()
{
return (isset($this->borderInsideHColor)) ? $this->borderInsideHColor : null;
2014-03-24 11:33:20 +07:00
}
/**
* Set border color inside vertical
*
* @param $pValue
*/
public function setBorderInsideVColor($pValue = null)
{
$this->borderInsideVColor = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border color inside vertical
*
* @return
*/
public function getBorderInsideVColor()
{
return (isset($this->borderInsideVColor)) ? $this->borderInsideVColor : null;
2014-03-24 11:33:20 +07:00
}
/**
* Set border size inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHSize($pValue = null)
{
$this->borderInsideHSize = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size inside horizontal
*
* @return
*/
public function getBorderInsideHSize()
{
return (isset($this->borderInsideHSize)) ? $this->borderInsideHSize : null;
2014-03-24 11:33:20 +07:00
}
/**
* Set border size inside vertical
*
* @param $pValue
*/
public function setBorderInsideVSize($pValue = null)
{
$this->borderInsideVSize = $pValue;
2014-03-24 11:33:20 +07:00
}
/**
* Get border size inside vertical
*
* @return
*/
public function getBorderInsideVSize()
{
return (isset($this->borderInsideVSize)) ? $this->borderInsideVSize : null;
}
/**
* Set cell margin top
*
* @param int $pValue
*/
public function setCellMarginTop($pValue = null)
{
$this->cellMarginTop = $pValue;
}
/**
* Get cell margin top
*
* @return int
*/
public function getCellMarginTop()
{
return $this->cellMarginTop;
}
/**
* Set cell margin left
*
* @param int $pValue
*/
public function setCellMarginLeft($pValue = null)
{
$this->cellMarginLeft = $pValue;
}
/**
* Get cell margin left
*
* @return int
*/
public function getCellMarginLeft()
{
return $this->cellMarginLeft;
}
/**
* Set cell margin right
*
* @param int $pValue
*/
public function setCellMarginRight($pValue = null)
{
$this->cellMarginRight = $pValue;
}
/**
* Get cell margin right
*
* @return int
*/
public function getCellMarginRight()
{
return $this->cellMarginRight;
}
/**
* Set cell margin bottom
*
* @param int $pValue
*/
public function setCellMarginBottom($pValue = null)
{
$this->cellMarginBottom = $pValue;
}
/**
* Get cell margin bottom
*
* @return int
*/
public function getCellMarginBottom()
{
return $this->cellMarginBottom;
}
/**
* Set TLRB cell margin
*
* @param int $pValue Margin in twips
*/
public function setCellMargin($pValue = null)
{
$this->cellMarginTop = $pValue;
$this->cellMarginLeft = $pValue;
$this->cellMarginRight = $pValue;
$this->cellMarginBottom = $pValue;
}
/**
* Get cell margin
*
* @return array
*/
public function getCellMargin()
{
return array($this->cellMarginTop, $this->cellMarginLeft, $this->cellMarginRight, $this->cellMarginBottom);
}
}