fix: [internal] Code cleanup

pull/8317/head
Jakub Onderka 2022-05-01 14:38:21 +02:00
parent ce2a2ecc9a
commit fa26e9836f
2 changed files with 12 additions and 23 deletions

View File

@ -83,14 +83,14 @@ class CustomPaginationTool
$items = array_values($items);
}
public function sortArray($items, $params, $escapeReindex = false)
public function sortArray(array $items, $params, $escapeReindex = false)
{
if (isset($params['sort'])) {
$sortArray = array();
foreach ($items as $k => $item) {
$sortArray[$k] = !empty(Hash::get($item, $params['sort'])) ? $item[$params['sort']] : '';
$sortArray[$k] = !empty($item[$params['sort']]) ? $item[$params['sort']] : '';
}
if (empty($params['options']['direction']) || $params['options']['direction'] == 'asc') {
if (empty($params['options']['direction']) || $params['options']['direction'] === 'asc') {
asort($sortArray);
} else {
arsort($sortArray);
@ -107,12 +107,13 @@ class CustomPaginationTool
return $items;
}
public function applyRulesOnArray(&$items, $options, $model, $sort = 'id', $focusKey = 'uuid', $escapeReindex = false)
public function applyRulesOnArray(array &$items, $options, $model, $sort = 'id', $focusKey = 'uuid', $escapeReindex = false)
{
$params = $this->createPaginationRules($items, $options, $model, $sort, $focusKey);
$items = $this->sortArray($items, $params, $escapeReindex);
if (!empty($params['options']['focus'])) {
$focus = $params['options']['focus'];
$focus = $params['options']['focus'];
foreach ($items as $k => $item) {
if ($item[$focusKey] === $focus) {
$params['page'] = 1 + intval(floor($k / $params['limit']));
@ -122,6 +123,7 @@ class CustomPaginationTool
}
unset($params['options']['focus']);
}
// Start array from one
array_unshift($items, 'dummy');
unset($items[0]);
$this->truncateByPagination($items, $params);

View File

@ -1,20 +1,8 @@
<?php
$mayChangeCorrelation = !Configure::read('MISP.completely_disable_correlation') && ($isSiteAdmin || ($mayModify && Configure::read('MISP.allow_disabling_correlation')));
$possibleAction = $mayModify ? 'attribute' : 'shadow_attribute';
$all = false;
if (isset($this->params->params['paging']['Event']['page'])) {
if ($this->params->params['paging']['Event']['page'] == 0) $all = true;
$page = $this->params->params['paging']['Event']['page']; // $page is probably unused
} else {
$page = 0; // $page is probably unused
}
$all = isset($this->params->params['paging']['Event']['page']) && $this->params->params['paging']['Event']['page'] == 0;
$fieldCount = 11;
$filtered = false;
if (isset($passedArgsArray)){
if (count($passedArgsArray) > 0) {
$filtered = true;
}
}
?>
<div class="pagination">
<ul>
@ -35,7 +23,7 @@
$paginatorLinks .= $this->Paginator->next(__('next') . ' &raquo;', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
echo $paginatorLinks;
?>
<li class="all <?php if ($all) echo 'disabled'; ?>">
<li class="all<?php if ($all) echo ' disabled'; ?>">
<?php
if ($all):
echo '<span class="red">' . __('view all') . '</span>';
@ -85,7 +73,6 @@
<?php
echo $this->element('eventattributetoolbar', [
'attributeFilter' => $attributeFilter,
'filtered' => $filtered,
'mayModify' => $mayModify,
'possibleAction' => $possibleAction
]);
@ -168,13 +155,13 @@
</table>
<?php
// Generate form for adding sighting just once, generation for every attribute is surprisingly too slow
echo $this->Form->create('Sighting', ['id' => 'SightingForm', 'url' => $baseurl . '/sightings/add/', 'style' => 'display:none;']);
echo $this->Form->create('Sighting', ['id' => 'SightingForm', 'url' => $baseurl . '/sightings/add/', 'style' => 'display:none']);
echo $this->Form->input('id', ['label' => false, 'type' => 'number']);
echo $this->Form->input('type', ['label' => false]);
echo $this->Form->end();
?>
</div>
<?php if ($emptyEvent && (empty($attributeFilter) || $attributeFilter === 'all') && !$filtered): ?>
<?php if ($emptyEvent && (empty($attributeFilter) || $attributeFilter === 'all') && empty($passedArgsArray)): ?>
<div class="background-red bold" style="padding: 2px 5px">
<?php
if ($me['org_id'] != $event['Event']['orgc_id']) {
@ -190,7 +177,7 @@ attributes or the appropriate distribution level. If you think there is a mistak
<div class="pagination">
<ul>
<?= $paginatorLinks ?>
<li class="all <?php if ($all) echo 'disabled'; ?>">
<li class="all<?php if ($all) echo ' disabled'; ?>">
<?php
if ($all):
echo '<span class="red">' . __('view all') . '</span>';