Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
NativeXmlPKPAuthorFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeImportFilter');
17 
23  function NativeXmlPKPAuthorFilter($filterGroup) {
24  $this->setDisplayName('Native XML author import');
25  parent::NativeImportFilter($filterGroup);
26  }
27 
28  //
29  // Implement template methods from NativeImportFilter
30  //
35  function getPluralElementName() {
36  return 'authors';
37  }
38 
44  return 'author';
45  }
46 
47  //
48  // Implement template methods from PersistableFilter
49  //
53  function getClassName() {
54  return 'lib.pkp.plugins.importexport.native.filter.NativeXmlPKPAuthorFilter';
55  }
56 
57 
63  function handleElement($node) {
64  $deployment = $this->getDeployment();
65  $context = $deployment->getContext();
66  $submission = $deployment->getSubmission();
67  assert(is_a($submission, 'Submission'));
68 
69  // Create the data object
70  $authorDao = DAORegistry::getDAO('AuthorDAO');
71  $author = $authorDao->newDataObject();
72  $author->setSubmissionId($submission->getId());
73  if ($node->getAttribute('primary_contact')) $author->setPrimaryContact(true);
74 
75  // Identify the user group by name
76  $userGroupName = $node->getAttribute('user_group_ref');
77  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
78  $userGroups = $userGroupDao->getByContextId($context->getId());
79  while ($userGroup = $userGroups->next()) {
80  if (in_array($userGroupName, $userGroup->getName(null))) {
81  // Found a candidate; stash it.
82  $author->setUserGroupId($userGroup->getId());
83  }
84  }
85  if (!$author->getUserGroupId()) {
86  fatalError("Could not identify a matching user group \"$userGroupName\".");
87  }
88 
89  // Handle metadata in subelements
90  for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) if (is_a($n, 'DOMElement')) switch($n->tagName) {
91  case 'firstname': $author->setFirstName($n->textContent); break;
92  case 'middlename': $author->setMiddleName($n->textContent); break;
93  case 'lastname': $author->setLastName($n->textContent); break;
94  case 'affiliation': $author->setAffiliation($n->textContent, $n->getAttribute('locale')); break;
95  case 'country': $author->setCountry($n->textContent); break;
96  case 'email': $author->setEmail($n->textContent); break;
97  case 'url': $author->setUrl($n->textContent); break;
98  case 'biography': $author->setBiography($n->textContent, $n->getAttribute('locale')); break;
99  }
100 
101  $authorDao->insertObject($author);
102  return $author;
103  }
104 }
105 
106 ?>
static & getDAO($name, $dbconn=null)
Base class that converts a Native XML document to a set of authors.
setDisplayName($displayName)
Definition: Filter.inc.php:140
Base class that converts a Native XML document to a DataObject.