示例#1
0
文件: city.php 项目: nemein/openpsa
 /**
  * @return org_routamc_positioning_country_dba Country the city is in
  */
 function get_parent_guid_uncached()
 {
     if ($this->country) {
         $qb = org_routamc_positioning_country_dba::new_query_builder();
         $qb->add_constraint('code', '=', $this->country);
         $countries = $qb->execute();
         if (count($countries) == 0) {
             debug_add("Could not load Country ID {$this->country} from the database, aborting.", MIDCOM_LOG_INFO);
             return null;
         }
         return $countries[0]->guid;
     }
     return null;
 }
示例#2
0
 static function get_by_name($name)
 {
     // Seek by strict city name first
     $qb = org_routamc_positioning_country_dba::new_query_builder();
     $qb->add_constraint('name', 'LIKE', $name);
     $qb->set_limit(1);
     $matches = $qb->execute_unchecked();
     if (count($matches) > 0) {
         return $matches[0];
     }
     // Strict name didn't match, seek by alternate names
     $qb = org_routamc_positioning_country_dba::new_query_builder();
     $qb->add_constraint('alternatenames', 'LIKE', "%{$name}%");
     // Most likely we're interested in the biggest city that matches
     $qb->add_order('population', 'DESC');
     $qb->set_limit(1);
     $matches = $qb->execute_unchecked();
     if (count($matches) > 0) {
         return $matches[0];
     }
     return false;
 }
示例#3
0
 public function __construct($args)
 {
     $this->_component = 'org.routamc.positioning';
     parent::__construct();
     $this->_data = array();
     if (isset($args['start_message'])) {
         if (is_bool($args['start_message']) && $args['start_message']) {
             $this->_data[''] = $this->_l10n->get('select your country');
         } else {
             if (is_string($args['start_message'])) {
                 $this->_data[''] = $args['start_message'];
             }
         }
     }
     $qb = org_routamc_positioning_country_dba::new_query_builder();
     $qb->add_constraint('code', '<>', '');
     $qb->add_order('name', 'ASC');
     $countries = $qb->execute_unchecked();
     if (count($countries) == 0) {
         debug_add('No countries found. You have to use org.routamc.positioning to import countries to database.');
     }
     $this->_populate_data($countries);
 }
示例#4
0
文件: widget.php 项目: nemein/openpsa
 function _get_country_list()
 {
     $this->_countrylist = array('' => midcom::get('i18n')->get_string('select your country', 'org.routamc.positioning'));
     $qb = org_routamc_positioning_country_dba::new_query_builder();
     $qb->add_constraint('code', '<>', '');
     $qb->add_order('name', 'ASC');
     $countries = $qb->execute_unchecked();
     if (count($countries) == 0) {
         debug_add('Cannot render country list: No countries found. You have to use org.routamc.positioning to import countries to database.');
     }
     foreach ($countries as $country) {
         $this->_countrylist[$country->code] = $country->name;
     }
 }
示例#5
0
文件: manual.php 项目: nemein/openpsa
 /**
  * Modify country to conform to ISO standards
  */
 function normalize_country($country)
 {
     if (strlen($country) == 2) {
         // Probably an ISO code
         return $country;
     }
     $qb = org_routamc_positioning_country_dba::new_query_builder();
     $qb->add_constraint('name', '=', $country);
     $countries = $qb->execute();
     if (count($countries) > 0) {
         return $countries[0]->code;
     }
     return '';
 }
