public static function getRoutes(Agency $agency, $version = 0) { /** * @var DB */ $dbObj = DBPool::getInstance(); $version = $version == 0 ? TableUpdate::getVersion() : $version; $dbObj->bindParams(array($agency->getId(), $version)); $routes = $dbObj->get_results("SELECT * FROM route WHERE agency_id=?\n AND version = ? ORDER BY position"); if ($dbObj->num_rows > 0) { $routeArray = array(); foreach ($routes as $r) { $routeObj = new Route(); $routeObj->setId($r->id); $routeObj->setAgency($agency); $routeObj->setTag($r->tag); $routeObj->setColor($r->color); $routeObj->setTitle($r->title); $routeObj->setShortTitle($r->short_title); $routeObj->setLatMin($r->lat_min); $routeObj->setLatMax($r->lat_max); $routeObj->setLonMin($r->lon_min); $routeObj->setLonMax($r->lon_max); $routeObj->setVehicleType($r->vehicle_type); $routeObj->setPosition($r->position); $routeArray[$r->tag] = $routeObj; } return $routeArray; } else { //TODO: Don't use a generic exception throw new Exception("No data available - Route::getRoutes"); } }
public function updateRoutes() { //Build an array of Route objects $routeArray = array(); $position = 0; $vehicleTypeOverrides = $this->getVehicleTypeOverride(); foreach ($this->xml->route as $r) { $route = new Route(); $routeTag = (string) $r['tag']; $vehicleType = isset($vehicleTypeOverrides[$routeTag]) ? $vehicleTypeOverrides[$routeTag] : "bus"; $position++; $route->setAgency($this->agency); $route->setTag($routeTag); $route->setTitle((string) $r['title']); $route->setShortTitle((string) $r['shortTitle']); $route->setPosition($position); $route->setVehicleType($vehicleType); $route->setColor((string) $r['color']); $route->setLatMin(isset($r['latMin']) ? (string) $r['latMin'] : ""); $route->setLatMax(isset($r['latMax']) ? (string) $r['latMax'] : ""); $route->setLonMin(isset($r['lonMin']) ? (string) $r['lonMin'] : ""); $route->setLonMax(isset($r['lonMax']) ? (string) $r['lonMax'] : ""); $routeArray[$routeTag] = $route; } try { //Pass it to the base RouteUpdate class $routeUpdate = new RouteUpdate($this->agency, $routeArray); $routeUpdate->updateDB(); } catch (Exception $ex) { throw new Exception($ex->getMessage()); } }
/** * For BART, the color value is the main identifier for a route */ public function updateRoutes() { //Build an array of Route objects $routeArray = array(); $position = 0; foreach ($this->xml->routes->route as $r) { $position++; $route = new Route(); $routeColor = substr((string) $r->color, 1); // We don't want the # $routeTag = BartColorCodes::getBartColor($routeColor); $route->setAgency($this->agency); $route->setTag($routeTag); $route->setTitle($routeTag); $route->setShortTitle($routeTag); $route->setColor($routeColor); $route->setVehicleType("train"); $route->setPosition($position); $routeArray[$routeTag] = $route; } try { //Pass it to the base RouteUpdate class $routeUpdate = new RouteUpdate($this->agency, $routeArray); $routeUpdate->updateDB(); } catch (Exception $ex) { throw new Exception($ex->getMessage()); } }