gestione gare pubbliche
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

910 righe
36 KiB

<?php
/**
* Bootstrap 4 form generator Trait
*/
trait BS4RenderTrait
{
// I trait non possono avere costanti.
private static function asterisk()
{
return "<span class='text-danger text-asterisk text-bold'>*</span>";
}
// Stampa la label con il nome interno del campo
private static function printCodeLabel(array $options) {
// Dividiamo la data reference
$split = explode(".", $options["attrs"]["data-reference"] ?? ".");
$index = array_key_last($split);
$label = $split[$index];
// Se la label trovata non è utile cerchiamone una utile
while($index > 0 && (in_array($label, ["codice", "*"]) || is_numeric($label))) {
$label = $split[--$index];
}
?>
<small class="ml-2 d-inline-block">
<code class="text-secondary text-nowrap">
<?= $label ?>
</code>
</small>
<?php
}
/**
* readonly
*
* @var bool
*/
public $readonly = false;
/**
* Setup validation rules
*
* @param Array $options
* @return void
*/
private function validation(array $options)
{
$rel = [];
$rel[] = "N";
$rel[] = "0";
$rel[] = "0";
$rel[] = "A";
if (!empty($options["required"])) {
$rel[0] = "S";
$rel[1] = "1";
}
if (!empty($options["rel"]) && is_array($options["rel"])) {
$rel = $options["rel"];
}
return implode(";", $rel);
}
/**
* Check inaccessible methods
*
* @param String $method
* @param Array $parameters
* @return void
*/
public function __call($method, $parameters)
{
if (method_exists($this, "__{$method}")) {
if ($method == "label") {
return $this->{"__{$method}"}($parameters[2] ?? "", $parameters[1]);
}
$parameters[0]["rel"] = $this->validation($parameters[0]);
return $this->{"__{$method}"}($parameters[0]);
}
}
/**
* Selezione codice istat
*
* @return void
*/
public function __codice_istat(array $options)
{
$options["attrs"]["class"][] = "not-chosen";
$options["field_id"] = uniqid("codice_istat_");
if (!empty($options["val"])) {
global $pdo;
$option = $pdo->go("SELECT * FROM b_istat_anac WHERE codice_istat = :codice_istat", [":codice_istat" => $options["val"]])->fetch(PDO::FETCH_ASSOC);
if($option)
$options["options"] = [$option["codice_istat"] => "{$option["etichetta"]}"];
}
ob_start();
echo $this->__select($options);
?>
<script type="text/javascript">
$('#<?= $options["field_id"] ?>').select2({
theme: "bootstrap",
ajax: {
url: '/backend/common/istat/codici_anac.php',
dataType: 'json'
}
});
</script>
<?
return ob_get_clean();
}
/**
* Tiene traccia che il boilerplate venga salvato una sola volta
*
* @var boolean
*/
private $__centroCostoPrintBoilerplate = true;
/**
* Select per centri di costo con auto refresh dei componenti
*
* @param Array $options
* @return void
*/
public function __centroCosto(array $options)
{
// Inizializziamo cone not-chosen per avere un select2
$options["attrs"]["class"][] = "not-chosen";
$options["attrs"]["centroCosto"] = "";
$options["field_id"] = uniqid("centroCosto_");
$options["options"] = [$options["val"] => $options["val"]];
ob_start();
echo $this->__select($options);
?>
<script type="text/javascript" id="boiler_<?= $options["field_id"] ?>">
<?php if($this->__centroCostoPrintBoilerplate) : ?>
// Inizializziamo la cache e il metodo helper globale solo una volta
<? $this->__centroCostoPrintBoilerplate = false ?>
if (typeof window.refreshCentriCosto == "undefined") {
// La cache evita troppe richieste al server
window.cacheCentriCosto = {}
window.refreshCentriCosto = function(cf, sel, dataSource) {
// Questo aggiorna il datasource una volta che sono ottenuti
function updateDataSource(data) {
// Aggiorniamo il dataSource in modo che select2 lo riottenga
dataSource["results"] = data;
// Se è la prima chiamata per questo select
if(sel.dataset.initialized != 1) {
sel.dataset.initialized = 1;
// Forziamo il testo per i valori iniziali
for(entry of data) {
let option = sel.querySelector(`option[value='${entry.id}']`);
if(option == null) {
option = document.createElement('option');
sel.appendChild(option);
}
option.innerText = entry.text;
option.value = entry.id;
}
// Inizializziamo la select con un puntatore alla sorgente dati
let readOnly = sel.readOnly;
$(sel).select2({
//readonly : 'readonly',
ajax: {
transport: function(params, success, failure) {
// Risultati filtrati
var filteredResults = {"results": []};
// Query
let query = params.data.q;
if(typeof query === "undefined") {
// Se non c'è query ritorniamo tutto
filteredResults = dataSource;
} else {
query = query.toLowerCase();
// Includiamo prima quelli che iniziano come richiesto
for(item of dataSource["results"]) {
if(item.text.toLowerCase().startsWith(query)) {
filteredResults["results"].push(item);
}
}
// Includiamo poi quelli che contengono la query
for(item of dataSource["results"]) {
if(item.text.toLowerCase().includes(query)) {
if(!filteredResults["results"].includes(item)) {
filteredResults["results"].push(item);
}
}
}
}
var promise = new Promise(function(resolve, reject) {
resolve(filteredResults);
});
promise.then(success);
promise.catch(failure);
}
},
theme: 'bootstrap'
});
$(sel).on('select2:opening', function (e) {
if($(this).is("[readonly]")) {
e.preventDefault();
$(sel).select2('close');
return false;
}
});
}
// TODO Verificare che l'opzione attuale sia presente nei risultati
// Refreshiamo il valore della select
$(sel).val(sel.value);
// Facciamo un trigger del change
$(sel).trigger("change");
}
// I valori invalidi sappiamo già saranno vuoti
if (cf.length < 11 || cf.length > 16) {
cacheCentriCosto[cf] = [];
}
// Se non c'è cache
if (typeof cacheCentriCosto[cf] == "undefined") {
// Facciamo una richiesta ajax
fetch(
`ajax/centriCosto.php?cf=${cf}&codice=${<?= $this->scheda["codice"] ?? 0 ?>}`, {
method: 'GET',
}
)
// TODO Check if response is JSON
.then(response => response.json())
.then(response => {
let data = response.results
cacheCentriCosto[cf] = data;
updateDataSource(cacheCentriCosto[cf]);
});
} else {
// Altrimenti usiamo la cache
updateDataSource(cacheCentriCosto[cf]);
}
}
}
<?php endif; ?>
(() => {
// Select centri di costo
const selCosto = document.getElementById("<?= $options["field_id"] ?>");
selCosto.dataset.initialized = 0;
let dataSource = {
"results": []
};
// Input codice fiscale
let txtCodiceFiscale = null;
let el = selCosto
while (txtCodiceFiscale == null) {
txtCodiceFiscale = el.parentElement.querySelector(`input[name$="[codiceFiscale]"`);
el = el.parentElement;
}
if (txtCodiceFiscale.value) {
refreshCentriCosto(txtCodiceFiscale.value, selCosto, dataSource);
}
// Facciamo la richiesta ad ogni modifica del codice fiscale
txtCodiceFiscale.addEventListener("input", function(e) {
refreshCentriCosto(txtCodiceFiscale.value, selCosto, dataSource);
})
})();
</script>
<?
return ob_get_clean();
}
/**
* Print select
*
* @param Array $options
* @return void
*/
public function __select(array $options)
{
// Supporto per readonly
if (!empty($options["attrs"]) && !empty($options["attrs"]["readonly"])) {
if(isset($options["attrs"]["centroCosto"])) {
} else {
$dummy_options = $options;
$dummy_options["attrs"]["disabled"] = 1;
// Previene che venga aggiornato il suo valore
$dummy_options["attrs"]["data-dummy"] = true;
$dummy_options["name"] = "dummy_" . $dummy_options["name"];
if (isset($options["options"]) && isset($options["options"][$options["val"]])) {
$dummy_options["val"] = $options["options"][$options["val"]];
} else {
$dummy_options["val"] = $options["val"];
}
$options["value"] = $options["val"];
return $this->__text($dummy_options) . $this->__hidden_but_better($options);
}
}
if (!empty($options["name"])) {
ob_start();
?>
<div class="form-group <?= $options["size"] ?? 'col-sm-12' ?>">
<?= $this->label($options["name"], $options, $options["title"] ?? null); ?>
<select class="custom-select <?= (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?>" name="<?= $options["name"] ?>" rel="<?= $options["rel"] ?? null ?>" data-rel="<?= $options["rel"] ?? null ?>" <?
$this->printAttributes($options["attrs"] ?? []) ?> id="<?= $options["field_id"] ?? $this->slugify($options["name"]) ?>" title="<?= $options["title"] ?>">
<option value=""><?= __guue("Seleziona un valore...") ?></option>
<?
foreach (($options["options"] ?? []) as $key => $title) {
?>
<?php
$optionVal = $options["val"] ?? null;
$selected = $key == $optionVal;
// PHP è un linguaggio di programmazione a tipizzazione dinamica, previene che ""|null == "0"
if($optionVal === "" || $optionVal === null)
$selected = false;
?>
<option <?= $selected ? 'selected="selected"' : null ?> value="<?= $key ?>">
<?= $title?></option>
<?
}
?>
</select>
<?
if (!empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small>
<?
}
?>
</div>
<?
return ob_get_clean();
}
return null;
}
/**
* __number
*
* @param mixed $options
* @return void
*/
public function __number(array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "N";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* __decimal
*
* @param mixed $options
* @return void
*/
public function __decimal(array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "2D";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print Select with Nuts Codes
*
* @param mixed $options
* @return void
*/
function __nuts(array $options = [])
{
global $pdo;
$bind = [];
$sql = "SELECT nuts, descrizione, data_fine_validita FROM b_nuts WHERE data_fine_validita = '' OR data_fine_validita IS NULL";
if (!empty($options["data_fine_validita"])) {
$sql .= "OR DATE(data_fine_validita) >= :data_fine_validita";
$bind[":data_fine_validita"] = $options["data_fine_validita"];
}
$nuts = $pdo->go($sql, $bind);
if ($nuts->rowCount() > 0) {
while ($code = $nuts->fetch(PDO::FETCH_ASSOC)) {
if (strlen($code["nuts"]) > 3) {
$options["options"][$code["nuts"]] = $code["descrizione"];
if (!empty($code["data_fine_validita"])) {
$data_fine_validita = mysql2date($code["data_fine_validita"]);
$options["options"][$code["nuts"]] = "{$code["descrizione"]} (data fine validità {$data_fine_validita})";
}
}
}
}
$options["type"] = "select";
return $this->__select($options);
}
/**
* Print text input
*
* @param Array $options
* @return void
*/
public function __text(array $options = [])
{
if (!empty($options["name"])) {
$class = null;
if (!empty($options["input"]["class"]) && is_array($options["input"]["class"])) {
$class = implode(" ", $options["input"]["class"]);
}
if (!empty($options["override"])) {
foreach ($options["override"] as $key => $value) {
if (array_key_exists($key, $options)) {
$options[$key] = $value;
}
}
}
ob_start();
?>
<div class="form-group <?= $options["size"] ?? 'col-sm-12' ?>">
<?
if (empty($options["hidden-label"])) {
echo $this->label($options["name"], $options, $options["title"] ?? null);
}
?>
<input type="text" placeholder="<?= __guue($options["title"] ?? $options["name"]) ?>" class="form-control <?= $class ?> <?= (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?>" <?php if ($options["pattern"] ?? false) : ?> data-regex="<?= $options["pattern"] ?>" <?php endif; ?> title="<?= __guue($options["title"] ?? $options["name"]) ?>" rel="<?= $options["rel"] ?? null ?>" data-rel="<?= $options["rel"] ?? null ?>" <? $this->printAttributes($options["attrs"] ?? []) ?> id="<?= $options["field_id"] ?? $this->slugify($options["name"]) ?>" name="<?= $options["name"] ?>" value="<?= $options["val"] ?? null ?>">
<?
if (!empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small>
<?
}
?>
</div>
<?
return ob_get_clean();
}
return null;
}
/**
* Print textarea input
*
* @param Array $options
* @return void
*/
public function __textarea(array $options = [])
{
if (!empty($options["name"])) {
ob_start();
?>
<div class="form-group <?= $options["size"] ?? 'col-sm-12' ?>">
<?= $this->label($options["name"], $options, $options["title"] ?? null); ?>
<textarea class="form-control <?= ($options["no-ckeditor"] ?? false) ? null : "ckeditor" ?> <?= (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?>" placeholder="<?= $options["title"] ?? $options["name"] ?>" id="<?= $options["field_id"] ?? $this->slugify($options["name"]) ?>" rel="<?= $options["rel"] ?? null ?>" data-rel="<?= $options["rel"] ?? null ?>" name="<?= $options["name"] ?>" title="<?= $options["title"] ?>" <?
$this->printAttributes($options["attrs"] ?? []) ?> rows="3"><? if (!empty($options["val"])) {
echo $options["val"];
} ?></textarea>
</div>
<?
return ob_get_clean();
}
if (!empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small>
<?
return ob_get_clean();
}
return null;
}
/**
* Print checkbox input
*
* @param Array $options
* @return void
*/
public function __checkbox(array $options = [])
{
if (!empty($options["name"])) {
$rel = explode(";", $options["rel"]);
if (count($rel) > 3 && $rel[3] != "Checked") {
$rel[3] = "Checked";
$options["rel"] = implode(";", $rel);
}
ob_start();
?>
<div class="<?= $options["size"] ?? 'col-sm-12' ?>">
<div class="form-check mb-3">
<input class="form-check-input <?= (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?> <?= $options["required"] ? "valida" : "" ?>" type="checkbox" value="<?= $options["value"] ?? null ?>" name="<?= $options["name"] ?>" rel="<?= $options["rel"] ?>" title="<?= $options["title"] ?? '' ?>" id="<?= $options["field_id"] ?? $this->slugify($options["name"]) ?>"
<? if (
!empty($options["val"]) &&
$options["val"] == $options["value"]
) {
echo 'checked="checked"';
} ?>
<? $this->printAttributes($options["attrs"] ?? []) ?>>
<label class="form-check-label" for="<?= $this->slugify($options["name"]) ?>">
<?= $options["title"] ?? $options["name"] ?> <?= $options["required"] ? self::asterisk() : "" ?>
<?= self::printCodeLabel($options) ?>
</label>
</div>
</div>
<?
return ob_get_clean();
}
return null;
}
/**
* Print a text line
*
* @param array $options
* @return void
*/
public function __text_line(array $options = [])
{
if (!empty($options["name"])) {
return "<div class='col-sm-12'><p>{$options["name"]}</p></div>";
}
return null;
}
/**
* Print CPV Selector
*
* @param mixed $options
* @return void
*/
public function __cpv(array $options)
{
global $pdo;
$id = $this->slugify(uniqid('', true));
ob_start();
?>
<div id="<?= $id ?>-search-cpv" class="col-sm-12 <?= !empty($options["val"]) ? 'd-none' : null ?>">
<label class="mb-0" for="<?= $id ?>"><?= $options["title"] . (($options["required"] ?? false) ? self::asterisk() : '') ?>: </label>
<?= self::printCodeLabel($options) ?>
<input id="<?= $id ?>" type="text" <? $this->printAttributes($options["attrs"] ?? []) ?> placeholder="<?= __guue("Scrivi per ricercare una") ?> CPV" title="<?= __guue("Scrivi per ricercare una") ?> CPV" autocomplete="false" class="form-control">
<script id='boiler_cpv<?= uniqid() ?>'>
$("#<?= $id ?>").typeahead({
hint: false,
highlight: true,
minLength: 2,
limit: 9999
}, {
name: 'cpv',
display: 'label',
source: function(query, syncResults, asyncResults) {
var selezionate = [];
$(".selected-cpv", "#<?= $id ?>").each(function() {
selezionate.push($(this).val());
});
$.ajax({
url: "/inc/cpv/autocomplete.php?minlength=<?= !empty($options["minlength"]) ? $options["minlength"] : 2 ?>&macro=<?= !empty($options["macro"]) ? $options["macro"] : '' ?>",
dataType: "json",
data: {
query: query,
selezionate: btoa(selezionate.join(","))
},
success: function(data) {
asyncResults(data);
}
});
},
limit: 9999
}).bind('typeahead:select', function(ev, suggestion) {
$.getJSON("/inc/cpv/info.php", {
cpv: suggestion.value
}, function(data, textStatus, jqXHR) {
if ("codice" in data) {
var cpv = $("<div>", {
class: "list-group-item d-flex align-items-center",
id: "cpv-" + suggestion.value
});
var title = $('<span>', {
class: 'text-left flex-fill'
}).text(data["codice_completo"] + " - " + data["IT"]);
var button = $('<button>', {
class: 'btn btn-danger',
type: 'button',
onClick: "deleteCPV('#cpv-" + suggestion.value + "','<?= $id ?>');"
}).html(
'<span class="fa fa-times"></span><span class="sr-only"><?= __guue("elimina") ?></span>'
);
var input = $('<input>', {
type: 'hidden',
name: '<?= $options["name"] ?>',
id: '<?= "input-{$id}" ?>'
}).val(suggestion.value);
cpv.append(title)
.append(button)
.append(input);
$('#<?= $id ?>-search-cpv').addClass('d-none');
$('.list-group', "#<?= $id ?>-cpv-list").append(cpv);
$("#<?= $id ?>-cpv-list").removeClass('d-none');
}
});
$('#<?= $id ?>').focus().typeahead('val', "");
$("#val" + suggestion.value).remove();
});
var deleteCPV = function(cpv, id) {
$(cpv).remove();
$(`#${id}-search-cpv`).removeClass('d-none');
$(`#${id}-cpv-list`).addClass('d-none');
}
</script>
</div>
<div id="<?= $id ?>-cpv-list" class="col-sm-12 <?= empty($options["val"]) ? 'd-none' : null ?> mt-3">
<div class="list-group">
<?
if (!empty($options["val"])) {
$cpv = $pdo->go("SELECT * FROM b_cpv WHERE codice = :codice", [":codice" => $options["val"]])->fetch(PDO::FETCH_ASSOC);
if (!empty($cpv)) {
?>
<div id="cpv-<?= $cpv["codice_completo"] ?>" class="list-group-item d-flex align-items-center">
<span class="text-left flex-fill"><?= $cpv["codice_completo"] ?>-<?= $cpv["IT"] ?></span>
<button class="btn btn-danger" type="button" onclick="deleteCPV('#cpv-<?= $cpv['codice_completo'] ?>','<?= $id ?>');"><span class="fa fa-times"></span><span class="sr-only"><?= __guue("elimina") ?></span></button>
<input type="hidden" name="<?= $options["name"] ?>" id="<?= "input-{$id}" ?>" value="<?= $cpv["codice"] ?>" <?= !empty($options["rel"]) ? "rel={$options['rel']}" : '' ?>>
</div>
<?
}
}
?>
</div>
</div>
<div class="clearfix">&nbsp;</div>
<?
return ob_get_clean();
}
/**
* Print checkbox input
*
* @param Array $options
* @return void
*/
public function __radio(array $options = [])
{
if (!empty($options["name"])) {
ob_start();
?>
<div class="form-group <?= !empty($options["assert_fail"]) ? 'text-danger' : null ?> <?= $options["size"] ?? 'col-sm-12' ?>">
<?= $this->label($options["name"], $options, $options["title"] ?? null); ?>
<select class="custom-select <?= (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?>" name="<?= $options["name"] ?>" rel="<?= $options["rel"] ?? null ?>" data-rel="<?= $options["rel"] ?? null ?>" <?
$this->printAttributes($options["attrs"] ?? []) ?> id="<?= $options["field_id"] ?? $this->slugify($options["name"]) ?>" title="<?= $options["title"] ?>">
<option value=""><?= __guue("Seleziona un valore...") ?></option>
<?
foreach ($options["options"] as $key => $title) {
?>
<option <?= ($key == ($options["val"] ?? null)) ? 'selected="selected"' : null ?> value="<?= $key ?>">
<?= $title ?></option>
<?
}
?>
</select>
<?
if (!empty($options["help"])) {
?><small id="<?= $this->slugify($options["name"]) ?>-help" class="form-text text-muted"><?= $options["help"] ?></small>
<?
}
?>
</div>
<?
return ob_get_clean();
}
return null;
}
/**
* Print input attributes
*
* @param mixed $attributes
* @return void
*/
public function printAttributes(array $attributes): void
{
if (!empty($attributes) && is_array($attributes) && !array_is_list($attributes)) {
foreach ($attributes as $key => $value) {
if ($key !== "class") {
echo ' ' . $key . (isset($value) ? '="' . $value . '"' : null) . ' ';
}
}
}
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __datetime(array $options = [])
{
$options["input"]["class"][] = "datetimepick";
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "DT";
$object = $options["object"] ?? "";
if ($object == "date_full") {
$options["input"]["class"][] = "datepick";
$options["rel"][3] = "D";
} else if ($object == "time") {
$options["input"]["class"][] = "timepick";
$options["rel"][3] = "T";
}
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __date(array $options = [])
{
$options["input"]["class"][] = "datepick";
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "D";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __time(array $options = [])
{
$options["input"]["class"][] = "time";
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "T";
$options["rel"] = implode(";", $options["rel"]);
if (!empty($options["val"])) {
preg_match('/^\d{2}:\d{2}/', $options["val"], $m);
if (!empty($m)) {
$options["val"] = $m[0];
}
}
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __email(array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "E";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print datetime input
*
* @param Array $options
* @return void
*/
public function __url(array $options = [])
{
$options["rel"] = explode(";", $options["rel"]);
$options["rel"][3] = "L";
$options["rel"] = implode(";", $options["rel"]);
return $this->__text($options);
}
/**
* Print label
*
* @param String $name
* @param String $title
* @return void
*/
public function __label(String $name, array $options, String $title = null)
{
if (!empty($name)) {
ob_start();
?>
<label class="mb-0 <?= !empty($options["label-attrs"]["class"]) ? $options["label-attrs"]["class"] : null ?>" for="<?= $this->slugify($name) ?>"><?= __guue($title ?? $name) ?>:
<?= (!empty($options["required"]) || (!empty($options["rel"] && $options["rel"][0] == "S"))) ? self::asterisk() : null ?>
<?= self::printCodeLabel($options) ?>
</label>
<?
return ob_get_clean();
}
return null;
}
public function __hidden_but_better(array $options = [])
{
ob_start();
?>
<input type="hidden" id="<?= $this->slugify($options["name"]) ?>" value="<?= ($options["value"] ?? "") ?>" name="<?= $options["name"] ?>">
<?
return ob_get_clean();
}
/**
* Print an hidden input
*
* @param mixed $options
* @return void
*/
public function __hidden(array $options = [])
{
ob_start();
?>
<input type="hidden" id="<?= $options["field_id"] ?? $this->slugify($options["name"]) ?>" value="<?= ($options["val"] ?? "") ?>" name="<?= $options["name"] ?>">
<?
return ob_get_clean();
}
/**
* Print a button
*
* @param mixed $options
* @return void
*/
public function __button(array $options = [])
{
ob_start();
?>
<div class="<?= $options["size"] ?? 'col-sm-12' ?>">
<button type="button" <? $this->printAttributes($options["attrs"]) ?> class="<?= (!empty($options["attrs"]["class"]) && is_array($options["attrs"]["class"])) ? implode(" ", $options["attrs"]["class"]) : null ?>"><?= $options["title"] ?></button>
</div>
<?
return ob_get_clean();
}
/**
* slugify
*
* @param mixed $text
* @return void
*/
public static function slugify($text)
{
$text = preg_replace('~[^\pL\d]+~u', '-', $text); // replace non letter or digits by -
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // transliterate
$text = preg_replace('~[^-\w]+~', '', $text); // remove unwanted characters
$text = trim($text, '-'); // trim
$text = preg_replace('~-+~', '-', $text); // remove duplicate -
$text = strtolower($text); // lowercase
if (empty($text)) return 'n-a';
return $text;
}
}