示例#6
0
文件: fetch.php 项目: nemein/openpsa
 /**
  * Imports an item as an event
  */
 private function import_event($item)
 {
     // Check that we're trying to import item suitable to be an event
     if (!isset($item['xcal']) && !isset($item['gd']['when@'])) {
         // Not an event
         return false;
     }
     // Get start and end times
     $start = null;
     $end = null;
     if (isset($item['xcal']['dtstart'])) {
         // xCal RSS feed, for example Upcoming or Last.fm
         $start = strtotime($item['xcal']['dtstart']);
     } elseif (isset($item['gd']['when@starttime'])) {
         // gData Atom feed, for example Dopplr
         $start = strtotime($item['gd']['when@starttime']);
     }
     if (isset($item['xcal']['dtend'])) {
         $end = strtotime($item['xcal']['dtend']);
     } elseif (isset($item['gd']['when@starttime'])) {
         $end = strtotime($item['gd']['when@endtime']);
     }
     if (!$start || !$end) {
         return false;
     }
     if (!$this->_datamanager) {
         $schemadb = midcom_helper_datamanager2_schema::load_database($this->_node_config->get('schemadb'));
         $this->_datamanager = new midcom_helper_datamanager2_datamanager($schemadb);
     }
     // TODO: Move to real geocoded stuff
     $location_parts = array();
     if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-venue-name'])) {
         $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-venue-name'];
     }
     if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-street'])) {
         $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-street'];
     }
     if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-city'])) {
         $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-city'];
     }
     if (isset($item['gd']['where@valuestring'])) {
         $wherevalues = explode(' ', $item['gd']['where@valuestring']);
         foreach ($wherevalues as $val) {
             $location_parts[] = $val;
         }
     }
     $qb = net_nemein_calendar_event_dba::new_query_builder();
     $qb->add_constraint('node', '=', $this->_feed->node);
     $qb->add_constraint('extra', '=', md5($item['guid']));
     $events = $qb->execute();
     if (count($events) > 0) {
         // This item has been imported already earlier. Update
         $event = $events[0];
         $event->_activitystream_verb = 'http://community-equity.org/schema/1.0/clone';
         $event->_rcs_message = sprintf(midcom::get('i18n')->get_string('%s was imported from %s', 'net.nemein.rss'), $event->title, $this->_feed->title);
         $event->allow_name_catenate = true;
         if (empty($event->name)) {
             $resolver = new midcom_helper_reflector_nameresolver($event);
             // To prevent validation errors in case the auto-catenate is not allowed in the urlname datatype
             $event->name = $resolver->generate_unique_name();
         }
     } else {
         $node = new midcom_db_topic($this->_feed->node);
         $node_lang_code = $node->get_parameter('net.nemein.calendar', 'language');
         // This is a new item
         $event = new net_nemein_calendar_event_dba();
         $event->start = $start;
         $event->end = $end;
         $event->extra = md5($item['guid']);
         $event->node = $this->_feed->node;
         if ($node->get_parameter('net.nemein.calendar', 'symlink_topic') != '') {
             try {
                 $symlink_topic = new midcom_db_topic($node->get_parameter('net.nemein.calendar', 'symlink_topic'));
                 $event->node = $symlink_topic->id;
             } catch (midcom_error $e) {
                 $e->log();
             }
         }
         if ($node_lang_code != '') {
             $lang_id = midcom::get('i18n')->code_to_id($node_lang_code);
             $event->lang = $lang_id;
         }
         $event->allow_name_catenate = true;
         $event->title = (string) $item['title'];
         $event->_activitystream_verb = 'http://community-equity.org/schema/1.0/clone';
         $event->_rcs_message = sprintf(midcom::get('i18n')->get_string('%s was imported from %s', 'net.nemein.rss'), $event->title, $this->_feed->title);
         $resolver = new midcom_helper_reflector_nameresolver($event);
         $event->name = $resolver->generate_unique_name();
         if (!$event->create()) {
             return false;
         }
     }
     $this->_datamanager->autoset_storage($event);
     $this->_datamanager->types['start']->value = new DateTime(strftime('%Y-%m-%d %H:%M:%S', $start));
     $this->_datamanager->types['end']->value = new DateTime(strftime('%Y-%m-%d %H:%M:%S', $end));
     if (is_a($this->_datamanager->types['location'], 'midcom_helper_datamanager2_type_position')) {
         // Position type, give all values we got, assume order "Street, City, Country"
         $location_parts = array_reverse($location_parts);
         if (count($location_parts) > 0) {
             $country = org_routamc_positioning_country_dba::get_by_name($location_parts[0]);
             if ($country && $country->code) {
                 $this->_datamanager->types['location']->location->county = $country->code;
             }
         }
         if (count($location_parts) > 1) {
             $city = org_routamc_positioning_city_dba::get_by_name($location_parts[1]);
             if ($city && $city->id) {
                 $this->_datamanager->types['location']->location->city = $city->id;
             }
         }
         if (count($location_parts) > 2) {
             $this->_datamanager->types['location']->location->street = $location_parts[2];
         }
         if (isset($item['gml'])) {
             $gml_parts = explode(' ', $item['gml']['where_point_pos']);
             if (count($gml_parts) == 2) {
                 $this->_datamanager->types['location']->location->latitude = (double) $gml_parts[0];
                 $this->_datamanager->types['location']->location->longitude = (double) $gml_parts[1];
             }
         }
     } else {
         // Just give the location string we got
         $this->_datamanager->types['location']->value = implode(', ', $location_parts);
     }
     foreach ($item as $key => $value) {
         if (isset($this->_datamanager->types[$key])) {
             $this->_datamanager->types[$key]->value = $value;
         }
     }
     if (!$this->_datamanager->save()) {
         return false;
     }
     // This should be unnecessary but left in place just to be sure
     if (strlen($this->_datamanager->storage->object->name) == 0) {
         // Generate something to avoid empty "/" links in case of failures
         $this->_datamanager->storage->object->name = time();
         $this->_datamanager->storage->object->update();
     }
     $this->parse_tags($event, $item, 'description');
     $this->parse_parameters($event, $item);
     return $event->guid;
 }
示例#7
0
<?php

midcom::get('auth')->require_admin_user();
$http_request = new org_openpsa_httplib();
$xml = $http_request->get('http://ws.geonames.org/countryInfo?lang=' . midcom::get('i18n')->get_current_language());
$simplexml = simplexml_load_string($xml);
foreach ($simplexml->country as $id => $countryinfo) {
    echo "<br />Importing {$countryinfo->countryName}...\n";
    $country = new org_routamc_positioning_country_dba();
    $country->code = (string) $countryinfo->countryCode;
    $country->name = (string) $countryinfo->countryName;
    $country->codenumeric = (string) $countryinfo->isoNumeric;
    $country->code3 = (string) $countryinfo->isoAlpha3;
    $country->fips = (string) $countryinfo->fipsCode;
    $country->continent = (string) $countryinfo->continent;
    $country->area = (double) $countryinfo->areaInSqKm;
    $country->population = (int) $countryinfo->population;
    $country->currency = (string) $countryinfo->currencyCode;
    $country->bboxwest = (double) $countryinfo->bBoxWest;
    $country->bboxnorth = (double) $countryinfo->bBoxNorth;
    $country->bboxeast = (double) $countryinfo->bBoxEast;
    $country->bboxsouth = (double) $countryinfo->bBoxSouth;
    $capital = org_routamc_positioning_city_dba::get_by_name((string) $countryinfo->capital);
    if ($capital) {
        $country->capital = $capital->id;
    }
    $country->create();
    echo midcom_connection::get_error_string();
}