PHPWord/src/PhpWord/Section/Footer.php

212 lines
5.1 KiB
PHP
Raw Normal View History

2012-05-06 18:25:40 +02:00
<?php
/**
* PHPWord
2012-05-06 18:25:40 +02: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
*
* @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
* @version 0.9.0
2012-05-06 18:25:40 +02:00
*/
namespace PhpOffice\PhpWord\Section;
2013-12-16 06:40:30 -05:00
2014-03-25 17:53:10 +07:00
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
/**
* 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\Section\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\Section\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\Section\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\Section\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
*
* @param string $link
* @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\Section\Footer\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;
}
}