Skip to content

Commit

Permalink
GH-224 Move delete ignore entries input normalization to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 14, 2022
1 parent 529315d commit 3ac4e2f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
2 changes: 2 additions & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
include($includePath . './utils/helpers/tryEnableVacation.helper.php');
include($includePath . './utils/helpers/tryIgnoreUser.helper.php');

include($includePath . './utils/input/normalizeDeleteUserIgnoreEntries.input.php');

include($includePath . './utils/queries/createEmailChangeProcessEntry.query.php');
include($includePath . './utils/queries/createUserIgnoreEntry.query.php');
include($includePath . './utils/queries/deleteUserIgnoreEntries.query.php');
Expand Down
5 changes: 5 additions & 0 deletions modules/settings/utils/input/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace UniEngine\Engine\Modules\Settings\Utils\Input;

/**
* @param mixed $input
*/
function normalizeDeleteUserIgnoreEntries($input) {
if (
empty($input) ||
!is_array($input)
) {
return [];
}

$normalizedInput = array_map_withkeys($input, function ($value) {
return intval($value, 10);
});
$normalizedInput = array_filter($normalizedInput, function ($value) {
return $value > 0;
});

return $normalizedInput;
}

?>
29 changes: 7 additions & 22 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,25 +804,12 @@
$_Lang['SetActiveMarker'] = '05';
}

if($_POST['saveType'] == 'delignore')
{
if(!empty($_POST['del_ignore']) && (array)$_POST['del_ignore'] === $_POST['del_ignore'])
{
foreach($_POST['del_ignore'] as $Values)
{
$Values = intval($Values);
if($Values > 0)
{
$ToDelete[] = $Values;
}
}
}
if(!empty($ToDelete))
{
foreach($ToDelete as $ThisID)
{
if(!empty($_User['IgnoredUsers'][$ThisID]))
{
if ($_POST['saveType'] == 'delignore') {
$entriesToDelete = Settings\Utils\Input\normalizeDeleteUserIgnoreEntries($_POST['del_ignore']);

if (!empty($entriesToDelete)) {
foreach ($entriesToDelete as $ThisID) {
if (!empty($_User['IgnoredUsers'][$ThisID])) {
$IgnoreSystem_Deleted[] = $ThisID;
unset($_User['IgnoredUsers'][$ThisID]);
}
Expand All @@ -840,9 +827,7 @@
} else {
$WarningMsgs[] = $_Lang['Ignore_NothingDeleted'];
}
}
else
{
} else {
$WarningMsgs[] = $_Lang['Ignore_NothingSelected'];
}
}
Expand Down

0 comments on commit 3ac4e2f

Please sign in to comment.