diff --git a/gatherling/Views/Components/HostEvents.php b/gatherling/Views/Components/HostEvents.php index b94797e17..758696c89 100644 --- a/gatherling/Views/Components/HostEvents.php +++ b/gatherling/Views/Components/HostEvents.php @@ -6,25 +6,41 @@ use function Safe\strtotime; -class HostActiveEvents extends Component +class HostEvents extends Component { - /** @var array */ - public array $events = []; + /** @var list */ + public array $pendingEvents = []; + /** @var list */ + public array $activeEvents = []; + + public bool $hasPendingEvents; + public bool $hasActiveEvents; + public Icon $playersIcon; public Icon $structureIcon; public Icon $standingsIcon; - /** @param array $events */ - public function __construct(array $events) + /** + * @param list $pendingEvents + * @param list $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; + $now = time(); - foreach ($events as $event) { + foreach ($pendingEvents as $event) { + $event['startTime'] = new Time(strtotime($event['start']), $now); + $this->pendingEvents[] = $event; + } + foreach ($activeEvents as $event) { $event['startTime'] = new Time(strtotime($event['start']), $now); - $this->events[] = $event; + $this->activeEvents[] = $event; } } } diff --git a/gatherling/Views/Components/ResultDropMenu.php b/gatherling/Views/Components/ResultDropMenu.php index 226f70b97..bbb9dec5e 100644 --- a/gatherling/Views/Components/ResultDropMenu.php +++ b/gatherling/Views/Components/ResultDropMenu.php @@ -6,10 +6,7 @@ class ResultDropMenu extends DropMenu { - /** - * @param array $extraOptions - * @return array{name: string, default: string, options: array} - */ + /** @param array $extraOptions */ public function __construct(string $name, array $extraOptions = []) { $options = [ diff --git a/gatherling/Views/Pages/EventList.php b/gatherling/Views/Pages/EventList.php index 533f6fb47..d35774d24 100644 --- a/gatherling/Views/Pages/EventList.php +++ b/gatherling/Views/Pages/EventList.php @@ -8,9 +8,10 @@ use Gatherling\Models\HostedEventDto; use Gatherling\Models\Player; use Gatherling\Views\Components\FormatDropMenu; -use Gatherling\Views\Components\HostActiveEvents; +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; @@ -18,13 +19,15 @@ class EventList extends Page { - public ?HostActiveEvents $hostActiveEvents; + public ?HostEvents $hostEvents; public FormatDropMenu $formatDropMenu; public SeriesDropMenu $seriesDropMenu; public SeasonDropMenu $seasonDropMenu; public bool $hasPlayerSeries; /** @var list */ - public array $events = []; + public array $upcomingEvents; + /** @var list */ + public array $pastEvents; public bool $hasMore; public function __construct(string $seriesName, string $format, ?int $season) @@ -44,7 +47,7 @@ public function __construct(string $seriesName, string $format, ?int $season) 32 => 'Championship', ]; - $activeEvents = $seriesShown = []; + $pendingEvents = $activeEvents = $upcomingEvents = $pastEvents = $seriesShown = []; foreach ($events as $event) { $seriesShown[] = $event->series; $baseLink = 'event.php?name=' . rawurlencode($event->name) . '&view='; @@ -68,11 +71,18 @@ public function __construct(string $seriesName, string $format, ?int $season) 'standingsLink' => "{$baseLink}standings", 'structureSummary' => (new Event($event->name))->structureSummary(), ]; - $this->events[] = $eventInfo; - if ($event->active == 1 || (!$event->finalized && strtotime($event->start) <= strtotime('+1 day'))) { + if (!$event->active && !$event->finalized && strtotime($event->start) <= strtotime('+1 hour')) { + $pendingEvents[] = $eventInfo; + } elseif ($event->active == 1) { $activeEvents[] = $eventInfo; + } elseif (strtotime($event->start) > strtotime('+1 hour')) { + $upcomingEvents[] = $eventInfo; + } else { + $pastEvents[] = $eventInfo; } } + $this->upcomingEvents = array_reverse($upcomingEvents); + $this->pastEvents = $pastEvents; if ($seriesName) { $seriesShown = $playerSeries; @@ -80,7 +90,7 @@ public function __construct(string $seriesName, string $format, ?int $season) $seriesShown = array_values(array_unique($seriesShown)); } - $this->hostActiveEvents = count($activeEvents) > 0 ? new HostActiveEvents($activeEvents) : null; + $this->hostEvents = new HostEvents($pendingEvents, $activeEvents); $this->formatDropMenu = new FormatDropMenu(get()->optionalString('format'), true); $this->seriesDropMenu = new SeriesDropMenu($seriesName, 'All', $seriesShown); $this->seasonDropMenu = new SeasonDropMenu($season, 'All'); @@ -114,7 +124,7 @@ function queryEvents(Player $player, array $playerSeries, string $seriesName, st $sql .= ' AND e.season = :season'; $params['season'] = $season; } - $sql .= ' GROUP BY e.name ORDER BY e.finalized, e.start DESC LIMIT 100'; + $sql .= ' GROUP BY e.name ORDER BY e.start DESC LIMIT 100'; return db()->select($sql, HostedEventDto::class, $params); } diff --git a/gatherling/templates/eventList.mustache b/gatherling/templates/eventList.mustache index 08554c4bd..0c969628f 100644 --- a/gatherling/templates/eventList.mustache +++ b/gatherling/templates/eventList.mustache @@ -5,9 +5,9 @@ {{/hasPlayerSeries}} -{{#hostActiveEvents}} - {{> hostActiveEvents}} -{{/hostActiveEvents}} +{{#hostEvents}} + {{> hostEvents}} +{{/hostEvents}}

Filter Events

@@ -45,39 +45,43 @@
-

All Events

- +

Upcoming Events

+
- - - - - {{#events}} + {{#upcomingEvents}} - - - + - - - - {{/events}} - {{#hasMore}} - - + {{/upcomingEvents}} + + + +
EventFormatK-Value PlayersHost(s)Finalized
{{#isOngoing}}* {{/isOngoing}}{{name}}{{format}}{{kvalueDisplay}}{{name}} {{players}}{{host}}{{#cohost}}/{{cohost}}{{/cohost}}{{#finalized}}✔{{/finalized}}
 
 
+ +

Past Events

+ + + + + + {{#pastEvents}} - + + + - {{/hasMore}} + {{/pastEvents}} - +
EventPlayers
- This list only shows the 100 most recent results. - Please use the filters at the top of this page to find older - results. - {{name}}{{players}}
  
+ +{{#hasMore}} +

This list only shows the 100 most recent results. + Please use the filters at the top of this page to find older + results.

+{{/hasMore}} diff --git a/gatherling/templates/partials/eventCard.mustache b/gatherling/templates/partials/eventCard.mustache new file mode 100644 index 000000000..b2057ee12 --- /dev/null +++ b/gatherling/templates/partials/eventCard.mustache @@ -0,0 +1,38 @@ + diff --git a/gatherling/templates/partials/hostEvents.mustache b/gatherling/templates/partials/hostEvents.mustache index c488aaa44..f4d71cead 100644 --- a/gatherling/templates/partials/hostEvents.mustache +++ b/gatherling/templates/partials/hostEvents.mustache @@ -1,44 +1,17 @@ -

Current Events

-
- {{#events}} - - {{/events}} -
+{{#hasActiveEvents}} +

Active Events

+
+ {{#activeEvents}} + {{> eventCard}} + {{/activeEvents}} +
+{{/hasActiveEvents}} diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8fac892bd..6bd6f100e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -374,10 +374,6 @@ - - - -