Automatically exported from code.google.com/p/planningalerts
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

application.php 6.5 KiB

há 18 anos
há 18 anos
há 18 anos
há 18 anos
há 18 anos
há 18 anos
há 18 anos
há 18 anos
há 17 anos
há 17 anos
há 18 anos
há 16 anos
há 18 anos
há 18 anos
há 18 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_received = "";
  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. $date_received = $db->quote($this->date_received);
  55. $map_url = $db->quote($this->map_url);
  56. $sql ="insert into application
  57. (
  58. council_reference,
  59. address,
  60. postcode,
  61. description,
  62. info_url,
  63. info_tinyurl,
  64. comment_url,
  65. comment_tinyurl,
  66. authority_id,
  67. x,
  68. y,
  69. date_scraped,
  70. date_recieved,
  71. map_url
  72. )
  73. values(
  74. $council_reference,
  75. $address,
  76. $postcode,
  77. $description,
  78. $info_url,
  79. $info_tinyurl,
  80. $comment_url,
  81. $comment_tinyurl,
  82. $authority_id,
  83. $x,
  84. $y,
  85. $date_scraped,
  86. $date_received,
  87. $map_url
  88. )";
  89. $db->query($sql);
  90. }
  91. }
  92. class Applications{
  93. //by point
  94. function query($x,$y,$d) {
  95. $db = DB::connect(DB_CONNECTION_STRING);
  96. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  97. from application
  98. inner join authority on application.authority_id = authority.authority_id
  99. where application.x > " . $db->quote($x - $d) . " and application.x < " . $db->quote($x + $d) .
  100. " and application.y > " . $db->quote($y - $d) . " and application.y < " . $db->quote($y + $d) .
  101. " order by date_scraped desc limit 100";
  102. $application_results = $db->getAll($sql);
  103. return applications::load_applications($application_results);
  104. }
  105. //by area
  106. function query_area($x1,$y1,$x2,$y2) {
  107. $db = DB::connect(DB_CONNECTION_STRING);
  108. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  109. from application
  110. inner join authority on application.authority_id = authority.authority_id
  111. where application.x > " . $db->quote($x1) . " and application.x < " . $db->quote($x2) .
  112. " and application.y > " . $db->quote($y1) . " and application.y < " . $db->quote($y2) .
  113. " order by date_scraped desc limit 100";
  114. $application_results = $db->getAll($sql);
  115. return applications::load_applications($application_results);
  116. }
  117. //by authority
  118. function query_authority($authority_short_name) {
  119. $db = DB::connect(DB_CONNECTION_STRING);
  120. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  121. from application
  122. inner join authority on application.authority_id = authority.authority_id
  123. where authority.short_name = " . $db->quote($authority_short_name) ." order by date_scraped desc limit 100";
  124. $application_results = $db->getAll($sql);
  125. return applications::load_applications($application_results);
  126. }
  127. //latest
  128. function query_latest($count = 100) {
  129. $db = DB::connect(DB_CONNECTION_STRING);
  130. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, date_scraped, full_name
  131. from application
  132. inner join authority on application.authority_id = authority.authority_id
  133. order by date_scraped desc limit " . $count;
  134. $application_results = $db->getAll($sql);
  135. return applications::load_applications($application_results);
  136. }
  137. function load_applications($application_results){
  138. $applications = array();
  139. if (sizeof($application_results) > 0) {
  140. for ($i=0; $i < sizeof($application_results); $i++) {
  141. $application = new application();
  142. $application->council_reference = $application_results[$i][0];
  143. $application->address = $application_results[$i][1];
  144. $application->postcode = $application_results[$i][2];
  145. $application->description = $application_results[$i][3];
  146. $application->info_url = $application_results[$i][4];
  147. $application->comment_url = $application_results[$i][5];
  148. $application->map_url = $application_results[$i][6];
  149. $application->x = $application_results[$i][7];
  150. $application->y = $application_results[$i][8];
  151. $application->date_received = $application_results[$i][9];
  152. $application->date_scraped = $application_results[$i][10];
  153. $application->authority_name = $application_results[$i][11];
  154. $os = new OSRef($application->x, $application->y);
  155. $latlng = $os->toLatLng();
  156. $application->lat = $latlng->lat;
  157. $application->lon = $latlng->lng;
  158. array_push($applications, $application);
  159. }
  160. }
  161. return $applications;
  162. }
  163. }
  164. ?>