Source for file person.php

Documentation is available at person.php

  1. <?php
  2. /**
  3. * @package org.routamc.positioning
  4. * @author The Midgard Project, http://www.midgard-project.org
  5. * @version $Id: person.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. * Positioning for a given person
  12. *
  13. * <b>Example:</b>
  14. *
  15. * <code>
  16. * <?php
  17. * $user_position = new org_routamc_positioning_person($user);
  18. * $coordinates = $user_position->get_coordinates($time);
  19. * if (!is_null($coordinates))
  20. * {
  21. * echo sprintf('On %s % was in %s, %s', strftime('%x' $time), $user->name, $coordinates['latitude'], $coordinates['longitude']);
  22. * // Will print "On 19.6.2006 Henri Bergius was in 60.2345, 25.00456"
  23. * }
  24. * ?>
  25. * </code>
  26. *
  27. * @package org.routamc.positioning
  28. */
  29. class org_routamc_positioning_person extends midcom_baseclasses_components_purecode
  30. {
  31. /**
  32. * The person we're looking for position of
  33. *
  34. * @var midcom_db_person
  35. */
  36. var $_person = null;
  37. /**
  38. * Initializes the class. The real startup is done by the initialize() call.
  39. */
  40. function org_routamc_positioning_person($person)
  41. {
  42. $this->_component = 'org.routamc.positioning';
  43. if (!is_a($person, 'midcom_baseclasses_database_person'))
  44. {
  45. return false;
  46. }
  47. $this->_person = $person;
  48. parent::midcom_baseclasses_components_purecode();
  49. }
  50.  
  51. /**
  52. * Get log object based on given time and the person
  53. *
  54. * @return org_routamc_positioning_log_dba
  55. */
  56. function seek_log($time = null)
  57. {
  58. /*if (!$this->_person->can_do('org.routamc.positioning:location'))
  59. {
  60. return null;
  61. }*/
  62. if (is_null($time))
  63. {
  64. $time = time();
  65. }
  66. $qb = org_routamc_positioning_log_dba::new_query_builder();
  67. // TODO: Switch to metadata
  68. $qb->add_constraint('person', '=', $this->_person->id);
  69. $qb->add_constraint('date', '<=', $time);
  70. $qb->add_order('created', 'DESC');
  71. $qb->set_limit(1);
  72. $matches = $qb->execute_unchecked();
  73. if (count($matches) > 0)
  74. {
  75. return $matches[0];
  76. }
  77. return null;
  78. }
  79.  
  80. /**
  81. * Get coordinates of the object
  82. *
  83. * @return Array
  84. */
  85. function get_coordinates($time = null)
  86. {
  87. if (is_null($time))
  88. {
  89. // Default to current time
  90. $time = time();
  91. }
  92. $coordinates = Array(
  93. 'latitude' => null,
  94. 'longitude' => null,
  95. 'altitude' => null,
  96. );
  97. // No location set, seek based on creator and creation time
  98. $log = $this->seek_log($time);
  99. if (is_object($log))
  100. {
  101. $coordinates['latitude'] = $log->latitude;
  102. $coordinates['longitude'] = $log->longitude;
  103. $coordinates['altitude'] = $log->altitude;
  104. return $coordinates;
  105. }
  106. // No coordinates found, return null
  107. return null;
  108. }
  109. }

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