summaryrefslogtreecommitdiff
path: root/src/Helpers/Schedule/Schedule.php
blob: 7150480c700515d2d91680db52c002f202c12d04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php

declare(strict_types=1);

namespace Engelsystem\Helpers\Schedule;

use Carbon\Carbon;

class Schedule
{
    /** @var string */
    protected $version;

    /** @var Conference */
    protected $conference;

    /** @var Day[] */
    protected $day;

    /**
     * @param string     $version
     * @param Conference $conference
     * @param Day[]      $days
     */
    public function __construct(
        string $version,
        Conference $conference,
        array $days
    ) {
        $this->version = $version;
        $this->conference = $conference;
        $this->day = $days;
    }

    /**
     * @return string
     */
    public function getVersion(): string
    {
        return $this->version;
    }

    /**
     * @return Conference
     */
    public function getConference(): Conference
    {
        return $this->conference;
    }

    /**
     * @return Day[]
     */
    public function getDay(): array
    {
        return $this->day;
    }

    /**
     * @return Room[]
     */
    public function getRooms(): array
    {
        $rooms = [];
        foreach ($this->day as $day) {
            foreach ($day->getRoom() as $room) {
                $name = $room->getName();
                $rooms[$name] = $room;
            }
        }

        return $rooms;
    }


    /**
     * @return Carbon|null
     */
    public function getStartDateTime(): ?Carbon
    {
        $start = null;
        foreach ($this->day as $day) {
            $time = $day->getStart();
            if ($time > $start && $start) {
                continue;
            }

            $start = $time;
        }

        return $start;
    }

    /**
     * @return Carbon|null
     */
    public function getEndDateTime(): ?Carbon
    {
        $end = null;
        foreach ($this->day as $day) {
            $time = $day->getEnd();
            if ($time < $end && $end) {
                continue;
            }

            $end = $time;
        }

        return $end;
    }
}