/**
  * @param   \SimpleXMLElement   $xml
  * @param   string              $date   The date that will be assigned to this journey
  * @param   Journey             $obj    An optional existing journey to overwrite
  * @return  Journey
  */
 public static function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Journey $obj = null)
 {
     if (!$obj) {
         $obj = new StationBoardJourney();
     }
     $obj = Journey::createFromXml($xml, $date, $obj);
     $obj->stop = Stop::createFromXml($xml->MainStop->BasicStop, $date, null);
     return $obj;
 }
 /**
  * @param \SimpleXMLElement   $xml
  * @param \DateTime           $date The date that will be assigned to this journey
  * @param StationBoardJourney $obj  An optional existing journey to overwrite
  *
  * @return StationBoardJourney
  */
 public static function createStationBoardFromXml(\SimpleXMLElement $xml, \DateTime $date, StationBoardJourney $obj = null)
 {
     if (!$obj) {
         $obj = new self();
     }
     $stop = Stop::createFromXml($xml->MainStop->BasicStop, $date, null);
     // use resolved date from main stop
     $date = new \DateTime($stop->departure);
     /* @var $obj StationBoardJourney */
     $obj = Journey::createFromXml($xml, $date, $obj);
     $obj->stop = $stop;
     return $obj;
 }
Beispiel #3
0
 public static function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Journey $obj = null)
 {
     if (!$obj) {
         $obj = new self();
     }
     // TODO: get attributes
     if ($xml->JourneyAttributeList) {
         foreach ($xml->JourneyAttributeList->JourneyAttribute as $journeyAttribute) {
             switch ($journeyAttribute->Attribute['type']) {
                 case 'NAME':
                     $obj->name = (string) $journeyAttribute->Attribute->AttributeVariant->Text;
                     break;
                 case 'CATEGORY':
                     $obj->category = (string) $journeyAttribute->Attribute->AttributeVariant->Text;
                     $obj->categoryCode = (int) $journeyAttribute->Attribute['code'];
                     break;
                 case 'INTERNALCATEGORY':
                     $obj->subcategory = (string) $journeyAttribute->Attribute->AttributeVariant->Text;
                     break;
                 case 'LINE':
                     $line = (string) $journeyAttribute->Attribute->AttributeVariant->Text;
                     if ($line && !$obj->number) {
                         $obj->number = $line;
                     }
                     break;
                 case 'NUMBER':
                     $number = (string) $journeyAttribute->Attribute->AttributeVariant->Text;
                     if ($number && !$obj->number) {
                         $obj->number = $number;
                     }
                     break;
                 case 'OPERATOR':
                     foreach ($journeyAttribute->Attribute->AttributeVariant as $journeyAttributeVariant) {
                         if ($journeyAttributeVariant['type'] == 'NORMAL') {
                             $obj->operator = (string) $journeyAttributeVariant->Text;
                         }
                     }
                     break;
                 case 'DIRECTION':
                     $obj->to = (string) $journeyAttribute->Attribute->AttributeVariant->Text;
                     break;
             }
         }
     }
     $capacities1st = [];
     $capacities2nd = [];
     if ($xml->PassList->BasicStop) {
         foreach ($xml->PassList->BasicStop as $basicStop) {
             if ($basicStop->Arr || $basicStop->Dep) {
                 $stop = Stop::createFromXml($basicStop, $date, null);
                 if ($stop->prognosis->capacity1st) {
                     $capacities1st[] = (int) $stop->prognosis->capacity1st;
                 }
                 if ($stop->prognosis->capacity2nd) {
                     $capacities2nd[] = (int) $stop->prognosis->capacity2nd;
                 }
                 $obj->passList[] = $stop;
             }
         }
     }
     if (count($capacities1st) > 0) {
         $obj->capacity1st = max($capacities1st);
     }
     if (count($capacities2nd) > 0) {
         $obj->capacity2nd = max($capacities2nd);
     }
     return $obj;
 }