From c7c558d09e178c688ac6775a0d124aee3eec5b00 Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Mon, 7 Aug 2023 05:06:05 +1000 Subject: [PATCH 1/6] Waiting On API --- gatherling/api_lib.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gatherling/api_lib.php b/gatherling/api_lib.php index 0cfde6558..b8fc1f41c 100644 --- a/gatherling/api_lib.php +++ b/gatherling/api_lib.php @@ -131,6 +131,7 @@ function repr_json_event($event) if ($matches) { $json['matches'] = []; $json['unreported'] = []; + $json['waiting_on'] = []; $addrounds = 0; $roundnum = 0; $timing = 0; @@ -143,6 +144,7 @@ function repr_json_event($event) if ($roundnum != $m->round) { $roundnum = $m->round; $json['unreported'] = []; + $json['waiting_on'] = []; } $data['round'] = $m->round + $addrounds; $json['matches'][] = $data; @@ -153,6 +155,11 @@ function repr_json_event($event) if (!$m->reportSubmitted($m->playerb)) { $json['unreported'][] = $m->playerb; } + if (!$m->reportSubmitted($m->playera) && $m->reportSubmitted($m->playerb)) { + $json['waiting_on'][] = $m->playera; + } elseif ($m->reportSubmitted($m->playera) && !$m->reportSubmitted($m->playerb)) { + $json['waiting_on'][] = $m->playerb; + } } } } From 25094cb06f112d7cfbc4d11b64423e15abcd7acc Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Thu, 26 Oct 2023 12:28:25 +1100 Subject: [PATCH 2/6] Start event without checks --- gatherling/event.php | 8 ++++++-- gatherling/models/Event.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gatherling/event.php b/gatherling/event.php index 192bd9534..2f26544b8 100644 --- a/gatherling/event.php +++ b/gatherling/event.php @@ -276,7 +276,9 @@ function content() authFailed(); } else { if (mode_is('Start Event')) { - $event->startEvent(); + $event->startEvent(true); + } elseif (mode_is('Start Event (No Deck Check)')) { + $event->startEvent(false); } elseif (mode_is('Recalculate Standings')) { $structure = $event->mainstruct; $event->recalculateScores($structure); @@ -851,7 +853,9 @@ function playerList($event) echo "name}\" />"; echo ''; if ($event->active == 0 && $event->finalized == 0) { - echo ''; + echo ''; echo '

Paste stuff:
'; echo "{$deckless}

"; } elseif ($event->active == 1) { diff --git a/gatherling/models/Event.php b/gatherling/models/Event.php index 637cf2b52..3386ea8e5 100644 --- a/gatherling/models/Event.php +++ b/gatherling/models/Event.php @@ -1827,9 +1827,9 @@ public function updateDecksFormat($format) } } - public function startEvent() + public function startEvent($precheck) { - $entries = $this->getRegisteredEntries(true); + $entries = $this->getRegisteredEntries($precheck); Standings::startEvent($entries, $this->name); // $this->dropInvalidEntries(); $this->pairCurrentRound(); From 0f2bab5fe35c3883c39cfb4c34e30213e403d468 Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Sat, 28 Oct 2023 12:44:47 +1100 Subject: [PATCH 3/6] Card Catalogue for client-side validation --- gatherling/api.php | 8 ++++++++ gatherling/api_lib.php | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) 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; +} From 65ccd8712738e44a3cc038a018aa2b2eacd7e434 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 28 Oct 2023 01:45:09 +0000 Subject: [PATCH 4/6] Apply fixes from StyleCI --- gatherling/api_lib.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gatherling/api_lib.php b/gatherling/api_lib.php index 9a8fcb08a..98492eb33 100644 --- a/gatherling/api_lib.php +++ b/gatherling/api_lib.php @@ -443,11 +443,14 @@ function card_catalog() } } $query->close(); + return $result; } -function cardname_from_id($id) { - $sql = "SELECT c.name as name FROM cards c WHERE c.scryfallId = ?"; +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; } From a9635eb7b3bc5d6bafe3966371cc8e057c906c55 Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Sun, 29 Oct 2023 15:36:23 +1100 Subject: [PATCH 5/6] A whole bunch of PHPDocs --- gatherling/api_lib.php | 5 +++++ tests/EventsTest.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gatherling/api_lib.php b/gatherling/api_lib.php index 98492eb33..8d0adbb0e 100644 --- a/gatherling/api_lib.php +++ b/gatherling/api_lib.php @@ -447,6 +447,11 @@ function card_catalog() return $result; } +/** + * @param string $id + * @return string + * @throws Exception + */ function cardname_from_id($id) { $sql = 'SELECT c.name as name FROM cards c WHERE c.scryfallId = ?'; diff --git a/tests/EventsTest.php b/tests/EventsTest.php index 1494941f8..fb0bc0a08 100644 --- a/tests/EventsTest.php +++ b/tests/EventsTest.php @@ -8,10 +8,17 @@ use Gatherling\Event; use Gatherling\Matchup; use Gatherling\Series; +use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; +use SebastianBergmann\RecursionContext\InvalidArgumentException; final class EventsTest extends TestCase { + /** + * @return Series + * @throws InvalidArgumentException + * @throws ExpectationFailedException + */ public function testSeriesCreation() { if (!Series::exists('Test')) { @@ -30,6 +37,11 @@ public function testSeriesCreation() } /** + * @param Series $series + * @return Event + * @throws Exception + * @throws InvalidArgumentException + * @throws ExpectationFailedException * @depends testSeriesCreation */ public function testEventCreation($series) @@ -78,6 +90,11 @@ public function testEventCreation($series) } /** + * @param Event $event + * @return Event + * @throws InvalidArgumentException + * @throws ExpectationFailedException + * @throws Exception * @depends testEventCreation */ public function testRegistration($event) @@ -113,6 +130,10 @@ public function testRegistration($event) } /** + * @param Event $event + * @return Event + * @throws InvalidArgumentException + * @throws ExpectationFailedException * @depends testRegistration */ public function testEventStart($event) @@ -120,7 +141,7 @@ public function testEventStart($event) $this->assertEquals($event->active, 0); $this->assertEquals($event->current_round, 0); - $event->startEvent(); + $event->startEvent(True); $event = new Event($event->name); $this->assertEquals($event->active, 1); @@ -130,6 +151,10 @@ public function testEventStart($event) } /** + * @param Event $event + * @return mixed + * @throws InvalidArgumentException + * @throws ExpectationFailedException * @depends testEventStart */ public function testReporting($event) @@ -151,6 +176,14 @@ public function testReporting($event) } } +/** + * @param string $player + * @param Event $event + * @param string $main + * @param string $side + * @return Deck + * @throws Exception + */ function insertDeck($player, $event, $main, $side) { $deck = new Deck(0); From 16a519773815a36cf57185c94b1428d6488439e6 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 29 Oct 2023 04:39:58 +0000 Subject: [PATCH 6/6] Apply fixes from StyleCI --- gatherling/api_lib.php | 4 +++- tests/EventsTest.php | 31 +++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/gatherling/api_lib.php b/gatherling/api_lib.php index 8d0adbb0e..28261d04c 100644 --- a/gatherling/api_lib.php +++ b/gatherling/api_lib.php @@ -449,8 +449,10 @@ function card_catalog() /** * @param string $id - * @return string + * * @throws Exception + * + * @return string */ function cardname_from_id($id) { diff --git a/tests/EventsTest.php b/tests/EventsTest.php index fb0bc0a08..b3c947f0e 100644 --- a/tests/EventsTest.php +++ b/tests/EventsTest.php @@ -15,9 +15,10 @@ final class EventsTest extends TestCase { /** - * @return Series * @throws InvalidArgumentException * @throws ExpectationFailedException + * + * @return Series */ public function testSeriesCreation() { @@ -38,10 +39,13 @@ public function testSeriesCreation() /** * @param Series $series - * @return Event + * * @throws Exception * @throws InvalidArgumentException * @throws ExpectationFailedException + * + * @return Event + * * @depends testSeriesCreation */ public function testEventCreation($series) @@ -91,10 +95,13 @@ public function testEventCreation($series) /** * @param Event $event - * @return Event + * * @throws InvalidArgumentException * @throws ExpectationFailedException * @throws Exception + * + * @return Event + * * @depends testEventCreation */ public function testRegistration($event) @@ -131,9 +138,12 @@ public function testRegistration($event) /** * @param Event $event - * @return Event + * * @throws InvalidArgumentException * @throws ExpectationFailedException + * + * @return Event + * * @depends testRegistration */ public function testEventStart($event) @@ -141,7 +151,7 @@ public function testEventStart($event) $this->assertEquals($event->active, 0); $this->assertEquals($event->current_round, 0); - $event->startEvent(True); + $event->startEvent(true); $event = new Event($event->name); $this->assertEquals($event->active, 1); @@ -152,9 +162,12 @@ public function testEventStart($event) /** * @param Event $event - * @return mixed + * * @throws InvalidArgumentException * @throws ExpectationFailedException + * + * @return mixed + * * @depends testEventStart */ public function testReporting($event) @@ -178,11 +191,13 @@ public function testReporting($event) /** * @param string $player - * @param Event $event + * @param Event $event * @param string $main * @param string $side - * @return Deck + * * @throws Exception + * + * @return Deck */ function insertDeck($player, $event, $main, $side) {
Round Actions
'; + echo ''; + echo '