Ejemplo n.º 1
0
 public function memberToAtom($userID)
 {
     if (!is_int($userID)) {
         throw new Exception("userID must be an integer (was " . gettype($userID) . ")");
     }
     if (!$this->loaded) {
         $this->load();
     }
     $groupUserData = $this->getUserData($userID);
     if (!$groupUserData) {
         throw new Exception("User {$userID} is not a member of group {$this->id}", Z_ERROR_USER_NOT_GROUP_MEMBER);
     }
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' . '<entry xmlns="' . Zotero_Atom::$nsAtom . '" ' . 'xmlns:zapi="' . Zotero_Atom::$nsZoteroAPI . '" ' . 'xmlns:xfer="' . Zotero_Atom::$nsZoteroTransfer . '"/>');
     // If we know the username, provide that
     // TODO: get and cache full names
     if (Zotero_Users::exists($userID)) {
         $title = Zotero_Users::getUsername($userID);
     } else {
         $title = "User {$userID}";
     }
     $xml->title = $title;
     $author = $xml->addChild('author');
     $author->name = "Zotero";
     $author->uri = "http://zotero.org";
     $xml->id = Zotero_URI::getGroupUserURI($this, $userID);
     $xml->published = Zotero_Date::sqlToISO8601($groupUserData['joined']);
     $xml->updated = Zotero_Date::sqlToISO8601($groupUserData['lastUpdated']);
     $link = $xml->addChild("link");
     $link['rel'] = "self";
     $link['type'] = "application/atom+xml";
     $link['href'] = Zotero_API::getGroupUserURI($this, $userID);
     $link = $xml->addChild('link');
     $link['rel'] = 'alternate';
     $link['type'] = 'text/html';
     $link['href'] = Zotero_URI::getGroupUserURI($this, $userID);
     $xml->content['type'] = 'application/xml';
     $userXML = new SimpleXMLElement('<user xmlns="' . Zotero_Atom::$nsZoteroTransfer . '"/>');
     // This method of adding the element seems to be necessary to get the
     // namespace prefix to show up
     $fNode = dom_import_simplexml($xml->content);
     $subNode = dom_import_simplexml($userXML);
     $importedNode = $fNode->ownerDocument->importNode($subNode, true);
     $fNode->appendChild($importedNode);
     $xml->content->user['id'] = $userID;
     $xml->content->user['role'] = $groupUserData['role'];
     return $xml;
 }