Esempio n. 1
0
 /**
  * Set relation Id
  *
  * @param string $elementName
  * @param string $source
  */
 private function setElementRelationId(AbstractElement $element, $elementName, $source)
 {
     $mediaContainer = $this->getMediaContainer();
     $hasMediaRelation = in_array($elementName, array('Link', 'Image', 'Object'));
     $hasOtherRelation = in_array($elementName, array('Footnote', 'Endnote', 'Title'));
     // Set relation Id for media elements (link, image, object; legacy of OOXML)
     // Only Image that needs to be passed to Media class
     if ($hasMediaRelation) {
         /** @var \PhpOffice\PhpWord\Element\Image $element Type hint */
         $image = $elementName == 'Image' ? $element : null;
         $rId = Media::addElement($mediaContainer, strtolower($elementName), $source, $image);
         $element->setRelationId($rId);
     }
     // Set relation Id for icon of object element
     if ($elementName == 'Object') {
         /** @var \PhpOffice\PhpWord\Element\Object $element Type hint */
         $rIdIcon = Media::addElement($mediaContainer, 'image', $element->getIcon(), new Image($element->getIcon()));
         $element->setImageRelationId($rIdIcon);
     }
     // Set relation Id for elements that will be registered in the Collection subnamespaces
     if ($hasOtherRelation && $this->phpWord instanceof PhpWord) {
         $addMethod = "add{$elementName}";
         $rId = $this->phpWord->{$addMethod}($element);
         $element->setRelationId($rId);
     }
 }
Esempio n. 2
0
 /**
  * Set element index and unique id, and add element into elements collection
  */
 protected function addElement(AbstractElement $element)
 {
     $element->setElementIndex($this->countElements() + 1);
     $element->setElementId();
     $this->elements[] = $element;
 }