Пример #1
0
 /**
  * Imports info from a leap:spatial element as a user's address-related
  * profile fields
  */
 private static function get_addressfields(PluginImportLeap $importer, SimpleXMLElement $addressdata)
 {
     // TODO: this xpath doesn't respect the namespace prefix - we should
     // look it up from $importer->namespaces[NS_LEAP]
     $namespaces = $importer->get_namespaces();
     $ns = $namespaces[$importer->get_leap2a_namespace()];
     $addresslines = $addressdata->xpath($ns . ':addressline');
     // We look for 'town' and 'city' deliberately, Mahara has
     // separate fields for those. The rest get thrown in the
     // 'address' field
     $personaddress = '';
     $address = array();
     foreach ($addresslines as $addressline) {
         $maharaattributes = PluginImportLeap::get_attributes($addressline, PluginImportLeap::NS_MAHARA);
         if (isset($maharaattributes['artefacttype'])) {
             switch ($maharaattributes['artefacttype']) {
                 case 'address':
                 case 'town':
                 case 'city':
                     $address[$maharaattributes['artefacttype']] = (string) $addressline;
             }
         } else {
             $personaddress .= (string) $addressline . "\n";
         }
     }
     if ($personaddress != '') {
         $address['address'] = substr($personaddress, 0, -1);
     }
     // Now deal with country
     $country = $addressdata->xpath($ns . ':country');
     if (count($country) == 1) {
         $country = $country[0];
         $leapattributes = PluginImportLeap::get_attributes($country, $importer->get_leap2a_namespace());
         // Try using countrycode attribute first, but fall back to name if it's not present or
         // doesn't represent a country
         require_once 'country.php';
         $countrycode = null;
         if (isset($leapattributes['countrycode'])) {
             $countrycode = Country::iso3166_alpha3_to_iso3166_alpha2($leapattributes['countrycode']);
         }
         if (!$countrycode) {
             $countrycode = Country::countryname_to_iso3166_alpha2((string) $country);
         }
     }
     return array('address' => $address, 'country' => isset($countrycode) ? $countrycode : null);
 }