Schedule: Simplify & cleanup data classes
This commit is contained in:
parent
e3e0fb33a2
commit
b63eb44b39
|
@ -498,13 +498,13 @@ class ScheduleController extends BaseController
|
||||||
$locations = $this->getAllLocations();
|
$locations = $this->getAllLocations();
|
||||||
$eventTimeZone = Carbon::now()->timezone;
|
$eventTimeZone = Carbon::now()->timezone;
|
||||||
|
|
||||||
foreach ($schedule->getDay() as $day) {
|
foreach ($schedule->getDays() as $day) {
|
||||||
foreach ($day->getRoom() as $room) {
|
foreach ($day->getRooms() as $room) {
|
||||||
if (!$scheduleModel->activeLocations->where('name', $room->getName())->count()) {
|
if (!$scheduleModel->activeLocations->where('name', $room->getName())->count()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($room->getEvent() as $event) {
|
foreach ($room->getEvents() as $event) {
|
||||||
$scheduleEvents[$event->getGuid()] = $event;
|
$scheduleEvents[$event->getGuid()] = $event;
|
||||||
|
|
||||||
$event->getDate()->timezone($eventTimeZone)->subMinutes($minutesBefore);
|
$event->getDate()->timezone($eventTimeZone)->subMinutes($minutesBefore);
|
||||||
|
|
|
@ -8,9 +8,6 @@ class Conference
|
||||||
{
|
{
|
||||||
use CalculatesTime;
|
use CalculatesTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* Event constructor.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected string $title,
|
protected string $title,
|
||||||
protected string $acronym,
|
protected string $acronym,
|
||||||
|
|
|
@ -8,38 +8,16 @@ use Carbon\Carbon;
|
||||||
|
|
||||||
class Day
|
class Day
|
||||||
{
|
{
|
||||||
/** @var string required */
|
|
||||||
protected string $date;
|
|
||||||
|
|
||||||
/** @var Carbon required */
|
|
||||||
protected Carbon $start;
|
|
||||||
|
|
||||||
/** @var Carbon required */
|
|
||||||
protected Carbon $end;
|
|
||||||
|
|
||||||
/** @var int required */
|
|
||||||
protected int $index;
|
|
||||||
|
|
||||||
/** @var Room[] */
|
|
||||||
protected array $room;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Day constructor.
|
|
||||||
*
|
|
||||||
* @param Room[] $rooms
|
* @param Room[] $rooms
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $date,
|
protected string $date,
|
||||||
Carbon $start,
|
protected Carbon $start,
|
||||||
Carbon $end,
|
protected Carbon $end,
|
||||||
int $index,
|
protected int $index,
|
||||||
array $rooms = []
|
protected array $rooms = []
|
||||||
) {
|
) {
|
||||||
$this->date = $date;
|
|
||||||
$this->start = $start;
|
|
||||||
$this->end = $end;
|
|
||||||
$this->index = $index;
|
|
||||||
$this->room = $rooms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDate(): string
|
public function getDate(): string
|
||||||
|
@ -65,8 +43,8 @@ class Day
|
||||||
/**
|
/**
|
||||||
* @return Room[]
|
* @return Room[]
|
||||||
*/
|
*/
|
||||||
public function getRoom(): array
|
public function getRooms(): array
|
||||||
{
|
{
|
||||||
return $this->room;
|
return $this->rooms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,16 @@ class Event
|
||||||
protected Carbon $endDate;
|
protected Carbon $endDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $guid globally unique
|
* @param string $guid globally unique
|
||||||
* @param int $id globally unique
|
* @param int $id globally unique
|
||||||
* @param string $start time (hh:mm:ss || hh:mm)
|
* @param string $start time (hh:mm:ss || hh:mm)
|
||||||
* @param string $duration (h?h:mm:ss || h?h:mm)
|
* @param string $duration (h?h:mm:ss || h?h:mm)
|
||||||
* @param string $slug globally unique
|
* @param string $slug globally unique
|
||||||
* @param string[] $persons id => name
|
* @param string[] $persons id => name
|
||||||
* @param string|null $language two letter code
|
* @param string|null $language two-letter code
|
||||||
* @param string|null $recording license (and opt out in XML, null if not recorded, empty if no license defined)/
|
* @param string|null $recording license (and opt out in XML, null if not recorded, empty if no license defined)/
|
||||||
* @param array $links href => title
|
* @param array $links href => title
|
||||||
* @param array $attachments href => title
|
* @param array $attachments href => title
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected string $guid,
|
protected string $guid,
|
||||||
|
|
|
@ -6,23 +6,13 @@ namespace Engelsystem\Helpers\Schedule;
|
||||||
|
|
||||||
class Room
|
class Room
|
||||||
{
|
{
|
||||||
/** @var string required */
|
|
||||||
protected string $name;
|
|
||||||
|
|
||||||
/** @var Event[] */
|
|
||||||
protected array $event;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Room constructor.
|
|
||||||
*
|
|
||||||
* @param Event[] $events
|
* @param Event[] $events
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $name,
|
protected string $name,
|
||||||
array $events = []
|
protected array $events = []
|
||||||
) {
|
) {
|
||||||
$this->name = $name;
|
|
||||||
$this->event = $events;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
|
@ -33,16 +23,16 @@ class Room
|
||||||
/**
|
/**
|
||||||
* @return Event[]
|
* @return Event[]
|
||||||
*/
|
*/
|
||||||
public function getEvent(): array
|
public function getEvents(): array
|
||||||
{
|
{
|
||||||
return $this->event;
|
return $this->events;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Event[] $event
|
* @param Event[] $events
|
||||||
*/
|
*/
|
||||||
public function setEvent(array $event): void
|
public function setEvents(array $events): void
|
||||||
{
|
{
|
||||||
$this->event = $event;
|
$this->events = $events;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,18 +8,14 @@ use Carbon\Carbon;
|
||||||
|
|
||||||
class Schedule
|
class Schedule
|
||||||
{
|
{
|
||||||
/** @var Day[] */
|
|
||||||
protected array $day;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Day[] $days
|
* @param Day[] $days
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected string $version,
|
protected string $version,
|
||||||
protected Conference $conference,
|
protected Conference $conference,
|
||||||
array $days
|
protected array $days
|
||||||
) {
|
) {
|
||||||
$this->day = $days;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVersion(): string
|
public function getVersion(): string
|
||||||
|
@ -35,9 +31,9 @@ class Schedule
|
||||||
/**
|
/**
|
||||||
* @return Day[]
|
* @return Day[]
|
||||||
*/
|
*/
|
||||||
public function getDay(): array
|
public function getDays(): array
|
||||||
{
|
{
|
||||||
return $this->day;
|
return $this->days;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,8 +42,8 @@ class Schedule
|
||||||
public function getRooms(): array
|
public function getRooms(): array
|
||||||
{
|
{
|
||||||
$rooms = [];
|
$rooms = [];
|
||||||
foreach ($this->day as $day) {
|
foreach ($this->days as $day) {
|
||||||
foreach ($day->getRoom() as $room) {
|
foreach ($day->getRooms() as $room) {
|
||||||
$name = $room->getName();
|
$name = $room->getName();
|
||||||
$rooms[$name] = $room;
|
$rooms[$name] = $room;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +56,7 @@ class Schedule
|
||||||
public function getStartDateTime(): ?Carbon
|
public function getStartDateTime(): ?Carbon
|
||||||
{
|
{
|
||||||
$start = null;
|
$start = null;
|
||||||
foreach ($this->day as $day) {
|
foreach ($this->days as $day) {
|
||||||
$time = $day->getStart();
|
$time = $day->getStart();
|
||||||
if ($time > $start && $start) {
|
if ($time > $start && $start) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -75,7 +71,7 @@ class Schedule
|
||||||
public function getEndDateTime(): ?Carbon
|
public function getEndDateTime(): ?Carbon
|
||||||
{
|
{
|
||||||
$end = null;
|
$end = null;
|
||||||
foreach ($this->day as $day) {
|
foreach ($this->days as $day) {
|
||||||
$time = $day->getEnd();
|
$time = $day->getEnd();
|
||||||
if ($time < $end && $end) {
|
if ($time < $end && $end) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -28,7 +28,9 @@ class XmlParser
|
||||||
/**
|
/**
|
||||||
* Parse the predefined XML content
|
* Parse the predefined XML content
|
||||||
*
|
*
|
||||||
* According to https://github.com/voc/voctosched/blob/master/schema/basic.xsd
|
* See also https://c3voc.de/wiki/schedule
|
||||||
|
*
|
||||||
|
* According to https://github.com/voc/schedule/blob/master/validator/xsd/schedule.xml.xsd
|
||||||
*/
|
*/
|
||||||
protected function parseXml(): void
|
protected function parseXml(): void
|
||||||
{
|
{
|
||||||
|
@ -53,7 +55,7 @@ class XmlParser
|
||||||
);
|
);
|
||||||
|
|
||||||
$events = $this->parseEvents($roomElement->xpath('event'), $room);
|
$events = $this->parseEvents($roomElement->xpath('event'), $room);
|
||||||
$room->setEvent($events);
|
$room->setEvents($events);
|
||||||
$rooms[] = $room;
|
$rooms[] = $room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class DayTest extends TestCase
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Day::getStart
|
* @covers \Engelsystem\Helpers\Schedule\Day::getStart
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Day::getEnd
|
* @covers \Engelsystem\Helpers\Schedule\Day::getEnd
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Day::getIndex
|
* @covers \Engelsystem\Helpers\Schedule\Day::getIndex
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Day::getRoom
|
* @covers \Engelsystem\Helpers\Schedule\Day::getRooms
|
||||||
*/
|
*/
|
||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ class DayTest extends TestCase
|
||||||
$this->assertEquals('2000-01-01T03:00:00+01:00', $day->getStart()->format(Carbon::RFC3339));
|
$this->assertEquals('2000-01-01T03:00:00+01:00', $day->getStart()->format(Carbon::RFC3339));
|
||||||
$this->assertEquals('2000-01-02T05:59:00+00:00', $day->getEnd()->format(Carbon::RFC3339));
|
$this->assertEquals('2000-01-02T05:59:00+00:00', $day->getEnd()->format(Carbon::RFC3339));
|
||||||
$this->assertEquals(1, $day->getIndex());
|
$this->assertEquals(1, $day->getIndex());
|
||||||
$this->assertEquals([], $day->getRoom());
|
$this->assertEquals([], $day->getRooms());
|
||||||
|
|
||||||
$rooms = [
|
$rooms = [
|
||||||
new Room('Foo'),
|
new Room('Foo'),
|
||||||
|
@ -44,6 +44,6 @@ class DayTest extends TestCase
|
||||||
1,
|
1,
|
||||||
$rooms
|
$rooms
|
||||||
);
|
);
|
||||||
$this->assertEquals($rooms, $day->getRoom());
|
$this->assertEquals($rooms, $day->getRooms());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace Engelsystem\Test\Unit\Helpers\Schedule;
|
||||||
|
|
||||||
use Engelsystem\Helpers\Schedule\Event;
|
use Engelsystem\Helpers\Schedule\Event;
|
||||||
use Engelsystem\Helpers\Schedule\Room;
|
use Engelsystem\Helpers\Schedule\Room;
|
||||||
|
use Engelsystem\Helpers\Uuid;
|
||||||
use Engelsystem\Test\Unit\TestCase;
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
|
|
||||||
class RoomTest extends TestCase
|
class RoomTest extends TestCase
|
||||||
|
@ -13,21 +14,21 @@ class RoomTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Room::__construct
|
* @covers \Engelsystem\Helpers\Schedule\Room::__construct
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Room::getName
|
* @covers \Engelsystem\Helpers\Schedule\Room::getName
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Room::getEvent
|
* @covers \Engelsystem\Helpers\Schedule\Room::getEvents
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Room::setEvent
|
* @covers \Engelsystem\Helpers\Schedule\Room::setEvents
|
||||||
*/
|
*/
|
||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
$room = new Room('Test');
|
$room = new Room('Test');
|
||||||
$this->assertEquals('Test', $room->getName());
|
$this->assertEquals('Test', $room->getName());
|
||||||
$this->assertEquals([], $room->getEvent());
|
$this->assertEquals([], $room->getEvents());
|
||||||
|
|
||||||
$events = [$this->createMock(Event::class), $this->createMock(Event::class)];
|
$events = [$this->createMock(Event::class), $this->createMock(Event::class)];
|
||||||
$events2 = [$this->createMock(Event::class)];
|
$events2 = [$this->createMock(Event::class)];
|
||||||
$room = new Room('Test2', $events);
|
$room = new Room('Test2', $events);
|
||||||
$this->assertEquals($events, $room->getEvent());
|
$this->assertEquals($events, $room->getEvents());
|
||||||
|
|
||||||
$room->setEvent($events2);
|
$room->setEvents($events2);
|
||||||
$this->assertEquals($events2, $room->getEvent());
|
$this->assertEquals($events2, $room->getEvents());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class ScheduleTest extends TestCase
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Schedule::__construct
|
* @covers \Engelsystem\Helpers\Schedule\Schedule::__construct
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Schedule::getVersion
|
* @covers \Engelsystem\Helpers\Schedule\Schedule::getVersion
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Schedule::getConference
|
* @covers \Engelsystem\Helpers\Schedule\Schedule::getConference
|
||||||
* @covers \Engelsystem\Helpers\Schedule\Schedule::getDay
|
* @covers \Engelsystem\Helpers\Schedule\Schedule::getDays
|
||||||
*/
|
*/
|
||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ class ScheduleTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals('Foo\'ing stuff 1.0', $schedule->getVersion());
|
$this->assertEquals('Foo\'ing stuff 1.0', $schedule->getVersion());
|
||||||
$this->assertEquals($conference, $schedule->getConference());
|
$this->assertEquals($conference, $schedule->getConference());
|
||||||
$this->assertEquals($days, $schedule->getDay());
|
$this->assertEquals($days, $schedule->getDays());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,14 +46,14 @@ class XmlParserTest extends TestCase
|
||||||
$this->assertEquals('Rooming', $room->getName());
|
$this->assertEquals('Rooming', $room->getName());
|
||||||
|
|
||||||
/** @var Day $day */
|
/** @var Day $day */
|
||||||
$day = Arr::first($schedule->getDay());
|
$day = Arr::first($schedule->getDays());
|
||||||
$this->assertEquals('2042-01-01', $day->getDate());
|
$this->assertEquals('2042-01-01', $day->getDate());
|
||||||
$this->assertEquals(1, $day->getIndex());
|
$this->assertEquals(1, $day->getIndex());
|
||||||
|
|
||||||
/** @var Room $room */
|
/** @var Room $room */
|
||||||
$room = Arr::first($day->getRoom());
|
$room = Arr::first($day->getRooms());
|
||||||
/** @var Event $event */
|
/** @var Event $event */
|
||||||
$event = Arr::first($room->getEvent());
|
$event = Arr::first($room->getEvents());
|
||||||
|
|
||||||
$this->assertEquals('Foo Bar Test', $event->getTitle());
|
$this->assertEquals('Foo Bar Test', $event->getTitle());
|
||||||
$this->assertEquals('WTFPL', $event->getRecording());
|
$this->assertEquals('WTFPL', $event->getRecording());
|
||||||
|
|
Loading…
Reference in New Issue