2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
namespace PhpOffice\PhpWord\Container;
|
2013-12-16 06:40:30 -05:00
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\Media;
|
|
|
|
|
use PhpOffice\PhpWord\Shared\String;
|
2014-03-31 01:13:02 +07:00
|
|
|
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;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Footer element
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
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
|
2014-03-24 00:26:10 +07:00
|
|
|
*
|
|
|
|
|
* @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
|
2014-03-31 01:13:02 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Element\Text
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function addText($text, $styleFont = null, $styleParagraph = null)
|
|
|
|
|
{
|
2014-03-23 17:37:26 +07:00
|
|
|
if (!String::isUTF8($text)) {
|
2013-12-16 06:40:30 -05:00
|
|
|
$text = utf8_encode($text);
|
|
|
|
|
}
|
2014-03-22 10:06:08 +04:00
|
|
|
$text = new Text($text, $styleFont, $styleParagraph);
|
2013-12-16 06:40:30 -05:00
|
|
|
$this->_elementCollection[] = $text;
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-14 22:03:19 +07:00
|
|
|
* Add TextBreak
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* @param int $count
|
2014-03-23 10:32:08 +04:00
|
|
|
* @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
|
|
|
*/
|
2014-03-14 22:03:19 +07:00
|
|
|
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
2013-12-16 06:40:30 -05:00
|
|
|
{
|
|
|
|
|
for ($i = 1; $i <= $count; $i++) {
|
2014-03-22 10:06:08 +04:00
|
|
|
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new TextRun
|
|
|
|
|
*
|
2014-03-24 00:26:10 +07:00
|
|
|
* @param mixed $styleParagraph
|
2014-03-31 01:13:02 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Element\TextRun
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function createTextRun($styleParagraph = null)
|
|
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
$textRun = new TextRun($styleParagraph);
|
2013-12-16 06:40:30 -05:00
|
|
|
$this->_elementCollection[] = $textRun;
|
|
|
|
|
return $textRun;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a Table Element
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $style
|
2014-03-31 01:13:02 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Element\Table
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function addTable($style = null)
|
|
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
$table = new Table('footer', $this->_footerCount, $style);
|
2013-12-16 06:40:30 -05:00
|
|
|
$this->_elementCollection[] = $table;
|
|
|
|
|
return $table;
|
2013-12-15 12:56:40 +01:00
|
|
|
}
|
2013-12-16 06:40:30 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a Image Element
|
|
|
|
|
*
|
|
|
|
|
* @param string $src
|
|
|
|
|
* @param mixed $style
|
2014-03-31 01:13:02 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Element\Image
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function addImage($src, $style = null)
|
|
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
$image = new Image($src, $style);
|
2013-12-16 06:40:30 -05:00
|
|
|
if (!is_null($image->getSource())) {
|
2014-03-24 16:24:50 +07:00
|
|
|
$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
|
2014-03-24 16:24:50 +07:00
|
|
|
* @deprecated
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-24 16:24:50 +07:00
|
|
|
public function addMemoryImage($src, $style = null)
|
2013-12-16 06:40:30 -05:00
|
|
|
{
|
2014-03-24 16:24:50 +07: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
|
2014-03-31 01:13:02 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Element\PreserveText
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
|
|
|
|
|
{
|
2014-03-23 17:37:26 +07:00
|
|
|
if (!String::isUTF8($text)) {
|
2013-12-16 06:40:30 -05:00
|
|
|
$text = utf8_encode($text);
|
|
|
|
|
}
|
2014-03-22 10:06:08 +04:00
|
|
|
$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;
|
2013-12-15 12:56:40 +01:00
|
|
|
}
|
2014-03-11 19:26:56 +07:00
|
|
|
}
|