parser($values, $values['icon-before']);
$values['icon-after'] = $this->parser($values, $values['icon-after']);
// Generazione dell'etichetta
if (!empty($values['label'])) {
$result .= '
';
unset($values['label']);
}
return $result;
}
protected function parser(&$values, $string)
{
$result = $string;
if (starts_with($string, 'add|')) {
$result = $this->add($values, $string);
$values['icon-custom'] = 'no-padding';
} elseif (starts_with($string, 'choice|')) {
$result = $this->choice($values, $string);
$values['icon-custom'] = 'no-padding';
}
return $result;
}
protected function add(&$values, $string)
{
$result = null;
$pieces = explode('|', $string);
$id_module = $pieces[1];
$extra = empty($pieces[2]) ? '' : '&'.$pieces[2];
$classes = empty($pieces[3]) ? '' : ' '.$pieces[3];
$module = \Modules::getModule($id_module);
if (in_array($module['permessi'], ['r', 'rw'])) {
$result = '
';
}
return $result;
}
protected function choice(&$values, $string)
{
$result = null;
$choices = [
[
'id' => 'UNT',
'descrizione' => _('€'),
],
[
'id' => 'PRC',
'descrizione' => '%',
],
];
$pieces = explode('|', $string);
$type = $pieces[1];
$value = (empty($pieces[2]) || !in_array($pieces[2], array_column($choices, 'id'))) ? 'UNT' : $pieces[2];
if ($type == 'untprc') {
$result = '{[ "type": "select", "name": "tipo_'.\HTMLBuilder\prepareToField($values['name']).'", "value": "'.\HTMLBuilder\prepareToField($value).'", "values": "json='.substr(str_replace('"', '\"', json_encode($choices)), 2, -2).'", "class": "no-search" ]}';
$result = \HTMLBuilder\HTMLBuilder::replace($result);
}
return $result;
}
}