protected function getAllExisting() { try { return Stop::getStops($this->agency, TableUpdate::getLiveVersion()); } catch (Exception $ex) { return false; } }
function generateXMLFile(Agency $agencyObj) { $dbObj = DBPool::getInstance(); $routeArray = Route::getRoutes($agencyObj); $stopArray = Stop::getStops($agencyObj); $xmlStr = '<?xml version="1.0" encoding="UTF-8" ?><agency title="' . $agencyObj->getTitle() . '" shortTitle="' . $agencyObj->getShortTitle() . '"></agency>'; $xml = new SimpleXMLElement($xmlStr); foreach ($stopArray as $s) { $stop = $xml->addChild("stop"); $stop->addAttribute("tag", $s->getTag()); $stop->addAttribute("title", $s->getPrettyTitle()); $stop->addAttribute("lat", $s->getLatitude()); $stop->addAttribute("lon", $s->getLongitude()); $stop->addAttribute("oppositeStopTag", $s->getFlipStopTag()); } foreach ($routeArray as $r) { $route = $xml->addChild("route"); $route->addAttribute("tag", $r->getTag()); $route->addAttribute("title", $r->getTitle()); $route->addAttribute("shortTitle", $r->getShortTitle()); $route->addAttribute("color", $r->getColor()); $route->addAttribute("latMin", $r->getLatMin()); $route->addAttribute("latMax", $r->getLatMax()); $route->addAttribute("lonMin", $r->getLonMin()); $route->addAttribute("lonMax", $r->getLonMax()); $route->addAttribute("vehicle", $r->getVehicleType()); $route->addAttribute("sortOrder", $r->getPosition()); $directionsArray = Direction::getDirections($r); foreach ($directionsArray as $d) { $dir = $route->addChild("direction"); $dir->addAttribute("tag", $d->getTag()); $dir->addAttribute("title", $d->getPrettyTitle()); $dir->addAttribute("name", $d->getPrettyName()); $dir->addAttribute("show", $d->getShow() ? "true" : "false"); $dir->addAttribute("useForUI", $d->getUseForUi() ? "true" : "false"); $dbObj->bindParams(array($d->getId())); $stopDirMap = $dbObj->get_results("SELECT a.tag, b.position\n FROM stop as a, stop_direction_map as b\n WHERE a.id=b.stop_id AND b.direction_id=?\n ORDER BY b.position"); if ($dbObj->num_rows > 0) { foreach ($stopDirMap as $m) { $map = $dir->addChild("stop"); $map->addAttribute("tag", $m->tag); } } } } $fileName = Util::getBaseDirectoryPath(Util::XML_FILE) . $agencyObj->getShortTitle() . ".xml"; Util::prettyPrintXml($xml, $fileName); }
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 }
public function updateStopDirMap() { /** * @var DB */ $dbObj = DBPool::getInstance(); $routeArray = Route::getRoutes($this->agency); $stopArray = Stop::getStops($this->agency); foreach ($this->xml->route as $r) { $routeTag = (string) $r['tag']; $routeObj = $routeArray[$routeTag]; foreach ($r->direction as $d) { $pos = 0; $dirTag = (string) $d['tag']; $directionArray = Direction::getDirections($routeObj); $dirObj = $directionArray[$dirTag]; //We're only interested in the directions we're showing //if (!$dirObj->getShow()) { continue; } foreach ($d->stop as $s) { $pos++; $stopTag = (string) $s['tag']; $tempStop = $stopArray[$stopTag]; if (empty($tempStop)) { var_dump("{$routeTag} {$stopTag}"); } $stopId = $tempStop->getId(); $tempDir = $directionArray[$dirTag]; $dirId = $tempDir->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 } } } } }