Пример #1
0
 /**
  * Get coordinates of the object
  *
  * @return Array
  */
 function get_coordinates($person = null, $time = null, $cache = true)
 {
     $coordinates = array('latitude' => null, 'longitude' => null, 'altitude' => null);
     if (is_a($this->_object, 'midcom_db_person')) {
         // This is a person record. Seek log
         $user_position = new org_routamc_positioning_person($this->_object);
         return $user_position->get_coordinates($time);
     }
     if (is_null($time)) {
         if (!isset($this->_object->metadata->published)) {
             //return null;
             $time = time();
         }
         $time = $this->_object->metadata->published;
     }
     // Check if the object has a location set
     $location = $this->seek_location_object();
     if (is_object($location) && $location->guid) {
         $coordinates['latitude'] = $location->latitude;
         $coordinates['longitude'] = $location->longitude;
         $coordinates['altitude'] = $location->altitude;
         // Consistency check
         if ($location->date != $time) {
             if ($location->log) {
                 // We are most likely pointing to wrong log. Remove this cached entry so we can recreate i
                 // again below
                 midcom::get('auth')->request_sudo('org.routamc.positioning');
                 $location->delete();
                 $cache = true;
                 midcom::get('auth')->drop_sudo();
             } else {
                 // This location entry isn't coming from a log so it just needs to be rescheduled
                 midcom::get('auth')->request_sudo('org.routamc.positioning');
                 $location->date = $time;
                 $location->update();
                 midcom::get('auth')->drop_sudo();
                 return $coordinates;
             }
         } else {
             return $coordinates;
         }
     }
     // No location set, seek based on creator and creation time
     $log = $this->seek_log_object($person, $time);
     if (is_object($log)) {
         $coordinates['latitude'] = $log->latitude;
         $coordinates['longitude'] = $log->longitude;
         $coordinates['altitude'] = $log->altitude;
         if ($cache) {
             // Cache the object's location into a location object
             midcom::get('auth')->request_sudo('org.routamc.positioning');
             $location = new org_routamc_positioning_location_dba();
             $location->log = $log->id;
             $location->relation = (int) ORG_ROUTAMC_POSITIONING_RELATION_IN;
             $location->date = $time;
             $location->parent = $this->_object->guid;
             $location->parentclass = get_class($this->_object);
             // TODO: Save parent component
             $location->latitude = $log->latitude;
             $location->longitude = $log->longitude;
             $location->altitude = $log->altitude;
             $location->create();
             midcom::get('auth')->drop_sudo();
         }
         return $coordinates;
     }
     // No coordinates found, return null
     return null;
 }
Пример #2
0
 /**
  * Handle storing Flickr-style geo tags to org.routamc.positioning
  * storage should be to org_routamc_positioning_location_dba object
  * with relation ORG_ROUTAMC_POSITIONING_RELATION_IN
  *
  * @return boolean
  */
 private function _geotag()
 {
     if (!$GLOBALS['midcom_config']['positioning_enable']) {
         return false;
     }
     midcom::get('componentloader')->load_library('org.routamc.positioning');
     // Get all "geo" tags of the object
     $object = midcom::get('dbfactory')->get_object_by_guid($this->fromGuid);
     $geotags = net_nemein_tag_handler::get_object_machine_tags_in_context($object, 'geo');
     $position = array('longitude' => null, 'latitude' => null, 'altitude' => null);
     foreach ($geotags as $key => $value) {
         switch ($key) {
             case 'lon':
             case 'lng':
             case 'long':
                 $position['longitude'] = $value;
                 break;
             case 'lat':
                 $position['latitude'] = $value;
                 break;
             case 'alt':
                 $position['altitude'] = $value;
                 break;
         }
     }
     if (is_null($position['longitude']) || is_null($position['latitude'])) {
         // Not enough information for positioning, we need both lon and lat
         return false;
     }
     $object_location = new org_routamc_positioning_location_dba();
     $object_location->relation = ORG_ROUTAMC_POSITIONING_RELATION_IN;
     $object_location->parent = $this->fromGuid;
     $object_location->parentclass = $this->fromClass;
     $object_location->parentcomponent = $this->fromComponent;
     $object_location->date = $this->metadata->published;
     $object_location->longitude = $position['longitude'];
     $object_location->latitude = $position['latitude'];
     $object_location->altitude = $position['altitude'];
     return $object_location->create();
 }
Пример #3
0
<?php

midcom::get('auth')->require_admin_user();
midcom::get()->disable_limits();
$json = file_get_contents('/tmp/doors.json');
$doors = json_decode($json);
echo "<pre>\n";
foreach ($doors->entrances as $entrance) {
    $location = new org_routamc_positioning_location_dba();
    $location->latitude = (double) ($entrance->lat / 20037508.34) * 180;
    $location->latitude = 180 / M_PI * (2 * atan(exp($location->latitude * M_PI / 180)) - M_PI / 2);
    $location->longitude = (double) ($entrance->lon / 20037508.34) * 180;
    $location->building = (string) $entrance->title;
    $location->street = (string) $entrance->address;
    if (isset($entrance->descr)) {
        $location->description = (string) $entrance->descr;
    }
    if (isset($entrance->url)) {
        $location->uri = (string) $entrance->url;
    }
    // Other metadata
    $location->relation = 20;
    $location->create();
    echo "{$location->building}: " . midcom_connection::get_error_string() . "\n";
}
echo "</pre>\n";
Пример #4
0
 private function _check_group_url(org_openpsa_contacts_group_dba $group)
 {
     $data = org_openpsa_contacts_interface::_get_data_from_url($group->homepage);
     // Use the data we got
     if (array_key_exists('icbm', $data)) {
         // We know where the group is located
         $icbm_parts = explode(',', $data['icbm']);
         if (count($icbm_parts) == 2) {
             $latitude = (double) $icbm_parts[0];
             $longitude = (double) $icbm_parts[1];
             if ($latitude < 90 && $latitude > -90 && ($longitude < 180 && $longitude > -180)) {
                 $location = new org_routamc_positioning_location_dba();
                 $location->date = time();
                 $location->latitude = $latitude;
                 $location->longitude = $longitude;
                 $location->relation = ORG_ROUTAMC_POSITIONING_RELATION_LOCATED;
                 $location->parent = $group->guid;
                 $location->parentclass = 'org_openpsa_contacts_group_dba';
                 $location->parentcomponent = 'org.openpsa.contacts';
                 $location->create();
             } else {
                 // This is no earth coordinate, my friend
             }
         }
     }
     // TODO: We can use a lot of other data too
     if (array_key_exists('hcards', $data)) {
         // Process those hCard values that are interesting for us
         foreach ($data['hcards'] as $hcard) {
             $group = $this->_update_from_hcard($group, $hcard);
         }
         $group->update();
     }
     return true;
 }
Пример #5
0
 private function _claim_location_entries()
 {
     $previous = $this->get_previous();
     if (is_object($previous)) {
         $qb = org_routamc_positioning_location_dba::new_query_builder();
         // Find locations reported to previous log but after
         // this log's date
         $qb->add_constraint('log', '=', $previous->id);
         $qb->add_constraint('date', '>=', $this->date);
         $matches = $qb->execute();
         if (count($matches) > 0) {
             foreach ($matches as $location) {
                 // Switch the location to point to this log
                 $location->log = $this->id;
                 $location->latitude = $this->latitude;
                 $location->longitude = $this->longitude;
                 $location->altitude = $this->altitude;
                 $location->update();
             }
         }
     }
 }