Skip to content

Commit

Permalink
Merge pull request #874 from PennyDreadfulMTG/completed-fixes
Browse files Browse the repository at this point in the history
Various fixes, remove PHP Icons (really)
  • Loading branch information
bakert authored Dec 5, 2024
2 parents 0314a4f + 46a9fa8 commit e817c39
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 187 deletions.
2 changes: 2 additions & 0 deletions gatherling/Data/sql/migrations/81.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE events DROP COLUMN pkonly;
ALTER TABLE series DROP COLUMN pkonly_default;
2 changes: 2 additions & 0 deletions gatherling/Data/sql/migrations/82.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Remove unused column - every entry is null
ALTER TABLE entries DROP COLUMN notes;
4 changes: 4 additions & 0 deletions gatherling/Data/sql/migrations/83.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- It doesn't really make sense for a deck to exist without an event, yet there are 2500 such decks
-- The details are here should we decide we need them: https://gist.githubusercontent.com/bakert/b1eb9cecd606cbf541732310d48d11d9/raw/914917e5c0e0cd9e4d22598a301bf5965356c173/gistfile1.txt
DELETE FROM deckcontents WHERE deck IN (SELECT id FROM decks WHERE id NOT IN (SELECT deck FROM entries WHERE deck IS NOT NULL));
DELETE FROM decks WHERE id NOT IN (SELECT deck FROM entries WHERE deck IS NOT NULL);
4 changes: 4 additions & 0 deletions gatherling/Data/sql/migrations/84.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Get rid of The Player With No Name and all his manifestations
UPDATE events SET host = 'bakert99' WHERE host = '';
UPDATE events SET cohost = NULL WHERE cohost = '';
DELETE FROM players WHERE name= '';
9 changes: 3 additions & 6 deletions gatherling/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Event

// Class associations
public ?string $series = null; // belongs to Series
public ?string $host; // has one Player - host
public string $host; // has one Player - host
public ?string $cohost; // has one Player - cohost

// Subevents
Expand Down Expand Up @@ -74,7 +74,7 @@ public function __construct(int|string $name = '')
$this->mainstruct = '';
$this->finalrounds = 0;
$this->finalstruct = '';
$this->host = null;
$this->host = '';
$this->cohost = null;
$this->threadurl = '';
$this->reporturl = '';
Expand Down Expand Up @@ -296,9 +296,6 @@ public function save(): void
if ($this->cohost == '') {
$this->cohost = null;
}
if ($this->host == '') {
$this->host = null;
}
if ($this->finalized) {
$this->active = 0;
}
Expand Down Expand Up @@ -489,7 +486,7 @@ public function setFinalists(string $win, ?string $sec, array $t4, array $t8): v

public function isHost(string $name): bool
{
$ishost = !is_null($this->host) && strcasecmp($name, $this->host) == 0;
$ishost = strcasecmp($name, $this->host) == 0;
$iscohost = !is_null($this->cohost) && strcasecmp($name, $this->cohost) == 0;
return $ishost || $iscohost;
}
Expand Down
1 change: 0 additions & 1 deletion gatherling/Models/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Gatherling\Models;

use Gatherling\Exceptions\DatabaseException;
use Gatherling\Exceptions\NotFoundException;
use Gatherling\Exceptions\ValidationException;
use Gatherling\Models\PlayerDto;
Expand Down
2 changes: 1 addition & 1 deletion gatherling/Views/Components/AllMatchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(Player $player, string $selectedFormat, string $sele
$this->seriesDropMenuP = selector(opts($player->getSeriesPlayed()), 'series', '-- Series --', $selectedSeries ? $selectedSeries : '%');
$this->seasonDropMenuP = selector(opts($player->getSeasonsPlayed()), 'season', '-- Season --', $selectedSeason ? $selectedSeason : '%');
$opts = array_map(fn (array $item) => ['value' => $item['opp'], 'text' => $item['opp'] . ' [' . $item['cnt'] . ']'], $player->getOpponents());
$this->oppDropMenuP= selector($opts, 'opp', '-- Opponent --', $selectedOpponent ? $selectedOpponent : '%');
$this->oppDropMenuP = selector($opts, 'opp', '-- Opponent --', $selectedOpponent ? $selectedOpponent : '%');
}
}

