Route_Point.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. /**
  4. * Route_Point.
  5. *
  6. * Represents an object from the table 'route_point'.
  7. */
  8. class Route_Point extends Entity{
  9. /**
  10. * Identifier.
  11. */
  12. public $id;
  13. /**
  14. * Reference of the route it belongs to.
  15. */
  16. public $route;
  17. /**
  18. * Numberic order of this on the route .
  19. */
  20. public $part;
  21. /**
  22. * Minutes it takes to cmplete this.
  23. */
  24. public $mins;
  25. /**
  26. * Indicates if the segment must be visible.
  27. */
  28. public $visible;
  29. /**
  30. * Starting point.
  31. */
  32. public $start = [
  33. "lat" => null,
  34. "lon" => null
  35. ];
  36. /**
  37. * End point.
  38. */
  39. public $end = [
  40. "lat" => null,
  41. "lon" => null
  42. ];
  43. /**
  44. * Sorted array of {@see Route_Point}.
  45. */
  46. public $point = [];
  47. /**
  48. * Constructor.
  49. *
  50. * Searches the database and retrieves the information about the
  51. * entity, populating it and it's items.
  52. *
  53. * @param db Connection to the database.
  54. * @param id Identifier.
  55. */
  56. public function __construct($db, $id){
  57. parent::__construct($db, null);
  58. $s =
  59. "SELECT " .
  60. " id, " .
  61. " route, " .
  62. " part, " .
  63. " lat_o, " .
  64. " lon_o, " .
  65. " lat_d, " .
  66. " lon_d, " .
  67. " mins, " .
  68. " visible " .
  69. "FROM route_point " .
  70. "WHERE id = $id;";
  71. $q = mysqli_query($this->db, $s);
  72. if (mysqli_num_rows($q) > 0){
  73. $r = mysqli_fetch_array($q);
  74. $this->id = $r["id"];
  75. $this->route = $r["route"];
  76. $this->part = $r["part"];
  77. $this->mins = $r["mins"];
  78. if ($r["visible"] == 1){
  79. $this->visible = true;
  80. }
  81. else{
  82. $this->visible = false;
  83. }
  84. $this->start->lat = $r["lat_o"];
  85. $this->start->lon = $r["lon_o"];
  86. $this->end->lat = $r["lat_d"];
  87. $this->end->lon = $r["lon_d"];
  88. $s_point =
  89. "SELECT id " .
  90. "FROM route_point " .
  91. "WHERE " .
  92. " route = " . $this->id . " AND " .
  93. " visible = 1 " .
  94. "ORDER BY part;";
  95. $q_point = mysqli_query($this->db, $s_point);
  96. while($r_point = mysqli_fetch_array($q_point)){
  97. array_push($this->point, new Route_Point($this->db, $r_point["id"]));
  98. }
  99. }
  100. }
  101. }
  102. ?>