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.
 
 
 
 
 
 

194 regels
6.5 KiB

  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. ?>