2012-05-06 18:25:40 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-03-22 10:06:08 +04:00
|
|
|
* PhpWord
|
2012-05-06 18:25:40 +02:00
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* Copyright (c) 2014 PhpWord
|
2012-05-06 18:25:40 +02:00
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* @copyright Copyright (c) 2014 PhpWord
|
2012-05-06 18:25:40 +02:00
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
2014-03-15 16:17:05 +07:00
|
|
|
* @version 0.8.0
|
2012-05-06 18:25:40 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
namespace PhpOffice\PhpWord\Section;
|
2013-12-16 06:40:30 -05:00
|
|
|
|
2014-03-23 10:32:08 +04:00
|
|
|
use PhpOffice\PhpWord\Exceptions\Exception;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\Media;
|
|
|
|
|
use PhpOffice\PhpWord\Section\Footer\PreserveText;
|
|
|
|
|
use PhpOffice\PhpWord\Shared\String;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($sectionCount)
|
|
|
|
|
{
|
|
|
|
|
$this->_footerCount = $sectionCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a Text Element
|
|
|
|
|
*
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @param mixed $styleFont
|
|
|
|
|
* @param mixed $styleParagraph
|
2014-03-23 10:32:08 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Section\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-23 10:32:08 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Section\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-23 10:32:08 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Section\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-23 10:32:08 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Section\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-22 10:06:08 +04:00
|
|
|
$rID = Media::addFooterMediaElement($this->_footerCount, $src);
|
2013-12-16 06:40:30 -05:00
|
|
|
$image->setRelationId($rID);
|
|
|
|
|
|
|
|
|
|
$this->_elementCollection[] = $image;
|
|
|
|
|
return $image;
|
|
|
|
|
} else {
|
2014-03-13 02:08:31 +07:00
|
|
|
throw new Exception('Src does not exist or invalid image type.');
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a by PHP created Image Element
|
|
|
|
|
*
|
|
|
|
|
* @param string $link
|
|
|
|
|
* @param mixed $style
|
2014-03-23 10:32:08 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Section\MemoryImage
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function addMemoryImage($link, $style = null)
|
|
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
$memoryImage = new MemoryImage($link, $style);
|
2013-12-16 06:40:30 -05:00
|
|
|
if (!is_null($memoryImage->getSource())) {
|
2014-03-22 10:06:08 +04:00
|
|
|
$rID = Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
|
2013-12-16 06:40:30 -05:00
|
|
|
$memoryImage->setRelationId($rID);
|
|
|
|
|
|
|
|
|
|
$this->_elementCollection[] = $memoryImage;
|
|
|
|
|
return $memoryImage;
|
|
|
|
|
} else {
|
2014-03-13 02:08:31 +07:00
|
|
|
throw new Exception('Unsupported image type.');
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a PreserveText Element
|
|
|
|
|
*
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @param mixed $styleFont
|
|
|
|
|
* @param mixed $styleParagraph
|
2014-03-23 10:32:08 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Section\Footer\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
|
|
|
}
|