feat: gestione pulsanti precedente e successivo

This commit is contained in:
MatteoPistorello 2024-10-31 14:49:13 +01:00
parent ab6cedcd13
commit 709652eecd
4 changed files with 38 additions and 11 deletions

View File

@ -29,6 +29,7 @@ $draw_numer = intval(filter('draw'));
if (!empty(filter('order'))) {
$order['column'] = $order['column'] - 1;
}
$_SESSION['module_'.$id_module]['order'] = $order;
array_shift($columns);
$total = Query::readQuery($structure);

View File

@ -172,6 +172,41 @@ if (empty($record) || !$has_access) {
<i class="fa fa-chevron-left"></i> '.tr("Torna all'elenco").'
</a>';
// Pulsante Precedente e Successivo
// Aggiungo eventuali filtri applicati alla vista
if (count(getSearchValues($id_module)) > 0) {
foreach (getSearchValues($id_module) as $key => $value) {
$where[$key] = $value;
}
}
// Ricavo la posizione per questo id_record
$order = $_SESSION['module_'.$id_module]['order'] ?: [];
$module_query = Util\Query::getQuery($structure, $where, $order);
$posizioni = $dbo->fetchArray($module_query);
$key = array_search($id_record, array_column($posizioni, 'id'));
// Precedente
$prev = $posizioni[$key-1]['id'];
// Successivo
$next = $posizioni[$key+1]['id'];
if (isMobile()) {
echo '<div>';
} else {
echo '<div class="col-md-2 d-none d-sm-inline">';
}
echo '
<a class="btn btn-default'.($prev ? '' : ' disabled').'" href="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$prev.'">
<i class="fa fa-arrow-circle-left"></i>
</a>
<a class="btn btn-default'.($next ? '' : ' disabled').'" href="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$next.'">
<i class="fa fa-arrow-circle-right"></i>
</a>
</div>';
if (isMobile()) {
echo '<div>';
} else {

View File

@ -39,17 +39,8 @@ echo '
<button type="button" class="btn btn-primary '.(!empty($info_firma) ? 'tip' : '').'" title="'.$info_firma.'" onclick="anteprimaFirma()" '.($record['flag_completato'] ? 'disabled' : '').'>
<i class="fa fa-'.(!empty($info_firma) ? 'refresh' : 'desktop').'"></i> '.$frase.'...
</button>';
</button>
// TODO: da standardizzare in struttura per tutti i moduli di tipo table
/*<a class="btn btn-info'.($prev ? '' : ' disabled').'" href="'.base_path().'/editor.php?id_module=3&id_record='.$prev.'">
<i class="fa fa-arrow-circle-left"></i> '.tr('Precedente').'
</a>
<a class="btn btn-info'.($next ? '' : ' disabled').'" href="'.base_path().'/editor.php?id_module=3&id_record='.$next.'">
'.tr('Successivo').' <i class="fa fa-arrow-circle-right"></i>
</a>*/
echo '
<script>
function duplicaIntervento() {
openModal("'.tr('Duplica attività').'", "'.$module->fileurl('modals/duplicazione.php').'?id_module='.$id_module.'&id_record='.$id_record.'");

View File

@ -478,7 +478,7 @@ class Query
$select = empty($select) ? '*' : implode(', ', $select);
$query = str_replace('|select|', $select.', @posizione := @posizione + 1 AS `posizione`', $query);
$query = str_replace('|select|', $select, $query);
return [
'query' => self::replacePlaceholder($query),