Expand Down
2 changes: 1 addition & 1 deletion gatherling/Views/Components/DeckProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DeckProfile extends Component
{
public int $deckId;
public bool $canEdit;
public DeckErrorTable $deckErrorTable;
public ?DeckErrorTable $deckErrorTable = null;
public DeckInfoCell $deckInfoCell;
public MaindeckTable $maindeckTable;
public SideboardTable $sideboardTable;
Expand Down
16 changes: 4 additions & 12 deletions gatherling/Views/Components/HostEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,20 @@

class HostEvents extends Component
{
/** @var list<array{name: string, format: string, players: int, host: string, start: string, active: int, finalized: int, cohost: string, series: string, kvalueDisplay: string, link: string, isOngoing: bool, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string, startTime: Time}> */
/** @var list<array{name: string, players: int, start: string, active: int, finalized: int, series: string, link: string, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string, startTime: Time}> */
public array $pendingEvents = [];
/** @var list<array{name: string, format: string, players: int, host: string, start: string, active: int, finalized: int, cohost: string, series: string, kvalueDisplay: string, link: string, isOngoing: bool, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string, startTime: Time}> */
/** @var list<array{name: string, players: int, start: string, active: int, finalized: int, series: string, link: string, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string, startTime: Time}> */
public array $activeEvents = [];

public bool $hasPendingEvents;
public bool $hasActiveEvents;

public Icon $playersIcon;
public Icon $structureIcon;
public Icon $standingsIcon;

/**
* @param list<array{name: string, format: string, players: int, host: string, start: string, active: int, finalized: int, cohost: string, series: string, kvalueDisplay: string, link: string, isOngoing: bool, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> $pendingEvents
* @param list<array{name: string, format: string, players: int, host: string, start: string, active: int, finalized: int, cohost: string, series: string, kvalueDisplay: string, link: string, isOngoing: bool, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> $activeEvents
* @param list<array{name: string, players: int, start: string, active: int, finalized: int, series: string, link: string, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> $pendingEvents
* @param list<array{name: string, players: int, start: string, active: int, finalized: int, series: string, link: string, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> $activeEvents
*/
public function __construct(array $pendingEvents, array $activeEvents)
{
$this->playersIcon = new Icon('lucide:users');
$this->structureIcon = new Icon('lucide:trophy');
$this->standingsIcon = new Icon('lucide:chevron-right');

$this->hasPendingEvents = count($pendingEvents) > 0;
$this->hasActiveEvents = count($activeEvents) > 0;

Expand Down
3 changes: 0 additions & 3 deletions gatherling/Views/Components/MatchTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public function __construct(Player $player, string $selectedFormat, string $sele
$opponent = new Player($opp);

$event = $match->getEvent();
if (!$event->id) {
throw new NotFoundException("Event not found for match {$match->id}", 0, null, 'Event', [$match->id]);
}
$oppRating = $opponent->getRating('Composite', $event->start);
$oppDeck = $opponent->getDeckEvent($event->id);

Expand Down
7 changes: 0 additions & 7 deletions gatherling/Views/Components/Preregistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class Preregistration extends Component

public function __construct(Player $player)
{
if (!$player->name) {
throw new NotFoundException("Tried to display preregistration for a player with no name", 0, null, 'Player', []);
}

$upcomingEvents = Event::getUpcomingEvents($player->name);
$events = Event::getNextPreRegister();

Expand Down Expand Up @@ -68,9 +64,6 @@ public function __construct(Player $player)
}
$startingSoon = time() >= $eventStart;
$startTime = new Time($eventStart, $now);
if (!$event->id) {
throw new InvalidArgumentException("Event ID not found for event {$event->name}");
}
$entry = new Entry($event->id, $player->name);

$createDeckLink = $deckLink = null;
Expand Down
4 changes: 2 additions & 2 deletions gatherling/Views/Components/RecentEventsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class RecentEventsTable extends Component
{
/** @var array<array{eventLink: string, eventName: string, startTime: ?Time, playerCount: int, host: string, cohost: string}> */
public array $events;
public array $events = [];

public function __construct(public Series $series)
{
Expand All @@ -25,7 +25,7 @@ public function __construct(public Series $series)
'eventName' => $event->name,
'startTime' => $startTime,
'playerCount' => $event->getPlayerCount(),
'host' => $event->host ?? '',
'host' => $event->host,
'cohost' => $event->cohost ?? '',

];
Expand Down
2 changes: 1 addition & 1 deletion gatherling/Views/Components/UnverifiedPlayerCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class UnverifiedPlayerCell
{
public ?string $playerName;
public string $playerName;
public int|null|false $wins;
public int|null|false $losses;
public GameName $displayName;
Expand Down
1 change: 1 addition & 0 deletions gatherling/Views/Pages/EventForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Gatherling\Views\Components\StructDropMenu;
use Gatherling\Views\Components\TimeDropMenu;
use Gatherling\Views\Components\TrophyField;

use function Gatherling\Helpers\getObjectVarsCamelCase;
use function Safe\preg_match;

Expand Down
22 changes: 4 additions & 18 deletions gatherling/Views/Pages/EventList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Gatherling\Views\Components\HostEvents;
use Gatherling\Views\Components\SeasonDropMenu;
use Gatherling\Views\Components\SeriesDropMenu;
use Gatherling\Views\Components\Time;

use function Gatherling\Helpers\db;
use function Gatherling\Helpers\get;
Expand All @@ -24,9 +23,9 @@ class EventList extends Page
public SeriesDropMenu $seriesDropMenu;
public SeasonDropMenu $seasonDropMenu;
public bool $hasPlayerSeries;
/** @var list<array{name: string, format: string, players: int, host: string, start: string, active: int, finalized: int, cohost: string, series: string, kvalueDisplay: string, link: string, isOngoing: bool, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> */
/** @var list<array{name: string, players: int, start: string, active: int, finalized: int, series: string, link: string, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> */
public array $upcomingEvents;
/** @var list<array{name: string, format: string, players: int, host: string, start: string, active: int, finalized: int, cohost: string, series: string, kvalueDisplay: string, link: string, isOngoing: bool, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> */
/** @var list<array{name: string, players: int, start: string, active: int, finalized: int, series: string, link: string, currentRound: int, settingsLink: string, registrationLink: string, matchesLink: string, standingsLink: string, structureSummary: string}> */
public array $pastEvents;
public bool $hasMore;

Expand All @@ -39,31 +38,18 @@ public function __construct(string $seriesName, string $format, ?int $season)
$events = queryEvents($player, $playerSeries, $seriesName, $format, $season);
$hasMore = count($events) == 100;

$kvalueMap = [
0 => 'none',
8 => 'Casual',
16 => 'Regular',
24 => 'Large',
32 => 'Championship',
];

$pendingEvents = $activeEvents = $upcomingEvents = $pastEvents = $seriesShown = [];
foreach ($events as $event) {
$seriesShown[] = $event->series;
$baseLink = 'event.php?name=' . rawurlencode($event->name) . '&view=';
$eventInfo = [
'name' => $event->name,
'format' => $event->format,
'players' => $event->players,
'host' => $event->host,
'start' => $event->start,
'active' => $event->active,
'finalized' => $event->finalized,
'cohost' => $event->cohost ?? '',
'series' => $event->series,
'kvalueDisplay' => $kvalueMap[$event->kvalue] ?? '',
'link' => 'event.php?name=' . rawurlencode($event->name),
'isOngoing' => $event->finalized == 0 && $event->active == 1,
'currentRound' => $event->current_round,
'settingsLink' => "{$baseLink}settings",
'registrationLink' => "{$baseLink}reg",
Expand Down Expand Up @@ -106,8 +92,8 @@ public function __construct(string $seriesName, string $format, ?int $season)
function queryEvents(Player $player, array $playerSeries, string $seriesName, string $format, ?int $season): array
{
$sql = '
SELECT e.name, e.format, COUNT(DISTINCT n.player) AS players, e.host, e.start,
e.active, e.finalized, e.cohost, e.series, e.kvalue, e.current_round
SELECT e.name, COUNT(DISTINCT n.player) AS players, e.start, e.active,
e.finalized, e.series, e.current_round
FROM events e
LEFT JOIN entries AS n ON n.event_id = e.id
WHERE (e.host = :player_name OR e.cohost = :player_name OR e.series IN (:series_names))';
Expand Down
Loading

0 comments on commit e817c39

Please sign in to comment.