Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPAuthorNativeXmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
23  function PKPAuthorNativeXmlFilter($filterGroup) {
24  $this->setDisplayName('Native XML author 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.native.filter.PKPAuthorNativeXmlFilter';
37  }
38 
39 
40  //
41  // Implement template methods from Filter
42  //
48  function &process(&$authors) {
49  // Create the XML document
50  $doc = new DOMDocument('1.0');
51  $deployment = $this->getDeployment();
52 
53  // Multiple authors; wrap in a <authors> element
54  $rootNode = $doc->createElementNS($deployment->getNamespace(), 'authors');
55  foreach ($authors as $author) {
56  $rootNode->appendChild($this->createPKPAuthorNode($doc, $author));
57  }
58  $doc->appendChild($rootNode);
59  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
60  $rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());
61 
62  return $doc;
63  }
64 
65  //
66  // PKPAuthor conversion functions
67  //
74  function createPKPAuthorNode($doc, $author) {
75  $deployment = $this->getDeployment();
76  $context = $deployment->getContext();
77 
78  // Create the author node
79  $authorNode = $doc->createElementNS($deployment->getNamespace(), 'author');
80  if ($author->getPrimaryContact()) $authorNode->setAttribute('primary_contact', 'true');
81  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
82  $userGroup = $userGroupDao->getById($author->getUserGroupId());
83  assert($userGroup);
84  $authorNode->setAttribute('user_group_ref', $userGroup->getName($context->getPrimaryLocale()));
85 
86  // Add metadata
87  $authorNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'firstname', $author->getFirstName()));
88  $this->createOptionalNode($doc, $authorNode, 'middlename', $author->getMiddleName());
89  $authorNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'lastname', $author->getLastName()));
90 
91  $this->createLocalizedNodes($doc, $authorNode, 'affiliation', $author->getAffiliation(null));
92 
93  $this->createOptionalNode($doc, $authorNode, 'country', $author->getCountry());
94  $authorNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'email', $author->getEmail()));
95  $this->createOptionalNode($doc, $authorNode, 'url', $author->getUrl());
96 
97  $this->createLocalizedNodes($doc, $authorNode, 'biography', $author->getBiography(null));
98 
99  return $authorNode;
100  }
101 }
102 
103 ?>
static & getDAO($name, $dbconn=null)
setDisplayName($displayName)
Definition: Filter.inc.php:140
Base class that converts a set of authors to a Native XML document.
Base class that converts a DataObject to a Native XML document.
createLocalizedNodes($doc, $parentNode, $name, $values)
createOptionalNode($doc, $parentNode, $name, $value)