pgee70 /
cda
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * The MIT License |
||
| 4 | * |
||
| 5 | * Copyright 2017 Julien Fastré <[email protected]>. |
||
| 6 | * |
||
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
| 8 | * of this software and associated documentation files (the "Software"), to deal |
||
| 9 | * in the Software without restriction, including without limitation the rights |
||
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
| 11 | * copies of the Software, and to permit persons to whom the Software is |
||
| 12 | * furnished to do so, subject to the following conditions: |
||
| 13 | * |
||
| 14 | * The above copyright notice and this permission notice shall be included in |
||
| 15 | * all copies or substantial portions of the Software. |
||
| 16 | * |
||
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE |
||
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
| 23 | * THE SOFTWARE. |
||
| 24 | */ |
||
| 25 | |||
| 26 | namespace i3Soft\CDA\Elements\Html; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Class Paragraph |
||
| 30 | * |
||
| 31 | * @package i3Soft\CDA\Elements |
||
| 32 | * there can be 0 or 1 caption tags, and 0 or more of the other tags. |
||
| 33 | * there can be an optional text element. |
||
| 34 | */ |
||
| 35 | class Paragraph extends AbstractHtmlElement |
||
| 36 | { |
||
| 37 | /** @var Caption */ |
||
| 38 | protected $caption; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Paragraph constructor. |
||
| 42 | * |
||
| 43 | * @param null $choice |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 44 | */ |
||
| 45 | public function __construct ($choice = NULL) |
||
| 46 | { |
||
| 47 | parent::__construct(\is_string($choice) |
||
|
0 ignored issues
–
show
|
|||
| 48 | ? $choice |
||
| 49 | : ''); |
||
| 50 | $this->addTag($choice); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param \DOMDocument $doc |
||
| 55 | * |
||
| 56 | * @return \DOMElement |
||
| 57 | */ |
||
| 58 | public function toDOMElement (\DOMDocument $doc): \DOMElement |
||
| 59 | { |
||
| 60 | $el = $this->createElement($doc); |
||
| 61 | |||
| 62 | if ($this->hasCaption()) |
||
| 63 | { |
||
| 64 | $el->appendChild($this->getCaption()->toDOMElement($doc)); |
||
| 65 | } |
||
| 66 | foreach ($this->getTags() as $tag) |
||
| 67 | { |
||
| 68 | $el->appendChild($tag->toDOMElement($doc)); |
||
| 69 | } |
||
| 70 | if ($this->hasContent()) |
||
| 71 | { |
||
| 72 | $el->appendChild($doc->createTextNode($this->getContent())); |
||
| 73 | } |
||
| 74 | return $el; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @return bool |
||
| 79 | */ |
||
| 80 | public function hasCaption (): bool |
||
| 81 | { |
||
| 82 | return NULL !== $this->caption; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return Caption |
||
| 87 | */ |
||
| 88 | public function getCaption (): Caption |
||
| 89 | { |
||
| 90 | return $this->caption; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param Caption $caption |
||
| 95 | * |
||
| 96 | * @return self |
||
| 97 | */ |
||
| 98 | public function setCaption (Caption $caption): self |
||
| 99 | { |
||
| 100 | $this->caption = $caption; |
||
| 101 | return $this; |
||
| 102 | } |
||
| 103 | |||
| 104 | protected function canAddTag ($choice): bool |
||
| 105 | { |
||
| 106 | return ($choice |
||
| 107 | && ($choice instanceof LinkHtml |
||
| 108 | || $choice instanceof Sub |
||
| 109 | || $choice instanceof Sup |
||
| 110 | || $choice instanceof Br |
||
| 111 | || $choice instanceof Footnote |
||
| 112 | || $choice instanceof FootNoteRef |
||
| 113 | || $choice instanceof RenderMultiMedia)); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | protected function getElementTag (): string |
||
| 120 | { |
||
| 121 | return 'paragraph'; |
||
| 122 | } |
||
| 123 | |||
| 124 | |||
| 125 | } |
||
| 126 |