72 lines
2.2 KiB
PHP
Raw Normal View History

<?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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\PhpWord\Element\SDT as SDTElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Structured document tag element writer
*
* @since 0.12.0
* @link http://www.datypic.com/sc/ooxml/t-w_CT_SdtBlock.html
*/
class SDT extends Text
{
/**
* Write element
*/
public function write()
{
$xmlWriter = $this->getXmlWriter();
$element = $this->getElement();
if (!$element instanceof SDTElement) {
return;
}
$type = $element->getType();
$listItems = $element->getListItems();
$this->startElementP();
$xmlWriter->startElement('w:sdt');
$xmlWriter->startElement('w:sdtPr');
$xmlWriter->writeElementBlock('w:id', 'w:val', rand(100000000, 999999999));
$xmlWriter->writeElementBlock('w:lock', 'w:val', 'sdtLocked');
$xmlWriter->startElement('w:placeholder');
$xmlWriter->writeElementBlock('w:docPart', 'w:val', 'string');
$xmlWriter->endElement(); // w:placeholder
$xmlWriter->startElement("w:{$type}");
foreach ($listItems as $key => $val) {
$xmlWriter->writeElementBlock('w:listItem', array('w:value' => $key, 'w:displayText' => $val));
}
$xmlWriter->endElement(); // w:{$type}
$xmlWriter->endElement(); // w:sdtPr
$xmlWriter->startElement('w:sdtContent');
$xmlWriter->endElement(); // w:sdtContent
$xmlWriter->endElement(); // w:sdt
$this->endElementP(); // w:p
}
}