Exemple #1
0
                // verify the segment in question exists
                if ($segment === null) {
                    throw new RuntimeException("segment must exist", 404);
                }
                $segment = new Segment($id, $segmentStart, $segmentStop, $requestObject->segmentStartElevation, $requestObject->segmentStopElevation);
                $segment->update($pdo);
                $reply->message = "segment update was successful";
            }
            if ($method === "POST") {
                // form a mini-constructor to assemble a segmentStart and a segmentStop....?????
                $segment = new Segment(null, $segmentStart, $segmentStop, $requestObject->segmentStartElevation, $requestObject->segmentStopElevation);
                $segment->insert($pdo);
                $reply->message = "segment insert was successful";
            }
        } elseif ($method === "DELETE") {
            $segment = Segment::getSegmentBySegmentId($pdo, $id);
            if ($segment === null) {
                throw new RuntimeException("segment must exist", 404);
            }
            $segment->delete($pdo);
            $deletedObject = new stdClass();
            $deletedObject->segmentId = $id;
            $reply->message = "segment was successfully Deleted";
        } else {
            if (empty($method) === false && $method !== "GET") {
                throw new RuntimeException("only active users are allowed to modify entries", 401);
            }
        }
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
Exemple #2
0
 $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();
     } elseif (empty($description) === false) {
         $reply->data = Trail::getTrailByTrailDescription($pdo, $description)->toArray();
     } elseif (empty($difficulty) === false) {
         $reply->data = Trail::getTrailByTrailDifficulty($pdo, $difficulty)->toArray();
 /**
  * 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);
     }
 }
Exemple #4
0
 /**
  * test creating a segment, and then deleting it
  **/
 public function testDeleteValidSegment()
 {
     //count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("segment");
     //create a new segment and insert it into the database
     $segment = new Segment(null, $this->VALID_SEGMENTSTART, $this->VALID_SEGMENTSTOP, $this->VALID_SEGMENTSTARTELEVATION, $this->VALID_SEGMENTSTOPELEVATION);
     $segment->insert($this->getPDO());
     //delete this segment from mySQL
     $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("segment"));
     $segment->delete($this->getPDO());
     //grab the data from mySQL and make sure the segmentId does not exist
     $pdoSegment = Segment::getSegmentBySegmentId($this->getPDO(), $segment->getSegmentId());
     $this->assertNull($pdoSegment);
     $this->assertSame($numRows, $this->getConnection()->getRowCount("segment"));
 }