fix: add upcoming filter, refactor from short_name to slug

This commit is contained in:
Andreas Hubel 2022-04-22 00:09:57 +02:00
parent 9deac37a33
commit e9d6de7587
4 changed files with 15 additions and 15 deletions

View file

@ -1,9 +1,6 @@
<?php
$upcoming_events = Upcoming::getNextEvents();
$upcoming_crs = array_values(array_filter($upcoming_events, function($event) {
return preg_match('/^events:cr[0-9]+$/i', $event['short_name']);
}));
$upcoming_crs = Upcoming::getNextEvents('/^cr[0-9]+$/i');
if(count($upcoming_crs) < 1)
{
@ -15,7 +12,7 @@ if(count($upcoming_crs) < 1)
else
{
$upcoming_cr = $upcoming_crs[0];
preg_match('/^events:cr([0-9]+)$/i', $upcoming_cr['short_name'], $m);
preg_match('/^cr([0-9]+)$/i', $upcoming_cr['slug'], $m);
$EPISODE = intval($m[1]);
$DATE = strtotime($upcoming_cr['start_date'].' 21:00');

View file

@ -1,9 +1,7 @@
<?php
$upcoming_events = Upcoming::getNextEvents();
$upcoming_dgs = array_values(array_filter($upcoming_events, function($event) {
return preg_match('/^events:dg[0-9]+$/i', $event['short_name']);
}));
$upcoming_dgs = Upcoming::getNextEvents('/^dg[0-9]+$/i');
if(count($upcoming_dgs) < 1)
{
$EPISODE = '???';
@ -13,7 +11,7 @@ if(count($upcoming_dgs) < 1)
else
{
$upcoming_dg = $upcoming_dgs[0];
preg_match('/^events:dg([0-9]+)$/i', $upcoming_dg['short_name'], $m);
preg_match('/^dg([0-9]+)$/i', $upcoming_dg['slug'], $m);
$EPISODE = intval($m[1]);
$DATE = strtotime($upcoming_dg['start_date'].' 20:00');

View file

@ -1,9 +1,7 @@
<?php
$upcoming_events = Upcoming::getNextEvents();
$upcoming_ocs = array_values(array_filter($upcoming_events, function($event) {
return preg_match('/^events:oc[0-9]+[a-z]+$/i', $event['short_name']);
}));
$upcoming_ocs = Upcoming::getNextEvents('/^oc[0-9]+[a-z]+$/i');
if(count($upcoming_ocs) < 1)
{
$EPISODE = '???';

View file

@ -4,7 +4,7 @@ class Upcoming
{
private static $events;
public static function getNextEvents()
public static function getNextEvents($filter = null)
{
try {
if (!isset(self::$events)) {
@ -13,6 +13,13 @@ class Upcoming
self::$events = array_values($events['voc_events']);
}
if (!is_null($filter) && $filter) {
return array_values(array_filter(self::$events, function($event) use($filter) {
return preg_match($filter, $event['slug']);
}));
}
return self::$events;
}
catch(ErrorException $e)