Example #1
0
 public static function createFromXmlString($xmlStr)
 {
     OSM_ZLog::debug(__METHOD__, 'User details: ', $xmlStr);
     $x = new SimpleXMLElement($xmlStr);
     $userDetails = new OSM_Objects_UserDetails();
     $u = $x->xpath('/osm/user');
     if ($u == null || count($u) == 0) {
         throw new OSM_Exception('Error while loading user details');
     }
     $u = $u[0];
     $userDetails->_details['id'] = (string) $u['id'];
     $userDetails->_details['account_created'] = (string) $u['account_created'];
     $userDetails->_details['display_name'] = (string) $u['display_name'];
     $o = $u->xpath('description');
     $userDetails->_details['description'] = $o == null ? '' : (string) $o[0];
     $o = $u->xpath('contributor-terms');
     $userDetails->_details['terms']['pd'] = $o == null ? '' : (bool) $o[0]['pd'];
     $userDetails->_details['terms']['agreed'] = $o == null ? '' : (bool) $o[0]['agreed'];
     $o = $u->xpath('home');
     $userDetails->_details['home']['lat'] = $o == null ? '' : (string) $o[0]['lat'];
     $userDetails->_details['home']['lon'] = $o == null ? '' : (string) $o[0]['lon'];
     $o = $u->xpath('img');
     $userDetails->_details['img'] = $o == null ? '' : (string) $o[0]['href'];
     return $userDetails;
 }
Example #2
0
 /**
  *
  * @param string $type
  * @param string $ref
  * @param string $role 
  */
 public function __construct($type, $ref, $role = '')
 {
     OSM_ZLog::debug(__METHOD__, 'Create a Member ', $type, '=', $ref, ' role=', $role);
     if (empty($type)) {
         throw new OSM_Exception('Type could not be empty');
     }
     if (empty($ref)) {
         throw new OSM_Exception('Ref could not be empty');
     }
     $this->_type = $type;
     $this->_ref = $ref;
     $this->_role = $role;
 }
Example #3
0
 /**
  *
  * @param array $options 
  * @return Log The new Log instance.
  */
 public static function configure(array $options)
 {
     if (is_null($options)) {
         throw new OSM_Exception('Invalid call of ' . __METHOD__);
     }
     foreach ($options as $k => $v) {
         if (!array_key_exists($k, self::$_options)) {
             throw new OSM_Exception('Unknow Log option "' . $k . '"');
         }
         self::$_options[$k] = $v;
     }
     self::$_log = null;
     self::_getLog();
 }
Example #4
0
 public static function fromXmlObj(SimpleXMLElement $xmlObj)
 {
     $relation = new OSM_Objects_Relation();
     $processedElements = $relation->_fromXmlObj($xmlObj);
     foreach ($xmlObj->children() as $child) {
         if (in_array($child->getName(), $processedElements)) {
             continue;
         }
         OSM_ZLog::debug(__METHOD__, 'Found child: ', $child->getName());
         switch ($child->getName()) {
             case self::OBJTYPE_MEMBER:
                 $member = OSM_Objects_Member::fromXmlObj($child);
                 $relation->addMember($member);
                 break;
             default:
                 throw new OSM_Exception('Object "' . $xmlObj->getName() . '" is not supported in relation');
         }
     }
     $relation->setDirty(false);
     return $relation;
 }
Example #5
0
 /**
  * Set a user preference value.
  *
  * @param string $key
  * @param string $value
  */
 public function setUserPreference($key, $value)
 {
     if ($this->_authProvider == null) {
         throw new OSM_Exception('Must be authenticated');
     }
     $result = $this->_httpApi('/user/preferences/' . rawurlencode(utf8_encode($key)), rawurlencode(utf8_encode($value)), 'PUT');
     OSM_ZLog::debug(__METHOD__, $result);
 }
Example #6
0
 /**
  *
  * @param SimpleXMLElement $xmlObj
  * @return array List of processed children types to avoid reprocessing in sub class.
  */
 protected function _fromXmlObj(SimpleXMLElement $xmlObj)
 {
     foreach ($xmlObj->attributes() as $k => $v) {
         $this->_attrs[(string) $k] = (string) $v;
     }
     if (!array_key_exists('id', $this->_attrs)) {
         throw new OSM_Exception(__CLASS__ . ' should must a "id" attribute');
     }
     OSM_ZLog::debug(__METHOD__, 'Got a ' . __CLASS__ . ' with id=', $this->getId());
     foreach ($xmlObj->children() as $child) {
         switch ($child->getName()) {
             case OSM_Objects_Object::OBJTYPE_TAG:
                 OSM_ZLog::debug(__METHOD__, 'Found child: ', OSM_Objects_Object::OBJTYPE_TAG);
                 $tag = OSM_Objects_Tag::fromXmlObj($child);
                 $this->_tags[$tag->getKey()] = $tag;
                 break;
         }
     }
     return array(OSM_Objects_Object::OBJTYPE_TAG);
 }