Open Monograph Press  3.3.0
ChapterNativeXmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
23  function __construct($filterGroup) {
24  $this->setDisplayName('Native XML chapter export');
25  parent::__construct($filterGroup);
26  }
27 
28 
29  //
30  // Implement template methods from PersistableFilter
31  //
35  function getClassName() {
36  return 'plugins.importexport.native.filter.ChapterNativeXmlFilter';
37  }
38 
39 
40  //
41  // Implement template methods from Filter
42  //
48  function &process(&$chapters) {
49  // Create the XML document
50  $doc = new DOMDocument('1.0');
51  $doc->preserveWhiteSpace = false;
52  $doc->formatOutput = true;
53  $deployment = $this->getDeployment();
54 
55  // Multiple authors; wrap in a <authors> element
56  $rootNode = $doc->createElementNS($deployment->getNamespace(), 'chapters');
57  foreach ($chapters as $chapter) {
58  $rootNode->appendChild($this->createChapterNode($doc, $chapter));
59  }
60  $doc->appendChild($rootNode);
61  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
62  $rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());
63 
64  return $doc;
65  }
66 
67  //
68  // PKPAuthor conversion functions
69  //
76  function createChapterNode($doc, $chapter) {
77  $deployment = $this->getDeployment();
78  $context = $deployment->getContext();
79 
80  $publication = $deployment->getPublication();
81 
82  // Create the entity node
83  $entityNode = $doc->createElementNS($deployment->getNamespace(), 'chapter');
84  $entityNode->setAttribute('seq', $chapter->getSequence());
85  $entityNode->setAttribute('id', $chapter->getId());
86 
87  // Add metadata
88  $this->createLocalizedNodes($doc, $entityNode, 'title', $chapter->getData('title'));
89  $this->createLocalizedNodes($doc, $entityNode, 'abstract', $chapter->getData('abstract'));
90  $this->createLocalizedNodes($doc, $entityNode, 'subtitle', $chapter->getData('subtitle'));
91 
92  $entityNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'pages', $chapter->getData('pages')));
93 
94  // Add authors
95  $chapterAuthorDao = DAORegistry::getDAO('ChapterAuthorDAO');
96  $chapterAuthors = $chapterAuthorDao->getAuthors($chapter->getData('publicationId'), $chapter->getId())->toArray();
97 
98  foreach ($chapterAuthors as $chapterAuthor) {
99  $entityNode->appendChild($this->createChapterAuthorNode($doc, $chapterAuthor));
100  }
101 
102  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
103  $submissionFiles = $submissionFileDao->getBySubmissionId($publication->getData('submissionId'));
104  foreach ($submissionFiles as $submissionFile) {
105  if ($submissionFile->getData('chapterId') == $chapter->getId()) {
106  $referenceFileNode = $doc->createElementNS($deployment->getNamespace(), 'submission_file_ref');
107  $referenceFileNode->setAttribute('id', $submissionFile->getId());
108  $referenceFileNode->setAttribute('revision', $submissionFile->getRevision());
109  $entityNode->appendChild($referenceFileNode);
110  }
111  }
112 
113  return $entityNode;
114  }
115 
122  function createChapterAuthorNode($doc, $chapterAuthor) {
123  $deployment = $this->getDeployment();
124  $context = $deployment->getContext();
125 
126  // Create the entity node
127  $entityNode = $doc->createElementNS($deployment->getNamespace(), 'chapterAuthor');
128  $entityNode->setAttribute('author_id', $chapterAuthor->getId());
129  $entityNode->setAttribute('primary_contact', $chapterAuthor->getData('primaryContact'));
130  $entityNode->setAttribute('seq', $chapterAuthor->getData('seq'));
131 
132  return $entityNode;
133  }
134 }
135 
136 
ChapterNativeXmlFilter\createChapterAuthorNode
createChapterAuthorNode($doc, $chapterAuthor)
Definition: ChapterNativeXmlFilter.inc.php:122
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
ChapterNativeXmlFilter\createChapterNode
createChapterNode($doc, $chapter)
Definition: ChapterNativeXmlFilter.inc.php:76
NativeImportExportFilter\getDeployment
getDeployment()
Definition: NativeImportExportFilter.inc.php:49
NativeExportFilter\createLocalizedNodes
createLocalizedNodes($doc, $parentNode, $name, $values)
Definition: NativeExportFilter.inc.php:87
NativeExportFilter
Base class that converts a DataObject to a Native XML document.
Definition: NativeExportFilter.inc.php:18
ChapterNativeXmlFilter\__construct
__construct($filterGroup)
Definition: ChapterNativeXmlFilter.inc.php:23
ChapterNativeXmlFilter
Base class that converts a set of authors to a Native XML document.
Definition: ChapterNativeXmlFilter.inc.php:18
ChapterNativeXmlFilter\process
& process(&$chapters)
Definition: ChapterNativeXmlFilter.inc.php:48
ChapterNativeXmlFilter\getClassName
getClassName()
Definition: ChapterNativeXmlFilter.inc.php:35
Filter\setDisplayName
setDisplayName($displayName)
Definition: Filter.inc.php:140