Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
NativeXmlSubmissionFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeImportFilter');
17 
23  function NativeXmlSubmissionFilter($filterGroup) {
24  $this->setDisplayName('Native XML submission import');
25  parent::NativeImportFilter($filterGroup);
26  }
27 
28 
29  //
30  // Implement template methods from PersistableFilter
31  //
35  function getClassName() {
36  return 'lib.pkp.plugins.importexport.native.filter.NativeXmlSubmissionFilter';
37  }
38 
39 
40  //
41  // Implement template methods from NativeImportFilter
42  //
47  function getPluralElementName() {
48  $deployment = $this->getDeployment();
49  return $deployment->getSubmissionsNodeName();
50  }
51 
57  $deployment = $this->getDeployment();
58  return $deployment->getSubmissionNodeName();
59  }
60 
65  function handleElement($node) {
66  $deployment = $this->getDeployment();
67  $context = $deployment->getContext();
68  $user = $deployment->getUser();
69 
70  // Create and insert the submission (ID needed for other entities)
71  $submissionDao = Application::getSubmissionDAO();
72  $submission = $submissionDao->newDataObject();
73  $submission->setContextId($context->getId());
74  $submission->setUserId($user->getId());
75  $submission->setStatus(STATUS_QUEUED);
76  $submission->setLocale($node->getAttribute('locale'));
77  $submission->setSubmissionProgress(0);
78  $submissionDao->insertObject($submission);
79  $deployment->setSubmission($submission);
80 
81  // Handle any additional attributes etc.
82  $submission = $this->populateObject($submission, $node);
83 
84  for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) {
85  if (is_a($n, 'DOMElement')) {
86  $this->handleChildElement($n, $submission);
87  }
88  }
89  $submissionDao->updateObject($submission); // Persist setters
90  return $submission;
91  }
92 
99  function populateObject($submission, $node) {
100  $submissionDao = Application::getSubmissionDAO();
101  $submissionDao->updateObject($submission);
102  // If the date_published was set, add a published submission
103  if ($datePublished = $node->getAttribute('date_published')) {
104  $publishedSubmissionDao = $this->getPublishedSubmissionDAO();
105  $publishedSubmission = $publishedSubmissionDao->newDataObject();
106  $publishedSubmission->setId($submission->getId());
107  $publishedSubmission->setDatePublished(strtotime($datePublished));
108  $publishedSubmissionDao->insertObject($publishedSubmission);
109  // Reload from DB now that some fields may have changed
110  $submission = $submissionDao->getById($submission->getId());
111  }
112  return $submission;
113  }
114 
120  function handleChildElement($n, $submission) {
121  $setterMappings = $this->_getLocalizedSubmissionSetterMappings();
122  if (isset($setterMappings[$n->tagName])) {
123  // If applicable, call a setter for localized content
124  $setterFunction = $setterMappings[$n->tagName];
125  list($locale, $value) = $this->parseLocalizedContent($n);
126  $submission->$setterFunction($value, $locale);
127  } else switch ($n->tagName) {
128  // Otherwise, delegate to specific parsing code
129  case 'id':
130  $this->parseIdentifier($n, $submission);
131  break;
132  case 'authors':
133  $this->parseAuthors($n, $submission);
134  break;
135  case 'submission_file':
136  $this->parseSubmissionFile($n, $submission);
137  break;
138  case 'comments_to_editor':
139  $submission->setCommentsToEditor($n->textContent);
140  break;
141  default:
142  fatalError('Unknown element ' . $n->tagName);
143  }
144  }
145 
146  //
147  // Element parsing
148  //
154  function parseIdentifier($element, $submission) {
155  switch ($element->getAttribute('type')) {
156  case 'internal':
157  // Currently internal IDs are discarded; new IDs
158  // are generated and assigned.
159  break;
160  case 'public':
161  $submission->setStoredPubId('publisher-id', $element->textContent);
162  break;
163  default:
164  $submission->setStoredPubId($element->getAttribute('type'), $element->textContent);
165  }
166  }
167 
173  function parseAuthors($node, $submission) {
174  for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) {
175  if (is_a($n, 'DOMElement')) {
176  assert($n->tagName == 'author');
177  $this->parseAuthor($n, $submission);
178  }
179  }
180  }
181 
187  function parseAuthor($n, $submission) {
188  $filterDao = DAORegistry::getDAO('FilterDAO');
189  $importFilters = $filterDao->getObjectsByGroup('native-xml=>author');
190  assert(count($importFilters)==1); // Assert only a single unserialization filter
191  $importFilter = array_shift($importFilters);
192  $importFilter->setDeployment($this->getDeployment());
193  $authorDoc = new DOMDocument();
194  $authorDoc->appendChild($authorDoc->importNode($n, true));
195  return $importFilter->execute($authorDoc);
196  }
197 
203  function parseSubmissionFile($n, $submission) {
204  $importFilter = $this->getImportFilter($n->tagName);
205  assert($importFilter); // There should be a filter
206 
207  $importFilter->setDeployment($this->getDeployment());
208  $submissionFileDoc = new DOMDocument();
209  $submissionFileDoc->appendChild($submissionFileDoc->importNode($n, true));
210  return $importFilter->execute($submissionFileDoc);
211  }
212 
213  //
214  // Helper functions
215  //
221  return array(
222  'title' => 'setTitle',
223  'prefix' => 'setPrefix',
224  'subtitle' => 'setSubtitle',
225  'abstract' => 'setAbstract',
226  'subject_class' => 'setSubjectClass',
227  'coverage_geo' => 'setCoverageGeo',
228  'coverage_chron' => 'setCoverageChron',
229  'coverage_sample' => 'setCoverageSample',
230  'source' => 'setSource',
231  'rights' => 'setRights',
232  );
233  }
234 
240  assert(false); // Subclasses must override
241  }
242 
248  return 'publication-format=>native-xml';
249  }
250 
256  function getImportFilter($elementName) {
257  assert(false); // Subclasses should override
258  }
259 }
260 
261 ?>
static & getDAO($name, $dbconn=null)
setDisplayName($displayName)
Definition: Filter.inc.php:140
static getSubmissionDAO()
Base class that converts a Native XML document to a set of submissions.
Base class that converts a Native XML document to a DataObject.