Beispiel #1
0
 /**
  * calculates trail distance using phpgeo composer package.
  **/
 public static function calculateTrailDistance()
 {
     $pdo = connectToEncryptedMySQL("/var/www/trailquail/encrypted-mysql/trailquail.ini");
     $trails = Trail::getAllTrails($pdo);
     $testNum = 0;
     foreach ($trails as $trail) {
         $testNum++;
         $trailRelationships = TrailRelationship::getTrailRelationshipByTrailId($pdo, $trail->getTrailId());
         $track = new Polyline();
         foreach ($trailRelationships as $trailRelationship) {
             $segment = Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId());
             $track->addPoint(new Coordinate($segment->getSegmentStart()->getY(), $segment->getSegmentStart()->getX()));
             $track->addPoint(new Coordinate($segment->getSegmentStop()->getY(), $segment->getSegmentStop()->getX()));
         }
         $trailDistanceM = $track->getLength(new Vincenty());
         $trailDistanceMi = $trailDistanceM / 1609.344;
         $trailDistance = $trailDistanceMi;
         $trail->setTrailDistance($trailDistance);
         $trail->update($pdo);
     }
 }
 /**
  * test grabbing a Trail Relationship by trailId
  **/
 public function testGetValidTrailRelationshipByTrailId()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("trailRelationship");
     //create a new Trail Relationship and insert it into mySQL
     $trailRelationship = new TrailRelationship($this->segment->getSegmentId(), $this->trail->getTrailId(), $this->VALID_SEGMENTTYPE);
     $trailRelationship->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoTrailRelationship = TrailRelationship::getTrailRelationshipByTrailId($this->getPDO(), $this->trail->getTrailId());
     $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("trailRelationship"));
     $this->assertSame($pdoTrailRelationship->getSegmentId(), $this->segment->getSegmentId());
     $this->assertSame($pdoTrailRelationship->getTrailId(), $this->trail->getTrailId());
     $this->assertSame($pdoTrailRelationship->getSegmentType(), $this->VALID_SEGMENTTYPE);
 }
Beispiel #3
0
 $difficulty = filter_input(INPUT_GET, "difficulty", FILTER_VALIDATE_INT);
 $distance = filter_input(INPUT_GET, "distance", FILTER_VALIDATE_INT);
 $name = filter_input(INPUT_GET, "name", FILTER_SANITIZE_STRING);
 $submission = filter_input(INPUT_GET, "submission", FILTER_VALIDATE_INT);
 $terrain = filter_input(INPUT_GET, "terrain", FILTER_SANITIZE_STRING);
 $traffic = filter_input(INPUT_GET, "traffic", FILTER_SANITIZE_STRING);
 $use = filter_input(INPUT_GET, "use", FILTER_SANITIZE_STRING);
 $uuid = filter_input(INPUT_GET, "uuid", FILTER_SANITIZE_STRING);
 // handle all restful calls
 // get some of all trails
 if ($method === "GET") {
     setXsrfCookie("/");
     if (empty($id) === false) {
         $reply->data = Trail::getTrailById($pdo, $id);
         // Grab segments
         $trailRelationships = TrailRelationship::getTrailRelationshipByTrailId($pdo, $id);
         $points = [];
         foreach ($trailRelationships as $trailRelationship) {
             $points[] = [Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStart()->getY(), Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStart()->getX()];
             $points[] = [Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStop()->getY(), Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStop()->getX()];
         }
         // Add segments to reply
         $reply->points = $points;
     } elseif (empty($userId) === false) {
         $reply->data = Trail::getTrailByUserId($pdo, $userId)->toArray();
     } elseif (empty($submitId) === false) {
         $reply->data = Trail::getTrailBySubmitTrailId($pdo, $submitId)->toArray();
     } elseif (empty($amenities) === false) {
         $reply->data = Trail::getTrailByTrailAmenities($pdo, $amenities)->toArray();
     } elseif (empty($condition) === false) {
         $reply->data = Trail::getTrailByTrailCondition($pdo, $condition)->toArray();