Aggiunto link a Plugin

This commit is contained in:
Thomas Zilio 2019-07-05 10:47:45 +02:00
parent 4a6ac3c870
commit a8bad1e30a
4 changed files with 38 additions and 2 deletions

View File

@ -49,6 +49,10 @@ $_SESSION['superselect']['idanagrafica'] = $record['idanagrafica'];
<div class="col-md-3">
<?php
echo Plugins::link('Referenti', $record['idanagrafica'], null, null, 'class="pull-right"');
?>
{[ "type": "select", "label": "<?php echo tr('Referente'); ?>", "name": "idreferente", "value": "$idreferente$", "ajax-source": "referenti" ]}
</div>

View File

@ -42,6 +42,10 @@ $_SESSION['superselect']['idanagrafica'] = $record['idanagrafica'];
</div>
<div class="col-md-3">
<?php
echo Plugins::link('Referenti', $record['idanagrafica'], null, null, 'class="pull-right"');
?>
{[ "type": "select", "label": "<?php echo tr('Referente'); ?>", "name": "idreferente", "value": "$idreferente$", "ajax-source": "referenti" ]}
</div>

View File

@ -250,10 +250,12 @@ class Modules
* @param string $testo
* @param string $alternativo
* @param string $extra
* @param bool $blank
* @param string $anchor
*
* @return string
*/
public static function link($modulo, $id_record = null, $testo = null, $alternativo = true, $extra = null, $blank = true)
public static function link($modulo, $id_record = null, $testo = null, $alternativo = true, $extra = null, $blank = true, $anchor = null)
{
$testo = isset($testo) ? nl2br($testo) : tr('Visualizza scheda');
$alternativo = is_bool($alternativo) && $alternativo ? $testo : $alternativo;
@ -270,7 +272,7 @@ class Modules
if (!empty($module) && in_array($module->permission, ['r', 'rw'])) {
$link = !empty($id_record) ? 'editor.php?id_module='.$module['id'].'&id_record='.$id_record : 'controller.php?id_module='.$module['id'];
return '<a href="'.ROOTDIR.'/'.$link.'" '.$extra.'>'.$testo.'</a>';
return '<a href="'.ROOTDIR.'/'.$link.'#'.$anchor.'" '.$extra.'>'.$testo.'</a>';
} else {
return $alternativo;
}

View File

@ -97,4 +97,30 @@ class Plugins
return $element ? $element->filepath($file) : null;
}
/**
* Costruisce un link HTML per il modulo e il record indicati.
*
* @param string|int $plugin
* @param int $id_record
* @param string $testo
* @param string $alternativo
* @param string $extra
* @param bool $blank
*
* @return string
*/
public static function link($plugin, $id_record = null, $testo = null, $alternativo = true, $extra = null, $blank = true)
{
$plugin = self::get($plugin);
$alternativo = is_bool($alternativo) && $alternativo ? $testo : $alternativo;
if (!empty($plugin) && in_array($plugin->permission, ['r', 'rw'])) {
$anchor = 'tab_'.$plugin->id;
return Modules::link($plugin->originalModule->id, $id_record, $testo, $alternativo, $extra, $blank, $anchor);
}
return $alternativo;
}
}