2021-10-20 09:39:12 +02:00
< ? php
2021-11-10 09:06:39 +01:00
use App\Utility\UI\IndexSetting ;
if ( empty ( $data [ 'table_setting_id' ]) && empty ( $model )) {
2021-10-20 09:39:12 +02:00
throw new Exception ( __ ( '`table_setting_id` must be set in order to use the `table_action` table topbar' ));
}
2021-11-10 09:06:39 +01:00
$data [ 'table_setting_id' ] = ! empty ( $data [ 'table_setting_id' ]) ? $data [ 'table_setting_id' ] : IndexSetting :: getIDFromTable ( $model );
$tableSettings = IndexSetting :: getTableSetting ( $loggedUser , $data [ 'table_setting_id' ]);
2021-10-20 11:28:39 +02:00
$compactDisplay = ! empty ( $tableSettings [ 'compact_display' ]);
2021-10-20 09:39:12 +02:00
$availableColumnsHtml = $this -> element ( '/genericElements/ListTopBar/group_table_action/hiddenColumns' , [
'table_data' => $table_data ,
'tableSettings' => $tableSettings ,
'table_setting_id' => $data [ 'table_setting_id' ],
]);
2021-11-10 09:06:39 +01:00
$metaTemplateColumnMenu = [];
if ( ! empty ( $meta_templates )) {
foreach ( $meta_templates as $meta_template ) {
$numberActiveMetaField = ! empty ( $tableSettings [ 'visible_meta_column' ][ $meta_template -> id ]) ? count ( $tableSettings [ 'visible_meta_column' ][ $meta_template -> id ]) : 0 ;
$metaTemplateColumnMenu [] = [
'text' => $meta_template -> name ,
'icon' => 'object-group' ,
'badge' => [
'text' => $numberActiveMetaField ,
'variant' => 'secondary' ,
'title' => __n ( '{0} meta-field active for this meta-template' , '{0} meta-fields active for this meta-template' , $numberActiveMetaField , $numberActiveMetaField ),
],
'keepOpen' => true ,
'menu' => [
[
'html' => $this -> element ( '/genericElements/ListTopBar/group_table_action/hiddenMetaColumns' , [
'tableSettings' => $tableSettings ,
'table_setting_id' => $data [ 'table_setting_id' ],
'meta_template' => $meta_template ,
])
]
],
];
}
}
$indexColumnMenu = array_merge ([[ 'html' => $availableColumnsHtml ]], $metaTemplateColumnMenu );
2021-10-20 11:28:39 +02:00
$compactDisplayHtml = $this -> element ( '/genericElements/ListTopBar/group_table_action/compactDisplay' , [
'table_data' => $table_data ,
'tableSettings' => $tableSettings ,
'table_setting_id' => $data [ 'table_setting_id' ],
'compactDisplay' => $compactDisplay
]);
2021-10-20 09:39:12 +02:00
?>
< ? php if ( ! isset ( $data [ 'requirement' ]) || $data [ 'requirement' ]) : ?>
< ? php
echo $this -> Bootstrap -> dropdownMenu ([
'dropdown-class' => 'ms-1' ,
'alignment' => 'end' ,
'direction' => 'down' ,
'toggle-button' => [
'icon' => 'sliders-h' ,
'variant' => 'primary' ,
],
'submenu_alignment' => 'end' ,
'submenu_direction' => 'start' ,
'params' => [
'data-table-random-value' => $tableRandomValue ,
'data-table_setting_id' => $data [ 'table_setting_id' ],
],
'menu' => [
[
'text' => __ ( 'Show/hide columns' ),
'icon' => 'eye-slash' ,
'keepOpen' => true ,
2021-11-10 09:06:39 +01:00
'menu' => $indexColumnMenu ,
2021-10-20 09:39:12 +02:00
],
[
2021-10-20 11:28:39 +02:00
'html' => $compactDisplayHtml ,
]
2021-10-20 09:39:12 +02:00
]
]);
?>
< ? php endif ; ?>