public static function getDirections(Route $route, $version = 0)
 {
     /**
      * @var DB
      */
     $dbObj = DBPool::getInstance();
     $version = $version == 0 ? TableUpdate::getVersion() : $version;
     $dbObj->bindParams(array($route->getId(), $version));
     $directions = $dbObj->get_results("SELECT * FROM direction WHERE route_id=?\n            AND version = ?");
     if ($dbObj->num_rows > 0) {
         $directionArray = array();
         foreach ($directions as $d) {
             $dirObj = new Direction();
             $dirObj->setId($d->id);
             $dirObj->setName($d->name);
             $dirObj->setPrettyName($d->pretty_name);
             $dirObj->setRoute($route);
             $dirObj->setTag($d->tag);
             $dirObj->setTitle($d->title);
             $dirObj->setPrettyTitle($d->pretty_title);
             $dirObj->setUseForUi($d->use_for_ui);
             $dirObj->setShow($d->show);
             $directionArray[$d->tag] = $dirObj;
         }
         return $directionArray;
     } else {
         //TODO: Don't use a generic exception
         throw new Exception("No data available - Direction::getDirections");
     }
 }
 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());
         }
     }
 }
 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("Nextbus directions could not be updated. Error building route array.");
     }
     //Add the directions for every route
     foreach ($this->xml->route as $r) {
         $routeTag = (string) $r['tag'];
         $routeObj = $routeArray[$routeTag];
         //Build an array of direction objects
         $directionInfo = array();
         foreach ($r->direction as $d) {
             $dirObj = new Direction();
             $dirTag = (string) $d['tag'];
             $useForUiValue = (string) $d['useForUI'] == "false" ? false : true;
             $dirObj->setRoute($routeObj);
             $dirObj->setTag($dirTag);
             $dirObj->setTitle((string) $d['title']);
             $dirObj->setName((string) $d['name']);
             $dirObj->setUseForUi($useForUiValue);
             $dirObj->setShow($this->getShowValue($routeTag, $dirTag, $useForUiValue));
             $directionInfo[$dirTag] = $dirObj;
         }
         //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());
         }
     }
 }