<commit_before><?php declare(strict_types=1);

$template = Smr\Template::getInstance();
$session = Smr\Session::getInstance();
$var = $session->getCurrentVar();
$player = $session->getPlayer();

$allianceID = $var['alliance_id'] ?? $player->getAllianceID();

$alliance = SmrAlliance::getAlliance($allianceID, $player->getGameID());
$template->assign('PageTopic', $alliance->getAllianceDisplayName(false, true));
Menu::alliance($alliance->getAllianceID());

$db = Smr\Database::getInstance();
$dbResult = $db->read('
SELECT
sum(mines) as tot_mines,
sum(combat_drones) as tot_cds,
sum(scout_drones) as tot_sds
FROM sector_has_forces JOIN player ON player.game_id=sector_has_forces.game_id AND sector_has_forces.owner_id=player.account_id
WHERE player.game_id=' . $db->escapeNumber($alliance->getGameID()) . '
AND player.alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . '
AND expire_time >= ' . $db->escapeNumber(Smr\Epoch::time()));

$hardwareTypes = Globals::getHardwareTypes();

$total = [];
$totalCost = [];
if ($dbResult->hasRecord()) {
	$dbRecord = $dbResult->record();
	// Get total number of forces
	$total['Mines'] = $dbRecord->getInt('tot_mines');
	$total['CDs'] = $dbRecord->getInt('tot_cds');
	$total['SDs'] = $dbRecord->getInt('tot_sds');
	// Get total cost of forces
	$totalCost['Mines'] = $total['Mines'] * $hardwareTypes[HARDWARE_MINE]['Cost'];
	$totalCost['CDs'] = $total['CDs'] * $hardwareTypes[HARDWARE_COMBAT]['Cost'];
	$totalCost['SDs'] = $total['SDs'] * $hardwareTypes[HARDWARE_SCOUT]['Cost'];
}
$template->assign('Total', $total);
$template->assign('TotalCost', $totalCost);

$dbResult = $db->read('
SELECT sector_has_forces.*
FROM player
JOIN sector_has_forces ON player.game_id = sector_has_forces.game_id AND player.account_id = sector_has_forces.owner_id
WHERE player.game_id=' . $db->escapeNumber($alliance->getGameID()) . '
AND player.alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . '
AND expire_time >= ' . $db->escapeNumber(Smr\Epoch::time()) . '
ORDER BY sector_id ASC');

$forces = [];
foreach ($dbResult->records() as $dbRecord) {
	$forces[] = SmrForce::getForce($player->getGameID(), $dbRecord->getInt('sector_id'), $dbRecord->getInt('owner_id'), false, $dbRecord);
}
$template->assign('Forces', $forces);<commit_msg>alliance_forces.php: fix SQL error due to null<commit_after><?php declare(strict_types=1);

$template = Smr\Template::getInstance();
$session = Smr\Session::getInstance();
$var = $session->getCurrentVar();
$player = $session->getPlayer();

$allianceID = $var['alliance_id'] ?? $player->getAllianceID();

$alliance = SmrAlliance::getAlliance($allianceID, $player->getGameID());
$template->assign('PageTopic', $alliance->getAllianceDisplayName(false, true));
Menu::alliance($alliance->getAllianceID());

$db = Smr\Database::getInstance();
$dbResult = $db->read('
SELECT
	IFNULL(sum(mines), 0) as tot_mines,
	IFNULL(sum(combat_drones), 0) as tot_cds,
	IFNULL(sum(scout_drones), 0) as tot_sds
FROM sector_has_forces JOIN player ON player.game_id=sector_has_forces.game_id AND sector_has_forces.owner_id=player.account_id
WHERE player.game_id=' . $db->escapeNumber($alliance->getGameID()) . '
	AND player.alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . '
	AND expire_time >= ' . $db->escapeNumber(Smr\Epoch::time()));
$dbRecord = $dbResult->record();

// Get total number of forces
$total = [
	'Mines' => $dbRecord->getInt('tot_mines'),
	'CDs' => $dbRecord->getInt('tot_cds'),
	'SDs' => $dbRecord->getInt('tot_sds'),
];
$template->assign('Total', $total);

	// Get total cost of forces
$hardwareTypes = Globals::getHardwareTypes();
$totalCost = [
	'Mines' => $total['Mines'] * $hardwareTypes[HARDWARE_MINE]['Cost'],
	'CDs' => $total['CDs'] * $hardwareTypes[HARDWARE_COMBAT]['Cost'],
	'SDs' => $total['SDs'] * $hardwareTypes[HARDWARE_SCOUT]['Cost'],
];
$template->assign('TotalCost', $totalCost);

$dbResult = $db->read('
SELECT sector_has_forces.*
FROM player
JOIN sector_has_forces ON player.game_id = sector_has_forces.game_id AND player.account_id = sector_has_forces.owner_id
WHERE player.game_id=' . $db->escapeNumber($alliance->getGameID()) . '
AND player.alliance_id=' . $db->escapeNumber($alliance->getAllianceID()) . '
AND expire_time >= ' . $db->escapeNumber(Smr\Epoch::time()) . '
ORDER BY sector_id ASC');

$forces = [];
foreach ($dbResult->records() as $dbRecord) {
	$forces[] = SmrForce::getForce($player->getGameID(), $dbRecord->getInt('sector_id'), $dbRecord->getInt('owner_id'), false, $dbRecord);
}
$template->assign('Forces', $forces);
{'fraction_non_alphanumeric': 0.19845984598459845, 'fraction_numerical': 0.0011001100110011, 'mean_word_length': 7.402957486136784, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380969', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1608, 'n_words': 262}