This commit is contained in:
2026-04-13 22:31:06 +02:00
parent 38259bc706
commit e15b4ccf45
24 changed files with 1580 additions and 3858 deletions

View File

@@ -145,6 +145,33 @@ final class PrintApiController
);
}
public function status(Request $request): Response
{
$raw = trim((string) $request->input('package_ids', ''));
if ($raw === '') {
return Response::json(['pending' => []]);
}
$ids = [];
foreach (explode(',', $raw) as $part) {
$id = (int) trim($part);
if ($id > 0) {
$ids[] = $id;
}
if (count($ids) >= 100) {
break;
}
}
if ($ids === []) {
return Response::json(['pending' => []]);
}
$pending = $this->printJobs->filterPendingPackageIds($ids);
return Response::json(['pending' => $pending]);
}
public function markComplete(Request $request): Response
{
$jobId = (int) $request->input('id', 0);

View File

@@ -107,6 +107,34 @@ final class PrintJobRepository
return is_array($rows) ? array_map('intval', $rows) : [];
}
/**
* @param list<int> $packageIds
* @return list<int>
*/
public function filterPendingPackageIds(array $packageIds): array
{
if ($packageIds === []) {
return [];
}
$placeholders = [];
$bindings = [];
foreach (array_values($packageIds) as $index => $id) {
$key = ':pkg_' . $index;
$placeholders[] = $key;
$bindings[$key] = (int) $id;
}
$sql = 'SELECT DISTINCT package_id FROM print_jobs '
. "WHERE status = 'pending' AND package_id IN (" . implode(', ', $placeholders) . ')';
$statement = $this->pdo->prepare($sql);
$statement->execute($bindings);
$rows = $statement->fetchAll(PDO::FETCH_COLUMN);
return is_array($rows) ? array_map('intval', $rows) : [];
}
/**
* @return array<string, mixed>|null
*/