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;
|
|
|
|
|
|
|
|
|
|
use PhpOffice\PhpWord\TOC;
|
|
|
|
|
use PhpOffice\PhpWord\Container\Footer;
|
|
|
|
|
use PhpOffice\PhpWord\Container\Header;
|
2014-03-31 23:10:51 +07:00
|
|
|
use PhpOffice\PhpWord\Container\Settings;
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Element\PageBreak;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Section
|
|
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
class Section extends Container
|
2013-12-16 06:40:30 -05:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Section settings
|
|
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @var Settings
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
private $settings;
|
2013-12-16 06:40:30 -05:00
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Section headers
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @var Header[]
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
private $headers = array();
|
2013-12-16 06:40:30 -05:00
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Section footer
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @var Footer
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
private $footer = null;
|
2013-12-16 06:40:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Create new instance
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
|
|
|
|
* @param int $sectionCount
|
2014-04-03 10:13:13 +07:00
|
|
|
* @param array $settings
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function __construct($sectionCount, $settings = null)
|
|
|
|
|
{
|
2014-04-02 09:01:44 +07:00
|
|
|
$this->container = 'section';
|
|
|
|
|
$this->containerId = $sectionCount;
|
2014-04-05 00:08:00 +07:00
|
|
|
$this->setDocPart($this->container, $this->containerId);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->settings = new Settings();
|
2014-03-11 16:27:42 +07:00
|
|
|
$this->setSettings($settings);
|
|
|
|
|
}
|
2013-12-16 06:40:30 -05:00
|
|
|
|
2014-03-11 16:27:42 +07:00
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Set section settings
|
2014-03-11 16:27:42 +07:00
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @param array $settings
|
2014-03-11 16:27:42 +07:00
|
|
|
*/
|
|
|
|
|
public function setSettings($settings = null)
|
|
|
|
|
{
|
2013-12-16 06:40:30 -05:00
|
|
|
if (!is_null($settings) && is_array($settings)) {
|
|
|
|
|
foreach ($settings as $key => $value) {
|
|
|
|
|
if (substr($key, 0, 1) != '_') {
|
|
|
|
|
$key = '_' . $key;
|
|
|
|
|
}
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->settings->setSettingValue($key, $value);
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Section Settings
|
|
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @return Settings
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function getSettings()
|
|
|
|
|
{
|
2014-03-31 23:10:51 +07:00
|
|
|
return $this->settings;
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a PageBreak Element
|
|
|
|
|
*/
|
|
|
|
|
public function addPageBreak()
|
|
|
|
|
{
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->elements[] = new PageBreak();
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a Table-of-Contents Element
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $styleFont
|
|
|
|
|
* @param mixed $styleTOC
|
2014-03-31 23:10:51 +07:00
|
|
|
* @return TOC
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function addTOC($styleFont = null, $styleTOC = null)
|
|
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
$toc = new TOC($styleFont, $styleTOC);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->elements[] = $toc;
|
2013-12-16 06:40:30 -05:00
|
|
|
return $toc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Add header
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @return Header
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
public function addHeader()
|
2013-12-16 06:40:30 -05:00
|
|
|
{
|
2014-04-02 09:01:44 +07:00
|
|
|
$header = new Header($this->containerId);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->headers[] = $header;
|
|
|
|
|
return $header;
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Add footer
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @return Footer
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
public function addFooter()
|
2013-12-16 06:40:30 -05:00
|
|
|
{
|
2014-04-02 09:01:44 +07:00
|
|
|
$footer = new Footer($this->containerId);
|
2014-03-31 23:10:51 +07:00
|
|
|
$this->footer = $footer;
|
|
|
|
|
return $footer;
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Get Headers
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-04-03 10:13:13 +07:00
|
|
|
* @return Header[]
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
public function getHeaders()
|
2013-12-16 06:40:30 -05:00
|
|
|
{
|
2014-03-31 23:10:51 +07:00
|
|
|
return $this->headers;
|
2013-12-15 12:56:40 +01:00
|
|
|
}
|
2013-12-16 06:40:30 -05:00
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Get footer element
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @return Footer
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
public function getFooter()
|
2013-12-16 06:40:30 -05:00
|
|
|
{
|
2014-03-31 23:10:51 +07:00
|
|
|
return $this->footer;
|
2013-12-16 06:40:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is there a header for this section that is for the first page only?
|
|
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* If any of the Header instances have a type of Header::FIRST then this method returns true.
|
|
|
|
|
* False otherwise.
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-03-31 23:10:51 +07:00
|
|
|
* @return boolean
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
|
|
|
|
public function hasDifferentFirstPage()
|
|
|
|
|
{
|
2014-03-31 23:10:51 +07:00
|
|
|
$value = array_filter($this->headers, function (Header &$header) {
|
2014-03-22 10:06:08 +04:00
|
|
|
return $header->getType() == Header::FIRST;
|
2013-12-16 06:40:30 -05:00
|
|
|
});
|
|
|
|
|
return count($value) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Create header
|
2013-12-16 06:40:30 -05:00
|
|
|
*
|
2014-04-05 00:08:00 +07:00
|
|
|
* @return Header
|
2014-03-31 23:10:51 +07:00
|
|
|
* @deprecated 0.9.2
|
2014-04-03 11:34:06 +07:00
|
|
|
* @codeCoverageIgnore
|
2013-12-16 06:40:30 -05:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
public function createHeader()
|
2014-03-11 19:26:56 +07:00
|
|
|
{
|
2014-03-31 23:10:51 +07:00
|
|
|
return $this->addHeader();
|
2014-03-07 23:08:09 +01:00
|
|
|
}
|
2014-03-30 01:30:25 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:10:51 +07:00
|
|
|
* Create footer
|
2014-03-30 01:30:25 +07:00
|
|
|
*
|
2014-04-05 00:08:00 +07:00
|
|
|
* @return Footer
|
2014-03-31 23:10:51 +07:00
|
|
|
* @deprecated 0.9.2
|
2014-04-03 11:34:06 +07:00
|
|
|
* @codeCoverageIgnore
|
2014-03-30 01:30:25 +07:00
|
|
|
*/
|
2014-03-31 23:10:51 +07:00
|
|
|
public function createFooter()
|
2014-03-30 01:30:25 +07:00
|
|
|
{
|
2014-03-31 23:10:51 +07:00
|
|
|
return $this->addFooter();
|
2014-03-30 01:30:25 +07:00
|
|
|
}
|
2014-03-23 17:37:26 +07:00
|
|
|
}
|