1 | <?php |
||
12 | class Departures implements FactoryInterface { |
||
13 | /** |
||
14 | * @var ParserDepartures null |
||
15 | */ |
||
16 | protected $parserDepartures = null; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $departures = array(); |
||
22 | |||
23 | public function __construct(ParserDepartures $parserDepartures) { |
||
24 | $this->setParserDepartures($parserDepartures); |
||
25 | $this->departures = $parserDepartures->getDepartures(); |
||
26 | usort($this->departures, array("Mvg\Factories\Departures", "cmpObjects")); |
||
27 | |||
28 | } |
||
29 | |||
30 | protected static function cmpObjects($a, $b) { |
||
31 | |||
32 | if ($a->time === $b->time) { |
||
33 | return 0; |
||
34 | } |
||
35 | return ($a->time > $b->time) ? +1 : -1; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Filter By Destination |
||
40 | * @param mixed $filter |
||
41 | * @return array |
||
42 | */ |
||
43 | public function getItems($filter = '') { |
||
44 | if ('' === $filter) { |
||
45 | return $this->departures; |
||
46 | } |
||
47 | if (null === $filter) { |
||
48 | return $this->departures; |
||
49 | } |
||
50 | |||
51 | if( true === empty($filter)) { |
||
52 | return $this->departures; |
||
53 | } |
||
54 | |||
55 | if (false === is_array($filter)) { |
||
56 | $filter = [$filter]; |
||
57 | } |
||
58 | |||
59 | $departures = array(); |
||
60 | |||
61 | foreach ($this->departures as $departure) { |
||
62 | if (true === in_array($departure->destination, $filter)) { |
||
63 | $departures[] = $departure; |
||
64 | } |
||
65 | } |
||
66 | return $departures; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getCurrentTime() { |
||
75 | |||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getStation() { |
||
82 | |||
83 | /** |
||
84 | * @return array |
||
85 | */ |
||
86 | protected function getParserDepartures() { |
||
89 | |||
90 | /** |
||
91 | * @param ParserDepartures $parserDepartures |
||
92 | */ |
||
93 | protected function setParserDepartures(ParserDepartures $parserDepartures) { |
||
96 | |||
97 | |||
98 | } |