Skip to content

Commit b1a5595

Browse files
committed
Align with changes in plaisio/helper-html.
1 parent ec10738 commit b1a5595

27 files changed

+469
-285
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
"plaisio-ts/helper-cast": "^1.0.2",
1212
"plaisio/babel": "^2.0.1",
1313
"plaisio/helper-css": "^1.1.0",
14-
"plaisio/helper-html": "^3.0.0",
14+
"plaisio/helper-html": "^4.0.0",
1515
"plaisio/kernel": "^3.1.1",
1616
"plaisio/web-assets": "^2.0.0",
1717
"setbased/exception": "^2.2.0"
1818
},
1919
"require-dev": {
2020
"phing/phing": "^2.17.0",
21-
"phpunit/phpunit": "^9.5.10",
22-
"plaisio/console": "^2.4.9"
21+
"phpunit/phpunit": "^9.5.11",
22+
"plaisio/console": "^2.5.0"
2323
},
2424
"autoload": {
2525
"psr-4": {

src/OverviewTable.php

Lines changed: 99 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -133,36 +133,6 @@ public function enableFilter(): void
133133
$this->filter = true;
134134
}
135135

136-
//--------------------------------------------------------------------------------------------------------------------
137-
/**
138-
* Returns the HTML code of this table
139-
*
140-
* @param array[] $rows The data shown in the table.
141-
*
142-
* @return string
143-
*/
144-
public function getHtmlTable(array $rows): string
145-
{
146-
$this->prepare();
147-
148-
$ret = $this->getHtmlPrefix();
149-
150-
$ret .= Html::generateTag('table', $this->attributes);
151-
152-
$ret .= $this->getHtmlColGroup();
153-
$ret .= $this->getHtmlHeader();
154-
$ret .= $this->getHtmlBody($rows);
155-
$ret .= $this->getHtmlFooter();
156-
157-
$ret .= '</table>';
158-
159-
$ret .= $this->getHtmlPostfix();
160-
161-
$this->generateResponsiveCss();
162-
163-
return $ret;
164-
}
165-
166136
//--------------------------------------------------------------------------------------------------------------------
167137
/**
168138
* Returns the total number of columns of this table.
@@ -185,6 +155,30 @@ public function getTitle(): string
185155
return $this->title;
186156
}
187157

158+
//--------------------------------------------------------------------------------------------------------------------
159+
/**
160+
* Returns the HTML code of this table.
161+
*
162+
* @param array[] $rows The data shown in the table.
163+
*
164+
* @return string
165+
*/
166+
public function htmlTable(array $rows): string
167+
{
168+
$this->prepare();
169+
$this->generateResponsiveCss();
170+
171+
$struct = ['tag' => 'table',
172+
'attr' => $this->attributes,
173+
'inner' => [['html' => $this->htmlPrefix()],
174+
['html' => $this->htmlColGroup()],
175+
['html' => $this->htmlHeader()],
176+
['html' => $this->htmlBody($rows)],
177+
['html' => $this->htmlFooter()]]];
178+
179+
return Html::htmlNested($struct);
180+
}
181+
188182
//--------------------------------------------------------------------------------------------------------------------
189183
/**
190184
* Sets the helper class for generating the table row attributes.
@@ -209,6 +203,17 @@ public function setTitle(string $title): void
209203
$this->title = $title;
210204
}
211205

206+
//--------------------------------------------------------------------------------------------------------------------
207+
/**
208+
* Returns the HTML code inserted before the HTML code of the table.
209+
*
210+
* @return string
211+
*/
212+
protected function getHtmlPostfix(): string
213+
{
214+
return '';
215+
}
216+
212217
//--------------------------------------------------------------------------------------------------------------------
213218
/**
214219
* Returns the inner HTML code of the body for this table holding the rows as data.
@@ -217,23 +222,29 @@ public function setTitle(string $title): void
217222
*
218223
* @return string
219224
*/
220-
protected function getHtmlBody(array $rows): string
225+
protected function htmlBody(array $rows): string
221226
{
222-
$ret = Html::generateTag('tbody', ['class' => $this->renderWalker->getClasses('tbody')]);
223-
$i = 0;
227+
$i = 0;
228+
$htmlRows = '';
224229
foreach ($rows as $row)
225230
{
226-
$ret .= Html::generateTag('tr', $this->tableRow->getRowAttributes($this->renderWalker, $i, $row));
231+
$htmlCells = '';
227232
foreach ($this->columns as $column)
228233
{
229-
$ret .= $column->getHtmlCell($this->renderWalker, $row);
234+
$htmlCells .= $column->htmlCell($this->renderWalker, $row);
230235
}
231-
$ret .= '</tr>';
236+
237+
$htmlRows .= Html::htmlNested(['tag' => 'tr',
238+
'attr' => $this->tableRow->getRowAttributes($this->renderWalker, $i, $row),
239+
'html' => $htmlCells]);
232240
$i++;
233241
}
234-
$ret .= '</tbody>';
235242

236-
return $ret;
243+
$struct = ['tag' => 'tbody',
244+
'attr' => ['class' => $this->renderWalker->getClasses('tbody')],
245+
'html' => $htmlRows];
246+
247+
return Html::htmlNested($struct);
237248
}
238249

239250
//--------------------------------------------------------------------------------------------------------------------
@@ -242,7 +253,7 @@ protected function getHtmlBody(array $rows): string
242253
*
243254
* @return string
244255
*/
245-
protected function getHtmlColGroup(): string
256+
protected function htmlColGroup(): string
246257
{
247258
$ret = '<colgroup>';
248259
foreach ($this->columns as $column)
@@ -253,7 +264,7 @@ protected function getHtmlColGroup(): string
253264
$column->setSortable(false);
254265
}
255266

256-
$ret .= $column->getHtmlCol();
267+
$ret .= $column->htmlCol();
257268
}
258269
$ret .= '</colgroup>';
259270

