Skip to content

Commit

Permalink
GH-224 Move moving fleets counter fetcher to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 13, 2022
1 parent 539f51b commit 1cf6817
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
include($includePath . './utils/errorMappers/validateEmailChange.errorMapper.php');

include($includePath . './utils/queries/createEmailChangeProcessEntry.query.php');
include($includePath . './utils/queries/getMovingFleetsCount.query.php');
include($includePath . './utils/queries/getUserWithEmailAddress.query.php');

include($includePath . './utils/validators/validatePasswordChange.validator.php');
Expand Down
27 changes: 27 additions & 0 deletions modules/settings/utils/queries/getMovingFleetsCount.query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

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

/**
* @param array $params
* @param string $params['userId']
*/
function getMovingFleetsCount($params) {
$userId = $params['userId'];

$query = (
"SELECT " .
"COUNT(*) AS `fleetsCount` " .
"FROM {{table}} " .
"WHERE " .
"`fleet_owner` = {$userId} OR " .
"`fleet_target_owner` = {$userId} " .
";"
);

$result = doquery($query, 'fleets', true);

return $result['fleetsCount'];
}

?>
6 changes: 3 additions & 3 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@
$WarningMsgs[] = $_Lang['Vacation_24hNotPassed'];
}

$checkFleets = doquery("SELECT COUNT(*) AS `Count` FROM {{table}} WHERE `fleet_owner` = {$_User['id']} OR `fleet_target_owner` = {$_User['id']};", 'fleets', true);
if($checkFleets['Count'] > 0)
{
$movingFleetsCount = Settings\Utils\Queries\getMovingFleetsCount([ 'userId' => $_User['id'] ]);

if ($movingFleetsCount > 0) {
$allowVacation = false;
$WarningMsgs[] = $_Lang['Vacation_FlyingFleets'];
}
Expand Down

0 comments on commit 1cf6817

Please sign in to comment.