private function getVehicleTypeOverride() { $agencyShortTitle = $this->agency->getShortTitle(); $config = $this->appConfig; $filePath = $config['sfmuni_vehicle_override']; //TODO: Check for exception $xmlObjBuilder = new XmlObjBuilder($filePath); $xml = $xmlObjBuilder->getXmlObj(); $vehicleOverrides = array(); //We only support SF-Muni for now if ($agencyShortTitle == "sf-muni") { foreach ($xml->route as $r) { $routeTag = (string) $r['tag']; $vehicleType = (string) $r['vehicle']; $vehicleOverrides[$routeTag] = $vehicleType; } } return $vehicleOverrides; }
public function updateStopDirMap() { /** * @var DB */ $dbObj = DBPool::getInstance(); $routeArray = Route::getRoutes($this->agency); $stopArray = Stop::getStops($this->agency); $bartApiKey = $this->appConfig['BART_API_KEY']; foreach ($routeArray as $routeTag => $routeObj) { $pos = 0; $directionArray = Direction::getDirections($routeObj); foreach ($directionArray as $dirTag => $dirObj) { //We're only interested in the directions we're showing if (!$dirObj->getShow()) { continue; } //Fetch the direction details $apiURL = str_replace(BartApiEndPoints::DIRECTION, $dirObj->getTag(), BartApiEndPoints::ROUTE_INFO . $bartApiKey); $dirInfoXmlBuilder = new XmlObjBuilder($apiURL); $dirInfoXml = $dirInfoXmlBuilder->getXmlObj(); foreach ($dirInfoXml->routes->route->config as $c) { foreach ($c as $station) { $pos++; $stopTag = (string) $station; $tempStopObj = $stopArray[$stopTag]; $stopId = $tempStopObj->getId(); $tempDirObj = $directionArray[$dirTag]; $dirId = $tempDirObj->getId(); $dbObj->bindParams(array($stopId, $dirId, $pos, TableUpdate::getVersion())); $dbObj->query("INSERT INTO stop_direction_map\n (stop_id, direction_id, position, version, created_date)\n VALUES (?, ?, ?, ?, NOW())"); if ($dbObj->rows_affected != 1) { //TODO: Log it } } //Stations } } //Directions } //Routes }
private function getDirectionOverrides() { $config = $this->appConfig; $filePath = $config['location_override']; //TODO: Check for exception $xmlObjBuilder = new XmlObjBuilder($filePath); $xml = $xmlObjBuilder->getXmlObj(); $routeArray = array(); foreach ($xml->agency as $a) { $shortTitle = $a['shortTitle']; //We only want the overrides for the current agency if ($this->agency->getShortTitle() == $shortTitle) { foreach ($a->route as $r) { $routeTag = (string) $r['tag']; foreach ($r->direction as $d) { $routeArray[$routeTag][] = (string) $d['tag']; } } } } return $routeArray; }
public function getStops() { $apiURL = BartApiEndPoints::STATIONS . $this->getBartApiKey(); $stationInfoXmlBuilder = new XmlObjBuilder($apiURL); return $stationInfoXmlBuilder->getXmlObj(true); }
public function updateStops() { $routeArray = Route::getRoutes($this->agency); $stopArray = array(); //Final list of Stop objects $bartApiKey = $this->appConfig['BART_API_KEY']; //Platform mapping $xmlStr = '<?xml version="1.0"?><agency title="BART" shortTitle="bart"></agency>'; $platformXml = new SimpleXMLElement($xmlStr); foreach ($this->xml->stations->station as $s) { $stationTag = (string) $s->abbr; //Fetch the station details $apiURL = str_replace(BartApiEndPoints::ORIG, $stationTag, BartApiEndPoints::STATION_INFO . $bartApiKey); $stationInfoXmlBuilder = new XmlObjBuilder($apiURL); $stationInfoXml = $stationInfoXmlBuilder->getXmlObj(); $stopObj = new Stop(); $stopObj->setAgency($this->agency); $stopObj->setTag($stationTag); $stopObj->setTitle((string) $stationInfoXml->stations->station->name); $stopObj->setLatitude((string) $stationInfoXml->stations->station->gtfs_latitude); $stopObj->setLongitude((string) $stationInfoXml->stations->station->gtfs_longitude); $stopArray[$stationTag] = $stopObj; /************* Add to platform XML object ****************/ //Add stop node $stopNode = $platformXml->addChild("stop"); $stopNode->addAttribute("tag", $stationTag); //Add platform node as a child of the stop node (north) $platformNode = $stopNode->addChild("platform"); $northPlatforms = array(); foreach ($stationInfoXml->stations->station->north_platforms as $p) { foreach ($p as $pNum) { $northPlatforms[] = trim((string) $pNum); } } $platformNode->addAttribute("number", implode(",", $northPlatforms)); //Add directions as a children of the platform node foreach ($stationInfoXml->stations->station->north_routes as $r) { foreach ($r->route as $direction) { $dirStr = trim((string) $direction); $dirTagArray = explode(" ", $dirStr); $dirTag = $dirTagArray[1]; $platformNode->addChild("direction", $dirTag); } } //Add platform node as a child of the stop node (south) $platformNode = $stopNode->addChild("platform"); $southPlatforms = array(); foreach ($stationInfoXml->stations->station->south_platforms as $p) { foreach ($p as $pNum) { $southPlatforms[] = trim((string) $pNum); } } $platformNode->addAttribute("number", implode(",", $southPlatforms)); //Add directions as a children of the platform node foreach ($stationInfoXml->stations->station->south_routes as $r) { foreach ($r as $direction) { $dirStr = trim((string) $direction); $dirTagArray = explode(" ", $dirStr); $dirTag = $dirTagArray[1]; $platformNode->addChild("direction", $dirTag); } } } //Write platform mapping XML to file $fileName = Util::getBaseDirectoryPath(Util::XML_FILE) . "bart-platforms.xml"; Util::prettyPrintXml($platformXml, $fileName); //Write the stops to the database try { //Pass it to the base RouteUpdate class $stopUpdate = new StopUpdate($this->agency, $stopArray); $stopUpdate->updateDB(); } catch (Exception $ex) { throw new Exception($ex->getMessage()); } }
/** * Read flip stop overrides from a file and return them as an array. * NOTE: This method returns the flip stops only for the agency being processed * * @return Array - stopTag => flipStopTag */ private function getFlipStopOverrides() { $agencyShortTitle = $this->agency->getShortTitle(); $config = $this->appConfig; $filePath = $config['flip_stop_override']; //TODO: Check for exception $xmlObjBuilder = new XmlObjBuilder($filePath); $xml = $xmlObjBuilder->getXmlObj(); $flipStopMap = array(); foreach ($xml->agency as $tempAgency) { if ((string) $tempAgency["shortTitle"] != $agencyShortTitle) { continue; } foreach ($tempAgency->stop as $tempStop) { $stopTag = (string) $tempStop["tag"]; $flipStopTag = (string) $tempStop["reverseStopTag"]; $flipStopMap[$stopTag] = $flipStopTag; if (!empty($flipStopTag)) { $flipStopMap[$flipStopTag] = $stopTag; } } } return $flipStopMap; }
private function getRoutes() { $apiURL = $this->getRouteListApiUrl() . $this->agency->getShortTitle(); $routeInfoXmlBuilder = new XmlObjBuilder($apiURL); return $routeInfoXmlBuilder->getXmlObj(true); }