array_push($response["journey"], $tmp); } echoRespnse(200, $response); }); /** * Listing single journey of particular user * method GET * url /journey/:id * Will return 404 if the journey doesn't belongs to user */ $app->get('/journey/:id', 'authenticate', function ($journey_id) { global $user_id; $response = array(); $db = new DbHandler(); // fetch journey $result = $db->getJourney($journey_id, $user_id); if ($result != NULL) { $response["error"] = false; $response["id"] = $result["id"]; $response["journey_score"] = rand(1, 100); //$result["journey_score"]; // generating random score since analysis doesnt work $response["status"] = $result["status"]; $response["createdAt"] = $result["created_at"]; echoRespnse(200, $response); } else { $response["error"] = true; $response["message"] = "The requested resource doesn't exists"; echoRespnse(404, $response); } }); /**
/** * Updating Journey data table * @param String $journey_id id of the journey * @param String $user_id id of the user * @param String $x_gps gps x coordinate * @param String $y_gps gps y coordinate * @param String $z_gps gps z coordinate * @param String $x_acl accelerometer x coordinate * @param String $y_acl accelerometer y coordinate * @param String $z_acl accelerometer z coordinate * @param String $timestamp time when data was sampled * @param String $sample_no the sample number of the journey * * jd - journey data table * j - journeys table * uj - user journeys table */ public function updateJourneyData($journey_id, $user_id, $x_gps, $y_gps, $x_acl, $y_acl, $z_acl, $timestamp, $sample_no) { $db = new DbHandler(); $result = $db->getJourney($journey_id, $user_id); if ($result == NULL) { //journey doesnt belong to user or doesnt exist return 0; } else { if ($result["status"] == 1) { // cant add data information to a completed journey return 0; } } // At last we can add the journey data! $stmt = $this->conn->prepare("INSERT INTO journey_data(journey_id, x_gps, y_gps, x_acl, y_acl, z_acl, time_stamp, sample_no) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("idddddsi", $journey_id, $x_gps, $y_gps, $x_acl, $y_acl, $z_acl, $timestamp, $sample_no); $stmt->execute(); $num_affected_rows = $stmt->affected_rows; $stmt->close(); return $num_affected_rows > 0; }