Automatically exported from code.google.com/p/planningalerts
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

application.php 4.8 KiB

18 年前
18 年前
18 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. function query($x,$y,$d) {
  91. $db = DB::connect(DB_CONNECTION_STRING);
  92. $sql = "select council_reference, address, postcode, description, info_url, comment_url, map_url, x, y, date_recieved, full_name
  93. from application
  94. inner join authority on application.authority_id = authority.authority_id
  95. where application.x > " . $db->quote($x - $d) . " and application.x < " . $db->quote($x + $d) .
  96. " and application.y > " . $db->quote($y - $d) . " and application.y < " . $db->quote($y + $d) .
  97. " order by date_scraped desc limit 100";
  98. $application_results = $db->getAll($sql);
  99. $applications = array();
  100. if (sizeof($application_results) > 0) {
  101. for ($i=0; $i < sizeof($application_results); $i++) {
  102. $application = new application();
  103. $application->council_reference = $application_results[$i][0];
  104. $application->address = $application_results[$i][1];
  105. $application->postcode = $application_results[$i][2];
  106. $application->description = $application_results[$i][3];
  107. $application->info_url = $application_results[$i][4];
  108. $application->comment_url = $application_results[$i][5];
  109. $application->map_url = $application_results[$i][6];
  110. $application->x = $application_results[$i][7];
  111. $application->y = $application_results[$i][8];
  112. $application->date_received = $application_results[$i][9];
  113. $application->authority_name = $application_results[$i][10];
  114. $os = new OSRef($application->x, $application->y);
  115. $latlng = $os->toLatLng();
  116. $application->lat = $latlng->lat;
  117. $application->lon = $latlng->lng;
  118. array_push($applications, $application);
  119. }
  120. }
  121. return $applications;
  122. }
  123. }
  124. ?>