Debian Codegraph @

vendor/ipl/web/src/Common/BaseTableRowItem.php

raw
1 <?php
2
3 namespace ipl\Web\Common;
4
5 use ipl\Html\Attributes;
6 use ipl\Html\BaseHtmlElement;
7 use ipl\Html\Html;
8 use ipl\Html\HtmlDocument;
9 use ipl\Html\HtmlElement;
10 use ipl\Web\Widget\ItemTable;
11
12 /** @deprecated Use a {@see ItemTable} with a dedicated {@see ItemRenderer} instead. */
13 abstract class BaseTableRowItem extends BaseHtmlElement
14 {
15 /** @var array<string, mixed> */
16 protected $baseAttributes = ['class' => ['table-row', 'item-layout', 'default-item-layout']];
17
18 /** @var object The associated list item */
19 protected $item;
20
21 /** @var ?BaseItemTable The list where the item is part of */
22 protected $table;
23
24 protected $tag = 'li';
25
26 /**
27 * Create a new table row item
28 *
29 * @param object $item
30 * @param BaseItemTable|null $table
31 */
32 public function __construct($item, ?BaseItemTable $table = null)
33 {
34 $this->item = $item;
35 $this->table = $table;
36
37 if ($table === null) {
38 $this->setTag('div');
39 }
40
41 $this->addAttributes($this->baseAttributes);
42
43 $this->init();
44 }
45
46 abstract protected function assembleTitle(BaseHtmlElement $title): void;
47
48 protected function assembleColumns(HtmlDocument $columns): void
49 {
50 }
51
52 protected function assembleVisual(BaseHtmlElement $visual): void
53 {
54 }
55
56 /**
57 * Create column
58 *
59 * @param mixed $content
60 *
61 * @return BaseHtmlElement
62 */
63 protected function createColumn($content = null): BaseHtmlElement
64 {
65 return new HtmlElement(
66 'div',
67 Attributes::create(['class' => 'col']),
68 new HtmlElement(
69 'div',
70 Attributes::create(['class' => 'column-content']),
71 ...Html::wantHtmlList($content)
72 )
73 );
74 }
75
76 protected function createColumns(): HtmlDocument
77 {
78 $columns = new HtmlDocument();
79
80 $this->assembleColumns($columns);
81
82 return $columns;
83 }
84
85 protected function createTitle(): BaseHtmlElement
86 {
87 $title = $this->createColumn()->addAttributes(['class' => 'title']);
88
89 $this->assembleTitle($title->getFirst('div'));
90
91 $title->prepend($this->createVisual());
92
93 return $title;
94 }
95
96 protected function createVisual(): ?BaseHtmlElement
97 {
98 $visual = new HtmlElement('div', Attributes::create(['class' => 'visual']));
99
100 $this->assembleVisual($visual);
101
102 return $visual->isEmpty() ? null : $visual;
103 }
104
105 /**
106 * Initialize the list item
107 *
108 * If you want to adjust the list item after construction, override this method.
109 */
110 protected function init(): void
111 {
112 }
113
114 protected function assemble(): void
115 {
116 $this->addHtml(
117 $this->createTitle(),
118 $this->createColumns()
119 );
120 }
121 }