/** * 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()); } }
public function updateDirections() { //Fetch all the routes that are already in the database try { $routeArray = Route::getRoutes($this->agency); } catch (Exception $ex) { throw new Exception("BART directions could not be updated"); } foreach ($routeArray as $routeTag => $routeObj) { //Build an array of direction objects $directionInfo = array(); //Add the directions for every route foreach ($this->xml->routes->route as $d) { $tempRouteTag = BartColorCodes::getBartColor(substr((string) $d->color, 1)); if ($tempRouteTag == $routeTag) { $dirObj = new Direction(); $dirTag = (string) $d->number; $useForUiValue = true; //Always true for BART $dirObj->setRoute($routeObj); $dirObj->setTag($dirTag); $dirObj->setTitle($this->formatTitle((string) $d->name)); $dirObj->setName((string) $d->abbr); $dirObj->setUseForUi($useForUiValue); $dirObj->setShow($useForUiValue); $directionInfo[$dirTag] = $dirObj; } } //var_dump($directionInfo);exit; //Update the database try { //Pass it to the base DirectionUpdate class $dirUpdate = new DirectionUpdate($routeObj, $directionInfo); $dirUpdate->updateDB(); } catch (Exception $ex) { throw new Exception($ex->getMessage()); } } }