예제 #1
0
 public function testGetTransferTrainsInTripWithMultipleTransfers()
 {
     $departureTrain = $this->createSimpleTrain();
     $transfer1 = $this->createTransferTrain($departureTrain);
     $transfer2 = $this->createTransferTrain($transfer1);
     $transfers = array($transfer1, $transfer2);
     $trip = new Trip($departureTrain, $transfers);
     $this->assertEquals(2, $trip->getTransferTrains()->count());
 }
예제 #2
0
function prepareResults(Trip $trip)
{
    $result = array("line" => $trip->getDepartureTrain()->getLine(), "departure" => $trip->getDepartureTrain()->getDepartureTime()->format("H:i"), "arrival" => $trip->getDepartureTrain()->getArrivalTime()->format("H:i"), "transfer_departure" => "", "transfer_arrival" => "", "transfer_line" => "");
    $transfers = array();
    if ($trip->hasTransfer()) {
        $i = 0;
        foreach ($trip->getTransferTrains() as $transfer) {
            /* @var Train $transfer */
            if ($i == 0) {
                $result["transfer_departure"] = $transfer->getDepartureTime()->format("H:i");
                $result["transfer_arrival"] = $transfer->getArrivalTime()->format("H:i");
                $result["transfer_line"] = $transfer->getLine();
                $i += 1;
            } else {
                $transfers[] = array("line" => "", "departure" => "", "arrival" => "", "transfer_departure" => $transfer->getDepartureTime()->format("H:i"), "transfer_arrival" => $transfer->getArrivalTime()->format("H:i"), "transfer_line" => $transfer->getLine());
            }
        }
    }
    $results = array($result);
    if ($transfers) {
        $results = array_merge($results, $transfers);
    }
    return $results;
}