Open Monograph Press  3.3.0
NativeXmlChapterFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeImportFilter');
17 
23  function __construct($filterGroup) {
24  $this->setDisplayName('Native XML Chapter import');
25  parent::__construct($filterGroup);
26  }
27 
28  //
29  // Implement template methods from NativeImportFilter
30  //
35  function getPluralElementName() {
36  return 'chapters';
37  }
38 
44  return 'chapter';
45  }
46 
47  //
48  // Implement template methods from PersistableFilter
49  //
53  function getClassName() {
54  return 'plugins.importexport.native.filter.NativeXmlChapterFilter';
55  }
56 
57 
63  function handleElement($node) {
64  $deployment = $this->getDeployment();
65  $context = $deployment->getContext();
66 
67  $publication = $deployment->getPublication();
68  assert(is_a($publication, 'Publication'));
69 
70  // Create the data object
71  $chapterDao = DAORegistry::getDAO('ChapterDAO');
73  $chapter = $chapterDao->newDataObject();
74 
75  $chapter->setData('publicationId', $publication->getId());
76  $chapter->setSequence($node->getAttribute('seq'));
77 
78  $chapterId = $chapterDao->insertChapter($chapter);
79  $chapter->setData('id', $chapterId);
80 
81  // Handle metadata in subelements
82  for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) if (is_a($n, 'DOMElement')) switch($n->tagName) {
83  case 'title':
84  $locale = $n->getAttribute('locale');
85  if (empty($locale)) $locale = $context->getLocale();
86  $chapter->setData('title', $n->textContent, $locale);
87  break;
88  case 'abstract':
89  $locale = $n->getAttribute('locale');
90  if (empty($locale)) $locale = $context->getLocale();
91  $chapter->setData('abstract', $n->textContent, $locale);
92  break;
93  case 'subtitle':
94  $locale = $n->getAttribute('locale');
95  if (empty($locale)) $locale = $context->getLocale();
96  $chapter->setData('subtitle', $n->textContent, $locale);
97  break;
98  case 'pages':
99  $chapter->setData('pages', $n->textContent);
100  break;
101  case 'chapterAuthor':
102  $this->parseAuthor($n, $chapter);
103  break;
104  case 'submission_file_ref':
105  $this->parseSubmissionFileRef($n, $chapter);
106  break;
107  }
108 
109  $chapterDao->updateObject($chapter);
110 
111  return $chapter;
112  }
113 
119  function parseAuthor($n, $chapter) {
120  $deployment = $this->getDeployment();
121 
122  $chapterAuthorDao = DAORegistry::getDAO('ChapterAuthorDAO');
124  $authorId = $deployment->getAuthorDBId($n->getAttribute('author_id'));
125  $primaryContact = $n->getAttribute('primary_contact');
126  $seq = $n->getAttribute('seq');
127 
128  $chapterAuthorDao->insertChapterAuthor($authorId, $chapter->getId(), $primaryContact, $seq);
129  }
130 
136  function parseSubmissionFileRef($n, $chapter) {
137  $deployment = $this->getDeployment();
138  $context = $deployment->getContext();
139 
140  $publication = $deployment->getPublication();
141 
142  $fileId = $n->getAttribute('id');
143  $fileRevision = $n->getAttribute('revision');
144 
145  $sourceFileId = $deployment->getFileDBId($fileId, $fileRevision);
146  if ($sourceFileId) {
147  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
148  $submissionFile = $submissionFileDao->getRevision($sourceFileId, $fileRevision);
149 
150  if ($submissionFile) {
151  $submissionFile->setData('chapterId', $chapter->getId());
152 
153  $submissionFileDao->updateObject($submissionFile);
154  }
155  }
156  }
157 }
158 
159 
NativeXmlChapterFilter\parseSubmissionFileRef
parseSubmissionFileRef($n, $chapter)
Definition: NativeXmlChapterFilter.inc.php:136
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
NativeImportExportFilter\getDeployment
getDeployment()
Definition: NativeImportExportFilter.inc.php:49
NativeXmlChapterFilter\parseAuthor
parseAuthor($n, $chapter)
Definition: NativeXmlChapterFilter.inc.php:119
NativeXmlChapterFilter\handleElement
handleElement($node)
Definition: NativeXmlChapterFilter.inc.php:63
NativeImportFilter
Base class that converts a Native XML document to a DataObject.
Definition: NativeImportFilter.inc.php:18
NativeXmlChapterFilter\getSingularElementName
getSingularElementName()
Definition: NativeXmlChapterFilter.inc.php:43
NativeXmlChapterFilter\getClassName
getClassName()
Definition: NativeXmlChapterFilter.inc.php:53
NativeXmlChapterFilter\getPluralElementName
getPluralElementName()
Definition: NativeXmlChapterFilter.inc.php:35
Filter\setDisplayName
setDisplayName($displayName)
Definition: Filter.inc.php:140
NativeXmlChapterFilter
Base class that converts a Native XML document to a set of authors.
Definition: NativeXmlChapterFilter.inc.php:18
NativeXmlChapterFilter\__construct
__construct($filterGroup)
Definition: NativeXmlChapterFilter.inc.php:23