|
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 |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct($choice = null) |
|
46
|
|
|
{ |
|
47
|
|
|
parent::__construct(\is_string($choice) |
|
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
|
|
|
$el->appendChild($this->getCaption()->toDOMElement($doc)); |
|
64
|
|
|
} |
|
65
|
|
|
foreach ($this->getTags() as $tag) { |
|
66
|
|
|
$el->appendChild($tag->toDOMElement($doc)); |
|
67
|
|
|
} |
|
68
|
|
|
if ($this->hasContent()) { |
|
69
|
|
|
$el->appendChild($doc->createTextNode($this->getContent())); |
|
70
|
|
|
} |
|
71
|
|
|
return $el; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return bool |
|
76
|
|
|
*/ |
|
77
|
|
|
public function hasCaption(): bool |
|
78
|
|
|
{ |
|
79
|
|
|
return null !== $this->caption; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return Caption |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getCaption(): Caption |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->caption; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param Caption $caption |
|
92
|
|
|
* |
|
93
|
|
|
* @return self |
|
94
|
|
|
*/ |
|
95
|
|
|
public function setCaption(Caption $caption): self |
|
96
|
|
|
{ |
|
97
|
|
|
$this->caption = $caption; |
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
protected function canAddTag($choice): bool |
|
102
|
|
|
{ |
|
103
|
|
|
return ($choice |
|
104
|
|
|
&& ($choice instanceof LinkHtml |
|
105
|
|
|
|| $choice instanceof Sub |
|
106
|
|
|
|| $choice instanceof Sup |
|
107
|
|
|
|| $choice instanceof Br |
|
108
|
|
|
|| $choice instanceof Footnote |
|
109
|
|
|
|| $choice instanceof FootNoteRef |
|
110
|
|
|
|| $choice instanceof RenderMultiMedia)); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function getElementTag(): string |
|
117
|
|
|
{ |
|
118
|
|
|
return 'paragraph'; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|