Skip to content

Commit

Permalink
Merge 46616a6 into 8fbd060
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-BF committed Sep 5, 2019
2 parents 8fbd060 + 46616a6 commit c08601b
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/PhpWord/Writer/RTF/Part/Document.php
Expand Up @@ -121,10 +121,26 @@ private function writeSections()

$sections = $this->getParentWriter()->getPhpWord()->getSections();
foreach ($sections as $section) {
// Write styles
$styleWriter = new SectionStyleWriter($section->getStyle());
$styleWriter->setParentWriter($this->getParentWriter());
$content .= $styleWriter->write();

// Append headers / footers
$sectionParts = array('Header', 'Footer');
foreach ($sectionParts as $sectionPart) {
$getFunction = 'get' . $sectionPart . 's';
$className = 'PhpOffice\\PhpWord\\Writer\\RTF\\Part\\Section' . $sectionPart;
$parts = $section->$getFunction();
foreach ($parts as $part) {
$partWriter = new $className();
$partWriter->setParentWriter($this->getParentWriter());
$partWriter->setElement($part);
$content .= $partWriter->write();
}
}

// Write content
$elementWriter = new Container($this->getParentWriter(), $section);
$content .= $elementWriter->write();

Expand Down
78 changes: 78 additions & 0 deletions src/PhpWord/Writer/RTF/Part/SectionFooter.php
@@ -0,0 +1,78 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2019 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\RTF\Part;

use PhpOffice\PhpWord\Element\Footer;
use PhpOffice\PhpWord\Writer\RTF\Element\Container;

/**
* RTF page footer writer
*/
class SectionFooter extends AbstractPart
{
/**
* Root element name
*
* @var string
*/
protected $rootElement = '\footer';

/**
* Footer/header element to be written
*
* @var \PhpOffice\PhpWord\Element\Footer|\PhpOffice\PhpWord\Element\Header
*/
protected $element;

/**
* Write part
*
* @return string
*/
public function write()
{
$content = '{';
$content .= $this->rootElement;
$type = $this->element->getType();
if ($type == Footer::FIRST) {
$content .= 'f';
} elseif ($type == Footer::EVEN) {
$content .= 'r';
}

$containerWriter = new Container($this->getParentWriter(), $this->element);
$content .= $containerWriter->write();

$content .= '}' . PHP_EOL;

return $content;
}

/**
* Set element
*
* @param \PhpOffice\PhpWord\Element\Footer|\PhpOffice\PhpWord\Element\Header $element
* @return self
*/
public function setElement($element)
{
$this->element = $element;

return $this;
}
}
31 changes: 31 additions & 0 deletions src/PhpWord/Writer/RTF/Part/SectionHeader.php
@@ -0,0 +1,31 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2019 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\RTF\Part;

/**
* RTF page header writer
*/
class SectionHeader extends SectionFooter
{
/**
* Root element name
*
* @var string
*/
protected $rootElement = '\header';
}

0 comments on commit c08601b

Please sign in to comment.