Source for file log.php

Documentation is available at log.php

  1. <?php
  2. /**
  3. * @package org.routamc.positioning
  4. * @author The Midgard Project, http://www.midgard-project.org
  5. * @version $Id: log.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. * MidCOM wrapper class for user position log entries
  12. *
  13. * @package org.routamc.positioning
  14. */
  15. class org_routamc_positioning_log_dba extends __org_routamc_positioning_log_dba
  16. {
  17. function org_routamc_positioning_log_dba($id = null)
  18. {
  19. return parent::__org_routamc_positioning_log_dba($id);
  20. }
  21.  
  22. /**
  23. * Returns the person who reported the position
  24. *
  25. * @return midcom_db_person Parent person
  26. */
  27. function get_parent_guid_uncached()
  28. {
  29. if ($this->person)
  30. {
  31. $parent = new midcom_db_person($this->person);
  32. if (! $parent)
  33. {
  34. debug_push_class(__CLASS__, __FUNCTION__);
  35. debug_add("Could not load Person ID {$this->person} from the database, aborting.",
  36. MIDCOM_LOG_INFO);
  37. debug_pop();
  38. return null;
  39. }
  40. return $parent->guid;
  41. }
  42.  
  43. return null;
  44. }
  45. /**
  46. * Don't save log if previous log is in same place
  47. */
  48. function _on_creating()
  49. {
  50. $previous = $this->get_previous();
  51. if ( round($previous->longitude, 4) == round($this->longitude, 4)
  52. && round($previous->latitude, 4) == round($this->latitude, 4)
  53. && $previous->altitude == $this->altitude)
  54. {
  55. // We don't need to save duplicate entries
  56. return false;
  57. }
  58. return parent::_on_creating();
  59. }
  60.  
  61. /**
  62. * Returns the previous log entry by the person
  63. *
  64. * @return org_routamc_positioning_log_dba Previous log entry
  65. */
  66. function get_previous()
  67. {
  68. $qb = org_routamc_positioning_log_dba::new_query_builder();
  69. $qb->add_constraint('person', '=', $this->person);
  70. $qb->add_constraint('date', '<', $this->date);
  71. $qb->add_order('date', 'DESC');
  72. $qb->set_limit(1);
  73. $matches = $qb->execute_unchecked();
  74. if (count($matches) > 0)
  75. {
  76. return $matches[0];
  77. }
  78. return null;
  79. }
  80. /**
  81. * Returns the next log entry by the person
  82. *
  83. * @return org_routamc_positioning_log_dba Next log entry
  84. */
  85. function get_next()
  86. {
  87. $qb = org_routamc_positioning_log_dba::new_query_builder();
  88. $qb->add_constraint('person', '=', $this->person);
  89. $qb->add_constraint('date', '>', $this->date);
  90. $qb->add_order('date', 'ASC');
  91. $qb->set_limit(1);
  92. $matches = $qb->execute_unchecked();
  93. if (count($matches) > 0)
  94. {
  95. return $matches[0];
  96. }
  97. return null;
  98. }
  99. function _claim_location_entries()
  100. {
  101. $previous = $this->get_previous();
  102.  
  103. if (is_object($previous))
  104. {
  105. $qb = <a href="../org.routamc.positioning/org_routamc_positioning_location_dba.html">org_routamc_positioning_location_dba</a>::new_query_builder();
  106. // Find locations reported to previous log but after
  107. // this log's date
  108. $qb->add_constraint('log', '=', $previous->id);
  109. $qb->add_constraint('date', '>=', $this->date);
  110.  
  111. $matches = $qb->execute();
  112. if (count($matches) > 0)
  113. {
  114. foreach ($matches as $location)
  115. {
  116. // Switch the location to point to this log
  117. $location->log = $this->id;
  118. $location->latitude = $this->latitude;
  119. $location->longitude = $this->longitude;
  120. $location->altitude = $this->altitude;
  121. $location->update();
  122. }
  123. }
  124. }
  125. }
  126.  
  127. /**
  128. * Checks after log creation, switch cached location entries of objects
  129. * made after the previous log entry by the person and before this one.
  130. */
  131. function _on_created()
  132. {
  133. $this->_claim_location_entries();
  134. return true;
  135. }
  136. }

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