/**
  * Add header/footer content.
  *
  * @param \PhpOffice\PhpWord\Element\Section &$section
  * @param \PhpOffice\PhpWord\Shared\ZipArchive $zip
  * @param string $elmType header|footer
  * @param integer &$rId
  * @return void
  */
 private function addHeaderFooterContent(Section &$section, ZipArchive $zip, $elmType, &$rId)
 {
     $getFunction = $elmType == 'header' ? 'getHeaders' : 'getFooters';
     $elmCount = ($section->getSectionId() - 1) * 3;
     $elements = $section->{$getFunction}();
     foreach ($elements as &$element) {
         /** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
         $elmCount++;
         $element->setRelationId(++$rId);
         $elmFile = "{$elmType}{$elmCount}.xml";
         // e.g. footer1.xml
         $this->contentTypes['override']["/word/{$elmFile}"] = $elmType;
         $this->relationships[] = array('target' => $elmFile, 'type' => $elmType, 'rID' => $rId);
         /** @var \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart $writerPart Type hint */
         $writerPart = $this->getWriterPart($elmType)->setElement($element);
         $zip->addFromString("word/{$elmFile}", $writerPart->write());
     }
 }
Esempio n. 2
0
 /**
  * Add header/footer content
  *
  * @param mixed $objZip
  * @param string $elmType
  * @param integer $rId
  */
 private function addHeaderFooterContent(Section &$section, $objZip, $elmType, &$rId)
 {
     $getFunction = $elmType == 'header' ? 'getHeaders' : 'getFooters';
     $writeFunction = $elmType == 'header' ? 'writeHeader' : 'writeFooter';
     $elmCount = ($section->getSectionId() - 1) * 3;
     $elmObjects = $section->{$getFunction}();
     foreach ($elmObjects as &$elmObject) {
         $elmCount++;
         $elmObject->setRelationId(++$rId);
         $elmFile = "{$elmType}{$elmCount}.xml";
         $objZip->addFromString("word/{$elmFile}", $this->getWriterPart($elmType)->{$writeFunction}($elmObject));
         $this->cTypes['override']["/word/{$elmFile}"] = $elmType;
         $this->docRels[] = array('target' => $elmFile, 'type' => $elmType, 'rID' => $rId);
     }
 }