Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

application.php 6.4 KiB

18 vuotta sitten
18 vuotta sitten
18 vuotta sitten
18 vuotta sitten
18 vuotta sitten
18 vuotta sitten
18 vuotta sitten
18 vuotta sitten
17 vuotta sitten
17 vuotta sitten
17 vuotta sitten
17 vuotta sitten
17 vuotta sitten
18 vuotta sitten
16 vuotta sitten
17 vuotta sitten
18 vuotta sitten
18 vuotta sitten
18 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. require_once('config.php');
  3. require_once('DB.php');
  4. class Application{
  5. var $authority_id = 0;
  6. var $council_reference = "";
  7. var $date_recieved = "";
  8. var $date_scraped ="";
  9. var $address = "";
  10. var $postcode = "";
  11. var $description = "";
  12. var $status = "";
  13. var $info_url = "";
  14. var $info_tinyurl = "";
  15. var $comment_url = "";
  16. var $comment_tinyurl = "";
  17. var $map_url = "";
  18. var $x = 0;
  19. var $y = 0;
  20. #lat/lon used by rss.tpl, not yet in schema
  21. var $lat = 0;
  22. var $lon = 0;
  23. #authority name in join'd table 'authority'
  24. var $authority_name = "";
  25. function exists(){
  26. $db = DB::connect(DB_CONNECTION_STRING);
  27. $exists = false;
  28. $council_reference = $db->quote($this->council_reference);
  29. $authority_id = $db->quote($this->authority_id);
  30. $sql = "select application_id
  31. from application
  32. where council_reference = $council_reference
  33. and authority_id = $authority_id";
  34. if(sizeof($db->getAll($sql)) >0){
  35. $exists = true;
  36. }
  37. return $exists;
  38. }
  39. //Save
  40. function save(){
  41. $db = DB::connect(DB_CONNECTION_STRING);
  42. $council_reference = $db->quote($this->council_reference);
  43. $address = $db->quote($this->address);
  44. $postcode = $db->quote($this->postcode);
  45. $description = $db->quote($this->description);
  46. $info_url = $db->quote($this->info_url);
  47. $info_tinyurl = $db->quote($this->info_tinyurl);
  48. $comment_url = $db->quote($this->comment_url);
  49. $comment_tinyurl = $db->quote($this->comment_tinyurl);
  50. $authority_id = $db->quote($this->authority_id);
  51. $x = $db->quote($this->x);
  52. $y = $db->quote($this->y);
  53. $date_scraped = $db->quote($this->date_scraped);
  54. $map_url = $db->quote($this->map_url);
  55. $sql ="insert into application
  56. (
  57. council_reference,
  58. address,
  59. postcode,
  60. description,
  61. info_url,
  62. info_tinyurl,
  63. comment_url,
  64. comment_tinyurl,
  65. authority_id,
  66. x,
  67. y,
  68. date_scraped,
  69. map_url
  70. )
  71. values(
  72. $council_reference,
  73. $address,
  74. $postcode,
  75. $description,
  76. $info_url,
  77. $info_tinyurl,
  78. $comment_url,
  79. $comment_tinyurl,
  80. $authority_id,
  81. $x,
  82. $y,
  83. $date_scraped,
  84. $map_url
  85. )";
  86. $db->query($sql);
  87. }
  88. }
  89. class Applications{
  90. //by point
  91. function query($x,$y,$d) {
  92. $db = DB::connect(DB_CONNECTION_STRING);
  93. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  94. from application
  95. inner join authority on application.authority_id = authority.authority_id
  96. where application.x > " . $db->quote($x - $d) . " and application.x < " . $db->quote($x + $d) .
  97. " and application.y > " . $db->quote($y - $d) . " and application.y < " . $db->quote($y + $d) .
  98. " order by date_scraped desc limit 100";
  99. $application_results = $db->getAll($sql);
  100. return applications::load_applications($application_results);
  101. }
  102. //by area
  103. function query_area($x1,$y1,$x2,$y2) {
  104. $db = DB::connect(DB_CONNECTION_STRING);
  105. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  106. from application
  107. inner join authority on application.authority_id = authority.authority_id
  108. where application.x > " . $db->quote($x1) . " and application.x < " . $db->quote($x2) .
  109. " and application.y > " . $db->quote($y1) . " and application.y < " . $db->quote($y2) .
  110. " order by date_scraped desc limit 100";
  111. $application_results = $db->getAll($sql);
  112. return applications::load_applications($application_results);
  113. }
  114. //by authority
  115. function query_authority($authority_short_name) {
  116. $db = DB::connect(DB_CONNECTION_STRING);
  117. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  118. from application
  119. inner join authority on application.authority_id = authority.authority_id
  120. where authority.short_name = " . $db->quote($authority_short_name) ." order by date_scraped desc limit 100";
  121. $application_results = $db->getAll($sql);
  122. return applications::load_applications($application_results);
  123. }
  124. //latest
  125. function query_latest($count = 100) {
  126. $db = DB::connect(DB_CONNECTION_STRING);
  127. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  128. from application
  129. inner join authority on application.authority_id = authority.authority_id
  130. order by date_scraped desc limit " . $count;
  131. $application_results = $db->getAll($sql);
  132. return applications::load_applications($application_results);
  133. }
  134. function load_applications($application_results){
  135. $applications = array();
  136. if (sizeof($application_results) > 0) {
  137. for ($i=0; $i < sizeof($application_results); $i++) {
  138. $application = new application();
  139. $application->council_reference = $application_results[$i][0];
  140. $application->address = $application_results[$i][1];
  141. $application->postcode = $application_results[$i][2];
  142. $application->description = $application_results[$i][3];
  143. $application->info_url = $application_results[$i][4];
  144. $application->comment_url = $application_results[$i][5];
  145. $application->map_url = $application_results[$i][6];
  146. $application->x = $application_results[$i][7];
  147. $application->y = $application_results[$i][8];
  148. $application->date_received = $application_results[$i][9];
  149. $application->date_scraped = $application_results[$i][10];
  150. $application->authority_name = $application_results[$i][11];
  151. $os = new OSRef($application->x, $application->y);
  152. $latlng = $os->toLatLng();
  153. $application->lat = $latlng->lat;
  154. $application->lon = $latlng->lng;
  155. array_push($applications, $application);
  156. }
  157. }
  158. return $applications;
  159. }
  160. }
  161. ?>