modifs.mineures sans commentaires
This commit is contained in:
parent
4d6d518c92
commit
e49bcb9852
|
@ -3,6 +3,7 @@ namespace nur\v\bs3\fo;
|
||||||
|
|
||||||
use nur\A;
|
use nur\A;
|
||||||
use nur\b\params\Tparametrable;
|
use nur\b\params\Tparametrable;
|
||||||
|
use nur\b\values\Breaker;
|
||||||
use nur\base;
|
use nur\base;
|
||||||
use nur\func;
|
use nur\func;
|
||||||
use nur\v\v;
|
use nur\v\v;
|
||||||
|
@ -15,11 +16,13 @@ class ControlSelect extends ControlVisual {
|
||||||
"items" => ["?iterable", null, "liste d'éléments à afficher"],
|
"items" => ["?iterable", null, "liste d'éléments à afficher"],
|
||||||
"items_func" => ["?callable", null, "fonction fournissant une liste d'éléments à afficher"],
|
"items_func" => ["?callable", null, "fonction fournissant une liste d'éléments à afficher"],
|
||||||
"item_value_key" => ["?key", null, "clé de la valeur d'un élément"],
|
"item_value_key" => ["?key", null, "clé de la valeur d'un élément"],
|
||||||
"item_value_func" => ["?callable", null, "fonction fournissant la clé de la valeur d'un élément"],
|
"item_value_func" => ["?callable", null, "fonction fournissant la valeur d'un élément"],
|
||||||
"item_text_key" => ["?key", null, "clé du libellé d'un élément"],
|
"item_text_key" => ["?key", null, "clé du libellé d'un élément"],
|
||||||
"item_text_func" => ["?callable", null, "fonction fournissant la clé du libellé d'un élément"],
|
"item_text_func" => ["?callable", null, "fonction fournissant le libellé d'un élément"],
|
||||||
"no_item_value" => ["?string", null, "valeur si aucun élément n'est sélectionné"],
|
"no_item_value" => ["?string", null, "valeur si aucun élément n'est sélectionné"],
|
||||||
"no_item_text" => ["?content", null, "libellé si aucun élément n'est sélectionné"],
|
"no_item_text" => ["?content", null, "libellé si aucun élément n'est sélectionné"],
|
||||||
|
"group_key" => ["?key", null, "clé d'une valeur sur laquelle grouper les éléments"],
|
||||||
|
"group_func" => ["?callable", null, "fonction fournissant une valeur sur laquelle grouper les éléments"],
|
||||||
"required" => ["?bool", null, "ce champ est-il requis?"],
|
"required" => ["?bool", null, "ce champ est-il requis?"],
|
||||||
"show_required" => ["?bool", null, "faut-il afficher la marque de champ requis?"],
|
"show_required" => ["?bool", null, "faut-il afficher la marque de champ requis?"],
|
||||||
"option_prefix" => ["?content", "\n", "contenu à afficher avant chaque option"],
|
"option_prefix" => ["?content", "\n", "contenu à afficher avant chaque option"],
|
||||||
|
@ -58,6 +61,12 @@ class ControlSelect extends ControlVisual {
|
||||||
/** @var array|string */
|
/** @var array|string */
|
||||||
protected $ppNoItemText;
|
protected $ppNoItemText;
|
||||||
|
|
||||||
|
/** @var string|int|null */
|
||||||
|
protected $ppGroupKey;
|
||||||
|
|
||||||
|
/** @var ?callable */
|
||||||
|
protected $ppGroupFunc;
|
||||||
|
|
||||||
/** @var ?bool */
|
/** @var ?bool */
|
||||||
protected $ppRequired;
|
protected $ppRequired;
|
||||||
|
|
||||||
|
@ -113,14 +122,20 @@ class ControlSelect extends ControlVisual {
|
||||||
"selected" => $value == $noItemValue,
|
"selected" => $value == $noItemValue,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
$haveGroups = $this->ppGroupKey !== null || $this->ppGroupFunc !== null;
|
||||||
foreach ($items as $key => $item) {
|
foreach ($items as $key => $item) {
|
||||||
$itemValue = $this->vof(null, $this->ppItemValueFunc, $item, $this->ppItemValueKey, 0, $item, $key);
|
$itemValue = $this->vof(null, $this->ppItemValueFunc, $item, $this->ppItemValueKey, 0, $item, $key);
|
||||||
$itemText = $this->vof(null, $this->ppItemTextFunc, $item, $this->ppItemTextKey, 1, $item, $key);
|
$itemText = $this->vof(null, $this->ppItemTextFunc, $item, $this->ppItemTextKey, 1, $item, $key);
|
||||||
|
$itemGroup = null;
|
||||||
|
if ($haveGroups) {
|
||||||
|
$itemGroup = $this->vof(null, $this->ppGroupFunc, $item, $this->ppGroupKey, null, $item, $key);
|
||||||
|
}
|
||||||
if (!$itemText) $itemText = $itemValue;
|
if (!$itemText) $itemText = $itemValue;
|
||||||
$options[] = array(
|
$options[] = array(
|
||||||
"value" => $itemValue,
|
"value" => $itemValue,
|
||||||
"text" => $itemText,
|
"text" => $itemText,
|
||||||
"selected" => $value == $itemValue,
|
"selected" => $value == $itemValue,
|
||||||
|
"group" => $itemGroup,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +151,14 @@ class ControlSelect extends ControlVisual {
|
||||||
"style" => $this->ppStyle,
|
"style" => $this->ppStyle,
|
||||||
$this->ppAttrs,
|
$this->ppAttrs,
|
||||||
]);
|
]);
|
||||||
|
$breaker = new Breaker();
|
||||||
|
$firstGroup = true;
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
|
if ($haveGroups && $breaker->shouldBreakOn($option["group"])) {
|
||||||
|
if ($firstGroup) $firstGroup = false;
|
||||||
|
else $control[] = v::end("optgroup");
|
||||||
|
$control[] = v::start("optgroup", ["label" => $option["group"]]);
|
||||||
|
}
|
||||||
$control[] = $this->ppOptionPrefix;
|
$control[] = $this->ppOptionPrefix;
|
||||||
$control[] = v::tag("option", [
|
$control[] = v::tag("option", [
|
||||||
"value" => $option["value"],
|
"value" => $option["value"],
|
||||||
|
@ -145,6 +167,9 @@ class ControlSelect extends ControlVisual {
|
||||||
]);
|
]);
|
||||||
$control[] = $this->ppOptionSuffix;
|
$control[] = $this->ppOptionSuffix;
|
||||||
}
|
}
|
||||||
|
if (!$firstGroup) {
|
||||||
|
$control[] = v::end("optgroup");
|
||||||
|
}
|
||||||
$control[] = v::end("select");
|
$control[] = v::end("select");
|
||||||
if ($this->ppNaked) return $control;
|
if ($this->ppNaked) return $control;
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ class _query_select extends _query {
|
||||||
if (($prefix = $query["prefix"] ?? null) !== null) $sql[] = $prefix;
|
if (($prefix = $query["prefix"] ?? null) !== null) $sql[] = $prefix;
|
||||||
|
|
||||||
## select
|
## select
|
||||||
self::consume('select\s*', $tmpsql);
|
self::consume('(select(?:\s*distinct)?)\s*', $tmpsql, $ms);
|
||||||
$sql[] = "select";
|
$sql[] = $ms[1];
|
||||||
|
|
||||||
## cols
|
## cols
|
||||||
$usercols = [];
|
$usercols = [];
|
||||||
|
@ -67,7 +67,7 @@ class _query_select extends _query {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$usercols && !$cols) $usercols = ["*"];
|
if (!$usercols && !$cols) $usercols = ["*"];
|
||||||
$sql[] = implode(" ", $usercols);
|
$sql[] = implode(", ", $usercols);
|
||||||
|
|
||||||
## from
|
## from
|
||||||
$from = $query["from"] ?? null;
|
$from = $query["from"] ?? null;
|
||||||
|
|
Loading…
Reference in New Issue