diff options
Diffstat (limited to 'mtg-pdf.php')
-rw-r--r-- | mtg-pdf.php | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/mtg-pdf.php b/mtg-pdf.php index b5e9fb2..068c91e 100644 --- a/mtg-pdf.php +++ b/mtg-pdf.php @@ -25,6 +25,10 @@ for ($idx = 0; $idx < count($matches[0]); $idx++) { ]; } +if (empty($cards)) { + die("Couldn't find any cards matching the pattern."); +} + /* * Select data from DB */ @@ -33,21 +37,32 @@ $db = new \PDO('sqlite:AllPrintings.sqlite'); $images = []; foreach ($cards as $card) { - $query = 'SELECT scryfallId,layout from cardIdentifiers JOIN cards on cardIdentifiers.uuid=cards.uuid WHERE cards.setCode=:setCode AND cards.number=:number'; + $query = <<<SQL + SELECT cardIdentifiers.scryfallId, cards.layout + FROM cardIdentifiers + JOIN cards ON cardIdentifiers.uuid=cards.uuid + WHERE (cards.name=:name OR cards.faceName=:name) AND cards.setCode=:setCode AND cards.number=:number + SQL; $statement = $db->prepare($query); - $statement->execute(['setCode' => $card['set'], 'number' => $card['number']]); + $statement->execute(['name' => $card['name'], 'setCode' => $card['set'], 'number' => $card['number']]); $result = $statement->fetch(); $id = $result['scryfallId'] ?? ''; if (empty($id)) { - $query = 'SELECT scryfallId,layout from tokenIdentifiers JOIN tokens on tokenIdentifiers.uuid=tokens.uuid WHERE tokens.setCode=:setCode AND tokens.number=:number'; + $query = <<<SQL + SELECT tokenIdentifiers.scryfallId, tokens.layout + FROM tokenIdentifiers + JOIN tokens ON tokenIdentifiers.uuid=tokens.uuid + WHERE (tokens.name=:name OR tokens.faceName=:name) AND tokens.setCode=:setCode AND tokens.number=:number + SQL; $statement = $db->prepare($query); - $statement->execute(['setCode' => $card['set'], 'number' => $card['number']]); + $statement->execute(['name' => $card['name'], 'setCode' => $card['set'], 'number' => $card['number']]); $result = $statement->fetch(); $id = $result['scryfallId'] ?? ''; if (empty($id)) { echo "$card[name] ($card[set]) $card[number] not found."; + echo php_sapi_name() == 'cli' ? "\n" : '<br>'; continue; } } @@ -67,6 +82,10 @@ foreach ($cards as $card) { } } +if (empty($images)) { + die('No cards to print.'); +} + /* * Build HTML */ |