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 | use i3Soft\CDA\DataType\ReferenceType; |
||
| 29 | use i3Soft\CDA\Elements\AbstractElement; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @author Julien Fastré <[email protected]> |
||
| 33 | */ |
||
| 34 | class TableRow extends AbstractElement |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * |
||
| 38 | * @var TableCell[] |
||
| 39 | */ |
||
| 40 | private $cells; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * a reference to the section this row is attached to |
||
| 44 | * |
||
| 45 | * @var AbstractTableSection |
||
| 46 | */ |
||
| 47 | private $section; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * |
||
| 51 | * @var ReferenceType |
||
| 52 | */ |
||
| 53 | private $reference; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * TableRow constructor. |
||
| 57 | * |
||
| 58 | * @param AbstractTableSection $section |
||
| 59 | */ |
||
| 60 | public function __construct (AbstractTableSection $section = NULL) |
||
| 61 | { |
||
| 62 | $this->section = $section; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * |
||
| 67 | * @param string $content |
||
| 68 | * |
||
| 69 | * @param null $type |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 70 | * |
||
| 71 | * @return TableCell |
||
| 72 | */ |
||
| 73 | public function createCell ($content, $type = NULL): TableCell |
||
| 74 | { |
||
| 75 | if (NULL === $type) |
||
|
0 ignored issues
–
show
|
|||
| 76 | { |
||
| 77 | $type = $this->getSection() instanceof TableHead |
||
| 78 | ? TableCell::TH |
||
| 79 | : TableCell::TD; |
||
| 80 | } |
||
| 81 | $cell = new TableCell( |
||
| 82 | $type, |
||
| 83 | $this, |
||
| 84 | $content); |
||
| 85 | $this->addCell($cell); |
||
| 86 | return $cell; |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return AbstractTableSection |
||
| 91 | */ |
||
| 92 | public function getSection (): AbstractTableSection |
||
| 93 | { |
||
| 94 | return $this->section; |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param AbstractTableSection $section |
||
| 99 | * |
||
| 100 | * @return self |
||
| 101 | */ |
||
| 102 | public function setSection (AbstractTableSection $section): self |
||
| 103 | { |
||
| 104 | $this->section = $section; |
||
| 105 | return $this; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * |
||
| 110 | * @param TableCell $cell |
||
| 111 | * |
||
| 112 | * @return self |
||
| 113 | */ |
||
| 114 | public function addCell (TableCell $cell): self |
||
| 115 | { |
||
| 116 | $cell->setRow($this); |
||
| 117 | |||
| 118 | $this->cells[] = $cell; |
||
| 119 | |||
| 120 | return $this; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * |
||
| 125 | * @return boolean |
||
| 126 | */ |
||
| 127 | public function isEmpty (): bool |
||
| 128 | { |
||
| 129 | return \count($this->getCells()) > 0; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * |
||
| 134 | * @return TableCell[] |
||
| 135 | */ |
||
| 136 | public function getCells (): array |
||
| 137 | { |
||
| 138 | return $this->cells; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @param array $cells |
||
| 143 | * |
||
| 144 | * @return self |
||
| 145 | */ |
||
| 146 | public function setCells (array $cells): self |
||
| 147 | { |
||
| 148 | $this->cells = $cells; |
||
| 149 | return $this; |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param \DOMDocument $doc |
||
| 154 | * |
||
| 155 | * @return \DOMElement |
||
| 156 | */ |
||
| 157 | public function toDOMElement (\DOMDocument $doc): \DOMElement |
||
| 158 | { |
||
| 159 | $el = $this->createElement($doc); |
||
| 160 | |||
| 161 | if ($this->hasReference()) |
||
| 162 | { |
||
| 163 | $this->getReference()->setValueToElement($el, $doc); |
||
| 164 | } |
||
| 165 | |||
| 166 | foreach ($this->getCells() as $cell) |
||
| 167 | { |
||
| 168 | $el->appendChild($cell->toDOMElement($doc)); |
||
| 169 | } |
||
| 170 | |||
| 171 | return $el; |
||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @return bool |
||
| 176 | */ |
||
| 177 | public function hasReference (): bool |
||
| 178 | { |
||
| 179 | return NULL !== $this->reference; |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * |
||
| 184 | * @return ReferenceType |
||
| 185 | */ |
||
| 186 | public function getReference (): ReferenceType |
||
| 187 | { |
||
| 188 | return $this->reference; |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * |
||
| 193 | * @param ReferenceType $reference |
||
| 194 | * |
||
| 195 | * @return self |
||
| 196 | */ |
||
| 197 | public function setReference (ReferenceType $reference): self |
||
| 198 | { |
||
| 199 | $this->reference = $reference; |
||
| 200 | |||
| 201 | return $this; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | protected function getElementTag (): string |
||
| 208 | { |
||
| 209 | return 'tr'; |
||
| 210 | } |
||
| 211 | } |
||
| 212 |