201 lines
4.5 KiB
PHP
Raw Normal View History

2012-05-06 18:25:40 +02:00
<?php
/**
* PHPWord
2012-05-06 18:25:40 +02:00
*
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
2012-05-06 18:25:40 +02:00
*/
namespace PhpOffice\PhpWord\Container;
2013-12-16 06:40:30 -05:00
use PhpOffice\PhpWord\Exception\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\PreserveText;
use PhpOffice\PhpWord\Element\TextBreak;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Element\Image;
/**
* Footer element
*/
class Footer
{
2013-12-16 06:40:30 -05:00
/**
* Footer Count
*
* @var int
*/
private $_footerCount;
/**
* Footer Relation ID
*
* @var int
*/
private $_rId;
/**
* Footer Element Collection
*
* @var int
*/
private $_elementCollection = array();
/**
* Create a new Footer
*
* @param int $sectionCount
2013-12-16 06:40:30 -05:00
*/
public function __construct($sectionCount)
{
$this->_footerCount = $sectionCount;
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Element\Text
2013-12-16 06:40:30 -05:00
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
2013-12-16 06:40:30 -05:00
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
2013-12-16 06:40:30 -05:00
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add TextBreak
2013-12-16 06:40:30 -05:00
*
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
2013-12-16 06:40:30 -05:00
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
2013-12-16 06:40:30 -05:00
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
2013-12-16 06:40:30 -05:00
}
}
/**
* Create a new TextRun
*
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Element\TextRun
2013-12-16 06:40:30 -05:00
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
2013-12-16 06:40:30 -05:00
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Add a Table Element
*
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Table
2013-12-16 06:40:30 -05:00
*/
public function addTable($style = null)
{
$table = new Table('footer', $this->_footerCount, $style);
2013-12-16 06:40:30 -05:00
$this->_elementCollection[] = $table;
return $table;
}
2013-12-16 06:40:30 -05:00
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Image
2013-12-16 06:40:30 -05:00
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
2013-12-16 06:40:30 -05:00
if (!is_null($image->getSource())) {
$rID = Media::addFooterMediaElement($this->_footerCount, $src, $image);
2013-12-16 06:40:30 -05:00
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
2014-03-25 17:53:10 +07:00
throw new InvalidImageException;
2013-12-16 06:40:30 -05:00
}
}
/**
* Add a by PHP created Image Element
*
2014-03-28 13:50:53 +07:00
* @param string $src
2013-12-16 06:40:30 -05:00
* @param mixed $style
* @deprecated
2013-12-16 06:40:30 -05:00
*/
public function addMemoryImage($src, $style = null)
2013-12-16 06:40:30 -05:00
{
return $this->addImage($src, $style);
2013-12-16 06:40:30 -05:00
}
/**
* Add a PreserveText Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Element\PreserveText
2013-12-16 06:40:30 -05:00
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
2013-12-16 06:40:30 -05:00
$text = utf8_encode($text);
}
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
2013-12-16 06:40:30 -05:00
$this->_elementCollection[] = $ptext;
return $ptext;
}
/**
* Get Footer Relation ID
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Footer Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get all Footer Elements
2014-03-09 19:09:22 +01:00
* @return array
2013-12-16 06:40:30 -05:00
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Footer Count
*/
public function getFooterCount()
{
return $this->_footerCount;
}
}