public function load_controller() { // 내부 컨트롤러를 로딩하는 예제 // 새 트레일 오브젝트의 생성 $inner_trail = new Trail("/samples/load_controller_inner"); // 작업 일괄 처리 $inner_trail->work_through(); // 오브젝트 assign $this->assigns["inner_trail"] = $inner_trail; // 만일, 결과를 스트링으로 받는 경우. 다음과 같이 하면 됩니다. $this->assigns["inner_trail_rendered"] = $inner_trail->method_invoke(true); }
/** * test grabbing a Trail Relationship by segmentType **/ public function testGetValidTrailRelationshipBySegmentType() { // 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::getTrailRelationshipBySegmentType($this->getPDO(), $this->VALID_SEGMENTTYPE); $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); }
/** * test inserting a Rating and grabbing it from my sql */ public function testGetValidRatingByTrail() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("rating"); // create a new rating and insert it into my sql $rating = new Rating($this->trail->getTrailId(), $this->user->getUserId(), $this->VALID_RATINGVALUE); $rating->insert($this->getPDO()); //grab the data from mySQL and enforce the fields match expectations $pdoRatings = Rating::getRatingValueByTrailId($this->getPDO(), $this->trail->getTrailId()); foreach ($pdoRatings as $pdoRating) { $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("rating")); $this->assertSame($pdoRating->getRatingValue(), $this->VALID_RATINGVALUE); } }
Version: 0.8.0 Last modified: 2011-06-14 Version history _____________ Jun. 14, 2011 (0.8.0) object_trail 로 대부분의 기능이 분리됨 Jul. 13, 2010 (0.7.0) Feb. 6, 2010 (0.6.1) Jan. 13, 2010 (0.6) Apr. 7, 2009 (0.5) Contact: binseop@gmail.com */ if (phpversion() >= "5.4") { // error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING); error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING & ~E_DEPRECATED); ini_set("display_errors", 1); } // 모델 및 컨트롤러 베이스 로딩 include_once '../tf_app/core/model.php'; include_once '../tf_app/core/controller.php'; include_once '../tf_app/core/route.php'; include_once '../tf_app/core/object_trail.php'; session_start(); //include_once('../tf_app/core/error_handler.php'); $trail = new Trail($_REQUEST['tf_url']); $trail->load_global_components(); $trail->set_route(); $trail->load_components(); $trail->load_models(); $trail->method_invoke();
/** * 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); } }
$requestObject->trailUuid = null; } if ($method === "PUT") { verifyXsrf(); $trail = Trail::getTrailById($pdo, $id); if ($trail === null) { throw new RuntimeException("trail does not exist", 404); } $trail = new Trail($id, $requestObject->userId, $trail->getBrowser(), $trail->getCreateDate(), $trail->getIpAddress(), $requestObject->submitTrailId, $requestObject->trailAmenities, $requestObject->trailCondition, $requestObject->trailDescription, $requestObject->trailDifficulty, $requestObject->trailDistance, $requestObject->trailName, $requestObject->trailSubmissionType, $requestObject->trailTerrain, $requestObject->trailTraffic, $requestObject->trailUse, $requestObject->trailUuid); $trail->update($pdo); $reply->message = "trail updated okay"; } if ($method === "POST") { verifyXsrf(); //preform the actual post/do i need to treat foreign keys in any special manner $trail = new Trail(null, $requestObject->userId, $_SERVER["HTTP_USER_AGENT"], new DateTime(), $_SERVER["REMOTE_ADDR"], $requestObject->submitTrailId, $requestObject->trailAmenities, $requestObject->trailCondition, $requestObject->trailDescription, $requestObject->trailDifficulty, $requestObject->trailDistance, $requestObject->trailName, $requestObject->trailSubmissionType, $requestObject->trailTerrain, $requestObject->trailTraffic, $requestObject->trailUse, $requestObject->trailUuid); $trail->insert($pdo); $reply->message = "trail submitted okay"; } } } else { // if not an active user and attempting a method other than get, throw an exception 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(); $reply->message = $exception->getMessage(); //blob }
/** * test grabbing a comment by its commentText */ public function testGetValidCommentByCommentText() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("comment"); //create a new comment and insert it into mysql $comment = new Comment(null, $this->trail->getTrailId(), $this->user->getUserId(), $this->VALID_BROWSER, $this->VALID_CREATEDATE, $this->VALID_IPADDRESS, $this->VALID_COMMENTPHOTO, $this->VALID_COMMENTPHOTOTYPE, $this->VALID_COMMENTTEXT); $comment->insert($this->getPDO()); // grab the data from mySQL and enforce it meets expectations $pdoComments = Comment::getCommentByCommentText($this->getPDO(), $comment->getCommentText()); $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("comment")); foreach ($pdoComments as $pdoComment) { $this->assertSame($pdoComment->getBrowser(), $this->VALID_BROWSER); $this->assertEquals($pdoComment->getCreateDate(), $this->VALID_CREATEDATE); $this->assertSame($pdoComment->getIpAddress(), $this->VALID_IPADDRESS); $this->assertSame($pdoComment->getCommentPhoto(), $this->VALID_COMMENTPHOTO); $this->assertSame($pdoComment->getCommentPhotoType(), $this->VALID_COMMENTPHOTOTYPE); $this->assertSame($pdoComment->getCommentText(), $this->VALID_COMMENTTEXT); } }
/** * test grabbing a Trail by TrailUuId that does not exist * * @expectedException PDOException **/ public function testGetInvalidTrailByTrailUuId() { //grab a TrailUuId that does not exist $trail = Trail::getTrailByTrailUuId($this->getPDO(), "<script></script>"); $this->assertNull($trail); }
<?php require_once "Controller/Trailing.php"; if ($db->StartDbConnection()) { if (isset($_POST["submit-trail"])) { $doing = $_POST["Doing"]; $desc = $_POST["desc"]; $where = $_POST["Where"]; $tag = $_POST["tags"]; $trail = new Trail($_SESSION["user"], $doing, $desc, $where, $tag, $_SESSION["photolink"]); // add time if ($trail->SaveTrail($db->GetCon())) { echo "<b>Trail saved.</b>"; } } }