2023-12-03 22:10:18 +04:00
|
|
|
<?php
|
|
|
|
namespace nur\v\bs3\vc;
|
|
|
|
|
|
|
|
use nur\b\params\Tparametrable;
|
|
|
|
use nur\b\ValueException;
|
2024-06-26 11:18:44 +04:00
|
|
|
use nur\func;
|
2023-12-03 22:10:18 +04:00
|
|
|
use nur\v\vo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CListGroup: afficher une liste d'éléments
|
|
|
|
*/
|
|
|
|
class CListGroup extends _CItemList {
|
|
|
|
use Tparametrable;
|
|
|
|
|
|
|
|
const CONTAINER = null;
|
|
|
|
|
|
|
|
const PARAMETRABLE_PARAMS_SCHEMA = [
|
2024-06-26 11:18:44 +04:00
|
|
|
"list_group_class" => ["?array", null, "classe CSS de la liste"],
|
2023-12-03 22:10:18 +04:00
|
|
|
"container" => ["string", "ul", "container de la liste: ul ou div"],
|
2024-06-26 11:18:44 +04:00
|
|
|
"item_func" => ["?callable", null, "fonction avec la signature (\$vs, \$item) retournant l'élément à afficher"],
|
2023-12-03 22:10:18 +04:00
|
|
|
];
|
|
|
|
|
|
|
|
function __construct(?iterable $items=null, ?array $params=null) {
|
|
|
|
self::set_parametrable_params_defaults($params, [
|
|
|
|
"container" => static::CONTAINER,
|
|
|
|
]);
|
|
|
|
parent::__construct($items, $params);
|
|
|
|
}
|
|
|
|
|
2024-06-26 11:18:44 +04:00
|
|
|
protected $ppListGroupClass;
|
|
|
|
|
2023-12-03 22:10:18 +04:00
|
|
|
private $ctag, $itag;
|
|
|
|
|
|
|
|
function pp_setContainer(string $container): self {
|
|
|
|
switch ($container) {
|
|
|
|
case "ul":
|
|
|
|
$this->ctag = "ul";
|
|
|
|
$this->itag = "li";
|
|
|
|
break;
|
|
|
|
case "div":
|
|
|
|
$this->ctag = "div";
|
|
|
|
$this->itag = "a";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw ValueException::invalid_value($container, "container");
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2024-06-26 11:18:44 +04:00
|
|
|
/** @var array */
|
|
|
|
protected $itemCtx;
|
|
|
|
|
|
|
|
function pp_setItemFunc($itemFunc): void {
|
|
|
|
if ($itemFunc === null) $this->itemCtx = null;
|
|
|
|
else $this->itemCtx = func::_prepare($itemFunc);
|
|
|
|
}
|
|
|
|
|
2023-12-03 22:10:18 +04:00
|
|
|
/** retourner le contenu associé au conteneur */
|
|
|
|
function container(): ?array {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _printStartContainer($container): void {
|
|
|
|
vo::start($this->ctag, [
|
2024-06-26 11:18:44 +04:00
|
|
|
"class" => ["list-group", $this->ppListGroupClass],
|
2023-12-03 22:10:18 +04:00
|
|
|
$this->container(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function printStartContainer(): void {
|
|
|
|
$this->_printStartContainer($this->container());
|
|
|
|
}
|
|
|
|
|
|
|
|
function printEndContainer(): void {
|
|
|
|
vo::end($this->ctag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** retourner le contenu associé à l'élément spécifié. */
|
|
|
|
function item($item): ?iterable {
|
2024-06-26 11:18:44 +04:00
|
|
|
$vs = [$item];
|
|
|
|
if ($this->itemCtx !== null) {
|
|
|
|
$vs = func::_call($this->itemCtx, [$vs, $item]);
|
|
|
|
}
|
|
|
|
return $vs;
|
2023-12-03 22:10:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function _printStartItem(): void {
|
|
|
|
vo::start($this->itag, [
|
|
|
|
"class" => "list-group-item",
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
protected function _printEndItem(): void {
|
|
|
|
vo::end($this->itag);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _printItem($item): void {
|
|
|
|
vo::tag($this->itag, [
|
|
|
|
"class" => "list-group-item",
|
|
|
|
$item,
|
|
|
|
], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function printItem($item): void {
|
|
|
|
$this->_printItem($this->item($item));
|
|
|
|
}
|
|
|
|
}
|