Source for file manual.php

Documentation is available at manual.php

  1. <?php
  2. /**
  3. * @package org.routamc.positioning
  4. * @author The Midgard Project, http://www.midgard-project.org
  5. * @version $Id: manual.php 3757 2006-07-27 14:32:42Z bergie $
  6. * @copyright The Midgard Project, http://www.midgard-project.org
  7. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
  8. */
  9.  
  10. /**
  11. * Importer for manually entered positions
  12. *
  13. * @package org.routamc.positioning
  14. */
  15. class org_routamc_positioning_importer_manual extends org_routamc_positioning_importer
  16. {
  17. /**
  18. * Initializes the class. The real startup is done by the initialize() call.
  19. */
  20. function org_routamc_positioning_importer_manual()
  21. {
  22. parent:: org_routamc_positioning_importer();
  23. }
  24. /**
  25. * Import manually entered log entry. The entries are associative arrays containing
  26. * some or all of the following keys:
  27. *
  28. * - latitude
  29. * - longitude
  30. * - altitude
  31. * - city
  32. * - country
  33. * - aerodrome
  34. *
  35. * @param Array $log Log entry in Array format specific to importer
  36. * @return bool Indicating success.
  37. */
  38. function import($log)
  39. {
  40. $this->log = new org_routamc_positioning_log_dba();
  41. $this->log->importer = 'manual';
  42. // Set different person if required
  43. if (array_key_exists('person', $log))
  44. {
  45. $this->log->person = $log['person'];
  46. }
  47. else
  48. {
  49. $this->log->person = $_MIDGARD['user'];
  50. }
  51. $this->log->date = time();
  52. // Figure out which option we will use, starting from best option
  53. // Best option: we know coordinates
  54. if ( array_key_exists('latitude', $log)
  55. && array_key_exists('longitude', $log))
  56. {
  57. // Manually entered positions are assumed to be only semi-accurate
  58. $this->log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_MANUAL;
  59. // Normalize coordinates to decimal
  60. $coordinates = $this->normalize_coordinates($log['latitude'], $log['longitude']);
  61. $this->log->latitude = $coordinates['latitude'];
  62. $this->log->longitude = $coordinates['longitude'];
  63. }
  64.  
  65. // Airport entered
  66. if (array_key_exists('aerodrome', $log))
  67. {
  68. // Aerodrome position is not usually very accurate, except if we're at the airport of course
  69. $this->log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_CITY;
  70. // Normalize aerodrome name
  71. $aerodrome = strtoupper($log['aerodrome']);
  72. // Seek the aerodrome entry, first by accurate match
  73. $aerodrome_entry = null;
  74. $qb = org_routamc_positioning_aerodrome_dba::new_query_builder();
  75. $qb->begin_group('OR');
  76. // We will seek by both ICAO and IATA codes
  77. $qb->add_constraint('icao', '=', $aerodrome);
  78. $qb->add_constraint('iata', '=', $aerodrome);
  79. $qb->end_group();
  80. $matches = $qb->execute();
  81. if (count($matches) > 0)
  82. {
  83. $aerodrome_entry = $matches[0];
  84. }
  85. if (is_null($aerodrome_entry))
  86. {
  87. // Couldn't match the entered city to a location
  88. $this->error = 'POSITIONING_AERODROME_NOT_FOUND';
  89. return false;
  90. }
  91. // Normalize coordinates
  92. $this->log->latitude = $aerodrome_entry->latitude;
  93. $this->log->longitude = $aerodrome_entry->longitude;
  94. $this->log->altitude = $aerodrome_entry->altitude;
  95. }
  96. // City and country entered
  97. if ( array_key_exists('city', $log)
  98. && array_key_exists('country', $log))
  99. {
  100. // City position is not very accurate
  101. $this->log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_CITY;
  102. $this->log->altitude = 0;
  103. // Normalize country name
  104. $country = $this->normalize_country($log['country']);
  105. // Seek the city entry, first by accurate match
  106. $city_entry = null;
  107. $qb = org_routamc_positioning_city_dba::new_query_builder();
  108. $qb->add_constraint('city', '=', $log['city']);
  109. $qb->add_constraint('country', '=', $log['country']);
  110. $matches = $qb->execute();
  111. if (count($matches) > 0)
  112. {
  113. $city_entry = $matches[0];
  114. }
  115.  
  116. if (is_null($city_entry))
  117. {
  118. // Seek the city entry by alternate names via a LIKE query
  119. $qb = org_routamc_positioning_city_dba::new_query_builder();
  120. $qb->add_constraint('alternatenames', 'LIKE', "%|{$log['city']}|%");
  121. $qb->add_constraint('country', '=', $log['country']);
  122. $matches = $qb->execute();
  123. if (count($matches) > 0)
  124. {
  125. $city_entry = $matches[0];
  126. }
  127. }
  128. if (is_null($city_entry))
  129. {
  130. // Couldn't match the entered city to a location
  131. $this->error = 'POSITIONING_CITY_NOT_FOUND';
  132. return false;
  133. }
  134. // Normalize coordinates
  135. $this->log->latitude = $city_entry->latitude;
  136. $this->log->longitude = $city_entry->longitude;
  137. }
  138. // Save altitude if provided
  139. if (array_key_exists('altitude', $log))
  140. {
  141. $this->log->altitude = $log['altitude'];
  142. }
  143. // Try to create the entry
  144. //print_r($this->log);
  145. //die();
  146. $stat = $this->log->create();
  147. $this->error = mgd_errstr();
  148. return $stat;
  149. }
  150. function normalize_country($country)
  151. {
  152. // TODO: Modify country to conform to ISO standards
  153. return $country;
  154. }
  155. }

Documentation generated on Tue, 15 Aug 2006 12:43:36 +0300 by phpDocumentor 1.3.0RC3