dayOfWeek]) { $from = Carbon::createFromFormat(static::$dateFormat, $scheduleType["dateFrom"]); $to = Carbon::createFromFormat(static::$dateFormat, $scheduleType["dateTo"]); if ($date->between($from, $to)) { return $scheduleType; } } } foreach ($config["scheduleTypes"] as $scheduleType) { if ($scheduleType["type"] == static::$days[$date->dayOfWeek]) { return $scheduleType; } } foreach ($config["scheduleTypes"] as $scheduleType) { if ($scheduleType["type"] == "week") { $from = Carbon::createFromFormat(static::$dateFormat, $scheduleType["dateFrom"]); $to = Carbon::createFromFormat(static::$dateFormat, $scheduleType["dateTo"]); if ($date->between($from, $to)) { return $scheduleType; } } } foreach ($config["scheduleTypes"] as $scheduleType) { if ($scheduleType["type"] == "week") { return $scheduleType; } } return $config["scheduleTypes"][0]; } public static function getSchedulesForDate(array $schedules, Carbon $date) { foreach ($schedules as $schedule) { if (in_array($date->dayOfWeek, $schedule["week_days"])) { return $schedule["schedule"]; } } return null; } public static function getSingle(array $scheduleType, StopsLiteRoutesLiteDbo $stop, Carbon $date, int $count) { $dbo = new StopsSchedulesDbo(); $dbo->setRouteId($stop->getRouteId()); $dbo->setStopId($stop->getStopId()); try { $data = static::getDataAccess()->get($scheduleType["resourceId"], "allweek", $stop->getStopId(), $stop->getRouteId()); } catch (ClientException $e) { if ($e->getCode() == 404) { $dbo->setSchedules([]); return $dbo; } else { throw $e; } } $schedules = static::getSchedulesForDate($data["data"]["schedules"], $date); $schedulesCarbon = []; for ($i = 0; $i < count($schedules) && $count > 0; ++$i) { $scheduleDate = Carbon::createFromFormat(static::$timeFormat . " " . static::$dateFormat, $schedules[$i] . " " . $date->toDateString()); if ($scheduleDate->gte($date)) { --$count; $schedulesCarbon[] = $scheduleDate; } } $dbo->setSchedules($schedulesCarbon); return $dbo; } public static function getMultiple(StopsLiteRoutesLiteDboArray $stops, Carbon $date, int $count) { $config = MiscBusiness::getConfig(); $scheduleType = static::getScheduleTypeForDate($config, $date); $dbos = []; foreach ($stops->getArray() as $stop) { $dbo = static::getSingle($scheduleType, $stop, $date, $count); if (count($dbo->getSchedules()) < $count) { $count2 = $count - count($dbo->getSchedules()); $date2 = $date->copy(); $date2->addDay(1); $date2->setTime(0, 0, 0); $scheduleType2 = static::getScheduleTypeForDate($config, $date2); $dbo2 = static::getSingle($scheduleType2, $stop, $date2, $count2); $dbo->setSchedules(array_merge($dbo->getSchedules(), $dbo2->getSchedules())); } $dbos[] = $dbo; } return new LuPaginatedDbo(count($dbos), $dbos); } }