diff --git a/gatherling/api.php b/gatherling/api.php index 69e78847c..2aca53026 100644 --- a/gatherling/api.php +++ b/gatherling/api.php @@ -192,6 +192,14 @@ $result['key'] = $player->setApiKey(); break; + case 'known_cards_catalog': + $result = card_catalog(); + break; + + case 'cardname_from_id': + $result = cardname_from_id(arg('id')); + break; + default: $result['error'] = "Unknown action '{$action}'"; break; diff --git a/gatherling/api_lib.php b/gatherling/api_lib.php index b8fc1f41c..9a8fcb08a 100644 --- a/gatherling/api_lib.php +++ b/gatherling/api_lib.php @@ -4,6 +4,7 @@ //## Helper Functions +use Gatherling\Database; use Gatherling\Event; use Gatherling\Player; use Gatherling\Series; @@ -429,3 +430,24 @@ function create_pairing($event, $round, $a, $b, $res) $event->addMatch($playerA, $playerB, $round, $res, $pAWins, $pBWins); } } + +/** @return string[] */ +function card_catalog() +{ + $result = []; + $db = Database::getConnection(); + $query = $db->query('SELECT c.name as name FROM cards c'); + while ($row = $query->fetch_assoc()) { + if (!in_array($row['name'], $result)) { + $result[] = $row['name']; + } + } + $query->close(); + return $result; +} + +function cardname_from_id($id) { + $sql = "SELECT c.name as name FROM cards c WHERE c.scryfallId = ?"; + $name = Database::single_result_single_param($sql, 's', $id); + return $name; +}