@@ -266,7 +277,7 @@ protected function getHtmlColGroup(): string
266277
*
267278
* @return string
268279
*/
269-
protected function getHtmlFooter(): string
280+
protected function htmlFooter(): string
270281
{
271282
return '';
272283
}
@@ -277,13 +288,13 @@ protected function getHtmlFooter(): string
277288
*
278289
* @return string
279290
*/
280-
protected function getHtmlHeader(): string
291+
protected function htmlHeader(): string
281292
{
282-
$ret = Html::generateTag('thead', ['class' => $this->renderWalker->getClasses('thead')]);
283-
$ret .= $this->getHtmlInnerHeader();
284-
$ret .= '</thead>';
293+
$struct = ['tag' => 'thead',
294+
'attr' => ['class' => $this->renderWalker->getClasses('thead')],
295+
'html' => $this->htmlInnerHeader()];
285296

286-
return $ret;
297+
return Html::htmlNested($struct);
287298
}
288299

289300
//--------------------------------------------------------------------------------------------------------------------
@@ -292,15 +303,15 @@ protected function getHtmlHeader(): string
292303
*
293304
* @return string
294305
*/
295-
protected function getHtmlInnerHeader(): string
306+
protected function htmlInnerHeader(): string
296307
{
297-
$ret = '';
308+
$struct = [];
298309
if ($this->title!==null)
299310
{
300311
$mode = 1;
301312
$colspan = 0;
302313

303-
$ret .= Html::generateTag('tr', ['class' => $this->renderWalker->getClasses('title')]);
314+
$inner = [];
304315
foreach ($this->columns as $column)
305316
{
306317
$empty = $column->isHeaderEmpty();
@@ -309,7 +320,9 @@ protected function getHtmlInnerHeader(): string
309320
{
310321
if ($empty)
311322
{
312-
$ret .= Html::generateElement('th', ['class' => $this->renderWalker->getClasses('empty-header')]);
323+
$inner[] = ['tag' => 'th',
324+
'attr' => ['class' => $this->renderWalker->getClasses('empty-header')],
325+
'html' => null];
313326
}
314327
else
315328
{
@@ -331,70 +344,73 @@ protected function getHtmlInnerHeader(): string
331344

332345
if ($mode===3)
333346
{
334-
if ($colspan===1) $colspan = null;
335-
$ret .= Html::generateElement('th',
336-
['class' => $this->renderWalker->getClasses('header'),
337-
'colspan' => $colspan],
338-
$this->title);
339-
$mode = 4;
347+
if ($colspan===1)
348+
{
349+
$colspan = null;
350+
}
351+
$inner[] = ['tag' => 'th',
352+
'attr' => ['class' => $this->renderWalker->getClasses('header'),
353+
'colspan' => $colspan],
354+
'text' => $this->title];
355+
$mode = 4;
340356
}
341357

342358
if ($mode===4)
343359
{
344-
$ret .= Html::generateElement('th', ['class' => $this->renderWalker->getClasses('empty-header')]);
360+
$inner[] = ['tag' => 'th',
361+
'attr' => ['class' => $this->renderWalker->getClasses('empty-header')],
362+
'html' => null];
345363
}
346364
}
347365

348366
if ($mode===2)
349367
{
350-
if ($colspan===1) $colspan = null;
351-
$ret .= Html::generateElement('th',
352-
['class' => $this->renderWalker->getClasses('header'),
353-
'colspan' => $colspan],
354-
$this->title);
368+
if ($colspan===1)
369+
{
370+
$colspan = null;
371+
}
372+
$inner[] = ['tag' => 'th',
373+
'attr' => ['class' => $this->renderWalker->getClasses('header'),
374+
'colspan' => $colspan],
375+
'text' => $this->title];
355376
}
356377

357-
$ret .= '</tr>';
378+
$struct[] = ['tag' => 'tr',
379+
'attr' => ['class' => $this->renderWalker->getClasses('title')],
380+
'inner' => $inner];
358381
}
359382

360-
$ret .= Html::generateTag('tr', ['class' => $this->renderWalker->getClasses('header-row')]);
383+
$cells = '';
361384
foreach ($this->columns as $column)
362385
{
363-
$ret .= $column->getHtmlColumnHeader($this->renderWalker);
386+
$cells .= $column->htmlColumnHeader($this->renderWalker);
364387
}
365-
$ret .= '</tr>';
388+
$struct[] = ['tag' => 'tr',
389+
'attr' => ['class' => $this->renderWalker->getClasses('header-row')],
390+
'html' => $cells];
366391

367392
if ($this->filter)
368393
{
369-
$ret .= Html::generateTag('tr', ['class' => $this->renderWalker->getClasses('filter-row')]);
394+
$cells = '';
370395
foreach ($this->columns as $column)
371396
{
372-
$ret .= $column->getHtmlColumnFilter($this->renderWalker);
397+
$cells .= $column->htmlColumnFilter($this->renderWalker);
373398
}
374-
$ret .= '</tr>';
399+
$struct[] = ['tag' => 'tr',
400+
'attr' => ['class' => $this->renderWalker->getClasses('filter-row')],
401+
'html' => $cells];
375402
}
376403

377-
return $ret;
378-
}
379-
380-
//--------------------------------------------------------------------------------------------------------------------
381-
/**
382-
* Returns HTML code inserted before the HTML code of the table.
383-
*
384-
* @return string
385-
*/
386-
protected function getHtmlPostfix(): string
387-
{
388-
return '';
404+
return Html::htmlNested($struct);
389405
}
390406

391407
//--------------------------------------------------------------------------------------------------------------------
392408
/**
393-
* Returns HTML code appended after the HTML code of the table.
409+
* Returns the HTML code appended after the HTML code of the table.
394410
*
395411
* @return string
396412
*/
397-
protected function getHtmlPrefix(): string
413+
protected function htmlPrefix(): string
398414
{
399415
return '';
400416
}

src/TableColumn/ColElement.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class ColElement
2020
*
2121
* @return string
2222
*/
23-
public function getHtmlCol(): string
23+
public function htmlCol(): string
2424
{
25-
return Html::generateVoidElement('col', $this->attributes);
25+
return Html::htmlNested(['tag' => 'col',
26+
'attr' => $this->attributes]);
2627
}
2728

2829
//--------------------------------------------------------------------------------------------------------------------

src/TableColumn/CombinedTableColumn.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,34 @@ public function getHeader(): ?string
8282
/**
8383
* @inheritdoc
8484
*/
85-
public function getHtmlCell(RenderWalker $walker, array $row): string
85+
public function htmlCell(RenderWalker $walker, array $row): string
8686
{
87-
return $this->column1->getHtmlCell($walker, $row).$this->column2->getHtmlCell($walker, $row);
87+
return $this->column1->htmlCell($walker, $row).$this->column2->htmlCell($walker, $row);
8888
}
8989

9090
//--------------------------------------------------------------------------------------------------------------------
9191
/**
9292
* @inheritdoc
9393
*/
94-
public function getHtmlCol(): string
94+
public function htmlCol(): string
9595
{
96-
return $this->column1->getHtmlCol().$this->column2->getHtmlCol();
96+
return $this->column1->htmlCol().$this->column2->htmlCol();
9797
}
9898

9999
//--------------------------------------------------------------------------------------------------------------------
100100
/**
101101
* @inheritdoc
102102
*/
103-
public function getHtmlColumnFilter(RenderWalker $walker): string
103+
public function htmlColumnFilter(RenderWalker $walker): string
104104
{
105-
return $this->column1->getHtmlColumnFilter($walker).$this->column2->getHtmlColumnFilter($walker);
106-
} //--------------------------------------------------------------------------------------------------------------------
105+
return $this->column1->htmlColumnFilter($walker).$this->column2->htmlColumnFilter($walker);
106+
}
107+
108+
//--------------------------------------------------------------------------------------------------------------------
107109
/**
108110
* @inheritdoc
109111
*/
110-
public function getHtmlColumnHeader(RenderWalker $walker): string
112+
public function htmlColumnHeader(RenderWalker $walker): string
111113
{
112114
$attributes = [];
113115
$classes = $walker->getClasses('header');
@@ -143,9 +145,12 @@ public function getHtmlColumnHeader(RenderWalker $walker): string
143145
$attributes['class'] = $classes;
144146
$attributes['colspan'] = 2;
145147

146-
$innerText = '<span>&nbsp;</span>'.($this->headerIsHtml ? $this->header : Html::txt2Html($this->header));
148+
$struct = ['tag' => 'th',
149+
'attr' => $attributes,
150+
'inner' => [['html' => '<span>&nbsp;</span>'],
151+
[($this->headerIsHtml) ? 'html' : 'text' => $this->header]]];
147152

148-
return Html::generateElement('th', $attributes, $innerText, true);
153+
return Html::htmlNested($struct);
149154
}
150155

151156
//--------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)