Route.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Route_Point.php");
  4. /**
  5. * Route.
  6. *
  7. * Represents an object from the table 'route'.
  8. */
  9. class Route extends Entity{
  10. /**
  11. * Identifier.
  12. */
  13. public $id;
  14. /**
  15. * Name of the route. Keyword with no actual value.
  16. */
  17. public $name;
  18. /**
  19. * Duration of the route.
  20. */
  21. public $mins;
  22. /**
  23. * Default zoom level. Arbitrary. 14 is OK for urban routes.
  24. */
  25. public $zoom;
  26. /**
  27. * Aproximate center of the route. Used to center map.
  28. */
  29. public $center = [
  30. "lat" => null,
  31. "lon" => null
  32. ];
  33. /**
  34. * Constructor.
  35. *
  36. * Searches the database and retrieves the information about the
  37. * entity, populating it and it's items.
  38. *
  39. * @param db Connection to the database.
  40. * @param id Identifier.
  41. */
  42. public function __construct($db, $id){
  43. parent::__construct($db, null);
  44. $s =
  45. "SELECT " .
  46. " id, " .
  47. " name, " .
  48. " mins, " .
  49. " c_lat, " .
  50. " c_lon, " .
  51. " zoom " .
  52. "FROM route " .
  53. "WHERE id = $id;";
  54. $q = mysqli_query($this->db, $s);
  55. if (mysqli_num_rows($q) > 0){
  56. $r = mysqli_fetch_array($q);
  57. $this->id = $r["id"];
  58. $this->name = $r["name"];
  59. $this->mins = $r["mins"];
  60. $this->zoom = $r["zoom"];
  61. $this->center["lat"] = $r["c_lat"];
  62. $this->center["lon"] = $r["c_lon"];
  63. }
  64. }
  65. }
  66. ?>