2020-12-07 16:06:01 +01:00
|
|
|
<?php
|
|
|
|
$contextArray = [];
|
2020-12-08 15:15:58 +01:00
|
|
|
foreach ($data['context_filters'] as $filteringContext) {
|
2020-12-08 15:08:12 +01:00
|
|
|
$filteringContext['filterCondition'] = empty($filteringContext['filterCondition']) ? [] : $filteringContext['filterCondition'];
|
2020-12-07 16:06:01 +01:00
|
|
|
$urlParams = [
|
|
|
|
'controller' => $this->request->getParam('controller'),
|
|
|
|
'action' => 'index',
|
2021-02-26 10:36:06 +01:00
|
|
|
'?' => array_merge($filteringContext['filterCondition'], ['filteringLabel' => $filteringContext['label']])
|
2020-12-07 16:06:01 +01:00
|
|
|
];
|
2020-12-08 15:08:12 +01:00
|
|
|
$currentQuery = $this->request->getQuery();
|
2021-02-26 10:36:06 +01:00
|
|
|
$filteringLabel = !empty($currentQuery['filteringLabel']) ? $currentQuery['filteringLabel'] : '';
|
|
|
|
unset($currentQuery['page'], $currentQuery['limit'], $currentQuery['sort'], $currentQuery['filteringLabel']);
|
2021-01-11 16:28:07 +01:00
|
|
|
if (!empty($filteringContext['filterCondition'])) { // PHP replaces `.` by `_` when fetching the request parameter
|
2021-02-24 11:10:52 +01:00
|
|
|
$currentFilteringContext = [];
|
|
|
|
foreach ($filteringContext['filterCondition'] as $currentFilteringContextKey => $value) {
|
2021-03-10 09:43:36 +01:00
|
|
|
$currentFilteringContextKey = str_replace('.', '_', $currentFilteringContextKey);
|
|
|
|
$currentFilteringContextKey = str_replace(' ', '_', $currentFilteringContextKey);
|
|
|
|
$currentFilteringContext[$currentFilteringContextKey] = $value;
|
2021-02-24 11:10:52 +01:00
|
|
|
}
|
2021-01-11 16:28:07 +01:00
|
|
|
} else {
|
|
|
|
$currentFilteringContext = $filteringContext['filterCondition'];
|
|
|
|
}
|
2020-12-07 16:06:01 +01:00
|
|
|
$contextArray[] = [
|
2021-02-26 10:36:06 +01:00
|
|
|
'active' => (
|
|
|
|
(
|
|
|
|
$currentQuery == $currentFilteringContext && // query conditions match
|
|
|
|
!isset($filteringContext['filterConditionFunction']) && // not a custom filtering
|
|
|
|
empty($filteringLabel) // do not check `All` by default
|
|
|
|
) ||
|
|
|
|
$filteringContext['label'] == $filteringLabel // labels should not be duplicated
|
|
|
|
),
|
2020-12-10 15:37:39 +01:00
|
|
|
'isFilter' => true,
|
2021-01-12 11:30:15 +01:00
|
|
|
'onClick' => 'changeIndexContext',
|
2020-12-10 15:37:39 +01:00
|
|
|
'onClickParams' => [
|
2021-01-12 11:30:15 +01:00
|
|
|
'this',
|
2021-02-24 11:10:52 +01:00
|
|
|
$this->Url->build($urlParams, [
|
|
|
|
'escape' => false, // URL builder escape `&` when multiple ? arguments
|
|
|
|
]),
|
2020-12-10 15:37:39 +01:00
|
|
|
"#table-container-${tableRandomValue}",
|
|
|
|
"#table-container-${tableRandomValue} table.table",
|
|
|
|
],
|
2020-12-08 15:08:12 +01:00
|
|
|
'text' => $filteringContext['label'],
|
2021-01-12 11:30:15 +01:00
|
|
|
'class' => 'btn-sm'
|
2020-12-07 16:06:01 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$dataGroup = [
|
|
|
|
'type' => 'simple',
|
|
|
|
'children' => $contextArray,
|
|
|
|
];
|
|
|
|
if (isset($data['requirement'])) {
|
|
|
|
$dataGroup['requirement'] = $data['requirement'];
|
|
|
|
}
|
2021-01-12 10:56:47 +01:00
|
|
|
echo '<div class="d-flex align-items-end topbar-contextual-filter">';
|
2020-12-07 16:06:01 +01:00
|
|
|
echo $this->element('/genericElements/ListTopBar/group_simple', [
|
2020-12-15 15:00:21 +01:00
|
|
|
'data' => $dataGroup,
|
|
|
|
'tableRandomValue' => $tableRandomValue
|
2021-01-12 10:56:47 +01:00
|
|
|
]);
|
2021-01-12 11:30:15 +01:00
|
|
|
echo '</div>';
|
|
|
|
?>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function changeIndexContext(clicked, url, container, statusNode) {
|
2021-01-15 12:15:36 +01:00
|
|
|
UI.reload(url, container, statusNode, [{
|
|
|
|
node: clicked,
|
|
|
|
config: {
|
|
|
|
spinnerVariant: 'dark',
|
|
|
|
spinnerType: 'grow',
|
|
|
|
spinnerSmall: true
|
|
|
|
}
|
|
|
|
}])
|
2021-01-12 11:30:15 +01:00
|
|
|
}
|
|
|
|
</script>
|