Transport\Entity\Schedule\Connection::createFromXml PHP Method

createFromXml() public static method

public static createFromXml ( SimpleXMLElement $xml, Connection $obj = null )
$xml SimpleXMLElement
$obj Connection
    public static function createFromXml(\SimpleXMLElement $xml, Connection $obj = null)
    {
        if (!$obj) {
            $obj = new self();
        }
        $date = \DateTime::createFromFormat('Ymd', (string) $xml->Overview->Date, new \DateTimeZone('Europe/Zurich'));
        $date->setTimezone(new \DateTimeZone('Europe/Zurich'));
        $date->setTime(0, 0, 0);
        $obj->from = Entity\Schedule\Stop::createFromXml($xml->Overview->Departure->BasicStop, $date, null);
        $obj->to = Entity\Schedule\Stop::createFromXml($xml->Overview->Arrival->BasicStop, $date, null);
        $obj->duration = (string) $xml->Overview->Duration->Time;
        $obj->transfers = (int) $xml->Overview->Transfers;
        $obj->service = new Entity\Schedule\Service();
        if (isset($xml->Overview->ServiceDays->RegularServiceText)) {
            $obj->service->regular = (string) $xml->Overview->ServiceDays->RegularServiceText->Text;
        }
        if (isset($xml->Overview->ServiceDays->IrregularServiceText)) {
            $obj->service->irregular = (string) $xml->Overview->ServiceDays->IrregularServiceText->Text;
        }
        if (isset($xml->Overview->Products->Product)) {
            foreach ($xml->Overview->Products->Product as $product) {
                $obj->products[] = trim((string) $product['cat']);
            }
        }
        $capacities1st = [];
        $capacities2nd = [];
        foreach ($xml->ConSectionList->ConSection as $section) {
            if ($section->Journey) {
                if ($section->Journey->PassList->BasicStop) {
                    foreach ($section->Journey->PassList->BasicStop as $stop) {
                        if (isset($stop->StopPrognosis->Capacity1st)) {
                            $capacities1st[] = (int) $stop->StopPrognosis->Capacity1st;
                        }
                        if (isset($stop->StopPrognosis->Capacity2nd)) {
                            $capacities2nd[] = (int) $stop->StopPrognosis->Capacity2nd;
                        }
                    }
                }
            }
        }
        if (count($capacities1st) > 0) {
            $obj->capacity1st = max($capacities1st);
        }
        if (count($capacities2nd) > 0) {
            $obj->capacity2nd = max($capacities2nd);
        }
        foreach ($xml->ConSectionList->ConSection as $section) {
            $obj->sections[] = Entity\Schedule\Section::createFromXml($section, $date, null);
        }
        return $obj;
    }

Usage Example

コード例 #1
0
ファイル: API.php プロジェクト: opendatach/transport
 /**
  * @return array
  */
 public function findConnections(ConnectionQuery $query)
 {
     // send request
     $result = $this->sendAndParseQuery($query);
     // load pages
     for ($i = 0; $i < abs($query->page); $i++) {
         // load next page
         $pageQuery = new ConnectionPageQuery($query, (string) $result->ConRes->ConResCtxt);
         $result = $this->sendAndParseQuery($pageQuery);
     }
     $connections = [];
     if ($result->ConRes->ConnectionList->Connection) {
         foreach ($result->ConRes->ConnectionList->Connection as $connection) {
             $connections[] = Entity\Schedule\Connection::createFromXml($connection, null);
         }
     }
     return $connections;
 }
All Usage Examples Of Transport\Entity\Schedule\Connection::createFromXml
Connection