| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Web\Common; |
| 4 |
|
| 5 |
use ipl\Html\Attributes; |
| 6 |
use ipl\Html\BaseHtmlElement; |
| 7 |
use ipl\Html\HtmlElement; |
| 8 |
use ipl\Web\Widget\ItemList; |
| 9 |
|
| 10 |
/** |
| 11 |
* Base class for list items |
| 12 |
* |
| 13 |
* @deprecated Use a {@see ItemList} with a dedicated {@see ItemRenderer} instead. |
| 14 |
*/ |
| 15 |
abstract class BaseListItem extends BaseHtmlElement |
| 16 |
{ |
| 17 |
/** @var array<string, mixed> */ |
| 18 |
protected $baseAttributes = ['class' => ['list-item', 'item-layout', 'default-item-layout']]; |
| 19 |
|
| 20 |
/** @var object The associated list item */ |
| 21 |
protected $item; |
| 22 |
|
| 23 |
/** @var BaseItemList The list where the item is part of */ |
| 24 |
protected $list; |
| 25 |
|
| 26 |
protected $tag = 'li'; |
| 27 |
|
| 28 |
/** |
| 29 |
* Create a new list item |
| 30 |
* |
| 31 |
* @param object $item |
| 32 |
* @param BaseItemList $list |
| 33 |
*/ |
| 34 |
public function __construct($item, BaseItemList $list) |
| 35 |
{ |
| 36 |
$this->item = $item; |
| 37 |
$this->list = $list; |
| 38 |
|
| 39 |
$this->addAttributes($this->baseAttributes); |
| 40 |
|
| 41 |
$this->init(); |
| 42 |
} |
| 43 |
|
| 44 |
abstract protected function assembleHeader(BaseHtmlElement $header): void; |
| 45 |
|
| 46 |
abstract protected function assembleMain(BaseHtmlElement $main): void; |
| 47 |
|
| 48 |
protected function assembleFooter(BaseHtmlElement $footer): void |
| 49 |
{ |
| 50 |
} |
| 51 |
|
| 52 |
protected function assembleCaption(BaseHtmlElement $caption): void |
| 53 |
{ |
| 54 |
} |
| 55 |
|
| 56 |
protected function assembleTitle(BaseHtmlElement $title): void |
| 57 |
{ |
| 58 |
} |
| 59 |
|
| 60 |
protected function assembleVisual(BaseHtmlElement $visual): void |
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
protected function createCaption(): BaseHtmlElement |
| 65 |
{ |
| 66 |
$caption = new HtmlElement('section', Attributes::create(['class' => 'caption'])); |
| 67 |
|
| 68 |
$this->assembleCaption($caption); |
| 69 |
|
| 70 |
return $caption; |
| 71 |
} |
| 72 |
|
| 73 |
protected function createHeader(): BaseHtmlElement |
| 74 |
{ |
| 75 |
$header = new HtmlElement('header'); |
| 76 |
|
| 77 |
$this->assembleHeader($header); |
| 78 |
|
| 79 |
return $header; |
| 80 |
} |
| 81 |
|
| 82 |
protected function createMain(): BaseHtmlElement |
| 83 |
{ |
| 84 |
$main = new HtmlElement('div', Attributes::create(['class' => 'main'])); |
| 85 |
|
| 86 |
$this->assembleMain($main); |
| 87 |
|
| 88 |
return $main; |
| 89 |
} |
| 90 |
|
| 91 |
protected function createFooter(): ?BaseHtmlElement |
| 92 |
{ |
| 93 |
$footer = new HtmlElement('footer'); |
| 94 |
|
| 95 |
$this->assembleFooter($footer); |
| 96 |
if ($footer->isEmpty()) { |
| 97 |
return null; |
| 98 |
} |
| 99 |
|
| 100 |
return $footer; |
| 101 |
} |
| 102 |
|
| 103 |
protected function createTimestamp(): ?BaseHtmlElement |
| 104 |
{ |
| 105 |
return null; |
| 106 |
} |
| 107 |
|
| 108 |
protected function createTitle(): BaseHtmlElement |
| 109 |
{ |
| 110 |
$title = new HtmlElement('div', Attributes::create(['class' => 'title'])); |
| 111 |
|
| 112 |
$this->assembleTitle($title); |
| 113 |
|
| 114 |
return $title; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* @return ?BaseHtmlElement |
| 119 |
*/ |
| 120 |
protected function createVisual(): ?BaseHtmlElement |
| 121 |
{ |
| 122 |
$visual = new HtmlElement('div', Attributes::create(['class' => 'visual'])); |
| 123 |
|
| 124 |
$this->assembleVisual($visual); |
| 125 |
if ($visual->isEmpty()) { |
| 126 |
return null; |
| 127 |
} |
| 128 |
|
| 129 |
return $visual; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Initialize the list item |
| 134 |
* |
| 135 |
* If you want to adjust the list item after construction, override this method. |
| 136 |
*/ |
| 137 |
protected function init(): void |
| 138 |
{ |
| 139 |
} |
| 140 |
|
| 141 |
protected function assemble(): void |
| 142 |
{ |
| 143 |
$this->add([ |
| 144 |
$this->createVisual(), |
| 145 |
$this->createMain() |
| 146 |
]); |
| 147 |
} |
| 148 |
} |