Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPUserUserXmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
23  function PKPUserUserXmlFilter($filterGroup) {
24  $this->setDisplayName('User XML user export');
25  parent::NativeExportFilter($filterGroup);
26  }
27 
28 
29  //
30  // Implement template methods from PersistableFilter
31  //
35  function getClassName() {
36  return 'lib.pkp.plugins.importexport.users.filter.PKPUserUserXmlFilter';
37  }
38 
39 
40  //
41  // Implement template methods from Filter
42  //
48  function &process(&$users) {
49  // Create the XML document
50  $doc = new DOMDocument('1.0');
51  $deployment = $this->getDeployment();
52 
53  $rootNode = $doc->createElementNS($deployment->getNamespace(), 'PKPUsers');
54  $this->addUserGroups($doc, $rootNode);
55 
56  // Multiple users; wrap in a <users> element
57  $usersNode = $doc->createElementNS($deployment->getNamespace(), 'users');
58  foreach ($users as $user) {
59  $usersNode->appendChild($this->createPKPUserNode($doc, $user));
60  }
61  $rootNode->appendChild($usersNode);
62  $doc->appendChild($rootNode);
63  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
64  $rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());
65 
66  return $doc;
67  }
68 
69  //
70  // PKPAuthor conversion functions
71  //
78  function createPKPUserNode($doc, $user) {
79  $deployment = $this->getDeployment();
80  $context = $deployment->getContext();
81 
82  // Create the user node
83  $userNode = $doc->createElementNS($deployment->getNamespace(), 'user');
84 
85  // Add metadata
86  $userNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'firstname', $user->getFirstName()));
87  $this->createOptionalNode($doc, $userNode, 'middlename', $user->getMiddleName());
88  $userNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'lastname', $user->getLastName()));
89 
90  if (is_array($user->getAffiliation(null))) {
91  $this->createLocalizedNodes($doc, $userNode, 'affiliation', $user->getAffiliation(null));
92  }
93 
94  $this->createOptionalNode($doc, $userNode, 'country', $user->getCountry());
95  $userNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'email', $user->getEmail()));
96  $this->createOptionalNode($doc, $userNode, 'url', $user->getUrl());
97  if (is_array($user->getBiography(null))) {
98  $this->createLocalizedNodes($doc, $userNode, 'biography', $user->getBiography(null));
99  }
100 
101  $userNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'username', $user->getUsername()));
102 
103  if (is_array($user->getGossip(null))) {
104  $this->createLocalizedNodes($doc, $userNode, 'gossip', $user->getGossip(null));
105  }
106  if (is_array($user->getSignature(null))) {
107  $this->createLocalizedNodes($doc, $userNode, 'signature', $user->getSignature(null));
108  }
109 
110  $passwordNode = $doc->createElementNS($deployment->getNamespace(), 'password');
111  $passwordNode->setAttribute('is_disabled', $user->getDisabled() ? 'true' : 'false');
112  $passwordNode->setAttribute('must_change', $user->getMustChangePassword() ? 'true' : 'false');
113  $passwordNode->setAttribute('encryption', Config::getVar('security', 'encryption'));
114  $passwordNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'value', $user->getPassword()));
115 
116  $userNode->appendChild($passwordNode);
117 
118  $this->createOptionalNode($doc, $userNode, 'salutation', $user->getSalutation());
119  $this->createOptionalNode($doc, $userNode, 'initials', $user->getInitials());
120  $this->createOptionalNode($doc, $userNode, 'suffix', $user->getSuffix());
121  $this->createOptionalNode($doc, $userNode, 'gender', $user->getGender());
122  $this->createOptionalNode($doc, $userNode, 'date_registered', $user->getDateRegistered());
123  $this->createOptionalNode($doc, $userNode, 'date_last_login', $user->getDateLastLogin());
124  $this->createOptionalNode($doc, $userNode, 'date_last_email', $user->getDateLastEmail());
125  $this->createOptionalNode($doc, $userNode, 'date_validated', $user->getDateValidated());
126  $this->createOptionalNode($doc, $userNode, 'inline_help', $user->getInlineHelp() ? 'true' : 'false');
127  $this->createOptionalNode($doc, $userNode, 'auth_id', $user->getAuthId());
128  $this->createOptionalNode($doc, $userNode, 'auth_string', $user->getAuthStr());
129  $this->createOptionalNode($doc, $userNode, 'fax', $user->getFax());
130  $this->createOptionalNode($doc, $userNode, 'phone', $user->getPhone());
131  $this->createOptionalNode($doc, $userNode, 'mailing_address', $user->getMailingAddress());
132  $this->createOptionalNode($doc, $userNode, 'billing_address', $user->getBillingAddress());
133  $this->createOptionalNode($doc, $userNode, 'locales', join(':',$user->getLocales()));
134  if ($user->getDisabled()) {
135  $this->createOptionalNode($doc, $userNode, 'disabled_reason', $user->getDisabledReason());
136  }
137 
138  $userGroupAssignmentDao = DAORegistry::getDAO('UserGroupAssignmentDAO');
139  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
140  $assignedGroups = $userGroupAssignmentDao->getByUserId($user->getId(), $context->getId());
141  while ($assignedGroup = $assignedGroups->next()) {
142  $userGroup = $userGroupDao->getById($assignedGroup->getUserGroupId());
143  if ($userGroup) {
144  $userNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'user_group_ref', $userGroup->getName($context->getPrimaryLocale())));
145  }
146  }
147 
148  // Add Reviewing Interests, if any.
149  import('lib.pkp.classes.user.InterestManager');
150  $interestManager = new InterestManager();
151  $interests = $interestManager->getInterestsString($user);
152  $this->createOptionalNode($doc, $userNode, 'review_interests', $interests);
153 
154  return $userNode;
155  }
156 
157  function addUserGroups($doc, $rootNode) {
158  $deployment = $this->getDeployment();
159  $context = $deployment->getContext();
160  $userGroupsNode = $doc->createElementNS($deployment->getNamespace(), 'user_groups');
161 
162  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
163  $userGroups = $userGroupDao->getByContextId($context->getId());
164  $filterDao = DAORegistry::getDAO('FilterDAO');
165  $userGroupExportFilters = $filterDao->getObjectsByGroup('usergroup=>user-xml');
166  assert(count($userGroupExportFilters)==1); // Assert only a single serialization filter
167  $exportFilter = array_shift($userGroupExportFilters);
168  $exportFilter->setDeployment($this->getDeployment());
169 
170  $userGroupsDoc = $exportFilter->execute($userGroups->toArray());
171  if ($userGroupsDoc->documentElement instanceof DOMElement) {
172  $clone = $doc->importNode($userGroupsDoc->documentElement, true);
173  $rootNode->appendChild($clone);
174  }
175  }
176 }
177 
178 ?>
static & getDAO($name, $dbconn=null)
setDisplayName($displayName)
Definition: Filter.inc.php:140
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
Handle user interest functions.
Base class that converts a set of users to a User XML document.
Base class that converts a DataObject to a Native XML document.
createLocalizedNodes($doc, $parentNode, $name, $values)
createOptionalNode($doc, $parentNode, $name, $value)