Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
SubmissionFileNativeXmlFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeExportFilter');
17 
23  function SubmissionFileNativeXmlFilter($filterGroup) {
24  $this->setDisplayName('Native XML submissionFile 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.SubmissionFileNativeXmlFilter';
37  }
38 
39 
40  //
41  // Implement template methods from Filter
42  //
48  function &process(&$submissionFile) {
49  // Create the XML document
50  $doc = new DOMDocument('1.0');
51  $deployment = $this->getDeployment();
52  $rootNode = $this->createSubmissionFileNode($doc, $submissionFile);
53  $doc->appendChild($rootNode);
54  $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
55  $rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());
56 
57  return $doc;
58  }
59 
60  //
61  // SubmissionFile conversion functions
62  //
69  function createSubmissionFileNode($doc, $submissionFile) {
70  $deployment = $this->getDeployment();
71  $context = $deployment->getContext();
72 
73  // Create the submission_file node and set metadata
74  $submissionFileNode = $doc->createElementNS($deployment->getNamespace(), $this->getSubmissionFileElementName());
75 
76  $stageToName = array_flip($deployment->getStageNameStageIdMapping());
77  $submissionFileNode->setAttribute('stage', $stageToName[$submissionFile->getFileStage()]);
78  $submissionFileNode->setAttribute('id', $submissionFile->getFileId());
79 
80  // Create the revision node and set metadata
81  $revisionNode = $doc->createElementNS($deployment->getNamespace(), 'revision');
82  $revisionNode->setAttribute('number', $submissionFile->getRevision());
83  if ($sourceFileId = $submissionFile->getSourceFileId()) {
84  $revisionNode->setAttribute('source', $sourceFileId . '-' . $submissionFile->getSourceRevision());
85  }
86 
87  $genreDao = DAORegistry::getDAO('GenreDAO');
88  $genre = $genreDao->getById($submissionFile->getGenreId());
89  assert($genre);
90  $revisionNode->setAttribute('genre', $genre->getName($context->getPrimaryLocale()));
91 
92  $revisionNode->setAttribute('filename', $submissionFile->getOriginalFileName());
93  $revisionNode->setAttribute('viewable', $submissionFile->getViewable()?'true':'false');
94  $revisionNode->setAttribute('date_uploaded', strftime('%F', strtotime($submissionFile->getDateUploaded())));
95  $revisionNode->setAttribute('date_modified', strftime('%F', strtotime($submissionFile->getDateModified())));
96  if ($submissionFile->getDirectSalesPrice() !== null) {
97  $revisionNode->setAttribute('direct_sales_price', $submissionFile->getDirectSalesPrice());
98  }
99  $revisionNode->setAttribute('filesize', $submissionFile->getFileSize());
100  $revisionNode->setAttribute('filetype', $submissionFile->getFileType());
101 
102  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
103  $userGroup = $userGroupDao->getById($submissionFile->getUserGroupId());
104  assert($userGroup);
105  $revisionNode->setAttribute('user_group_ref', $userGroup->getName($context->getPrimaryLocale()));
106 
107  $userDao = DAORegistry::getDAO('UserDAO');
108  $uploaderUser = $userDao->getById($submissionFile->getUploaderUserId());
109  assert($uploaderUser);
110  $revisionNode->setAttribute('uploader', $uploaderUser->getUsername());
111  $this->createLocalizedNodes($doc, $revisionNode, 'name', $submissionFile->getName(null));
112 
113  $submissionFileNode->appendChild($revisionNode);
114 
115  // Embed the file contents
116  $embedNode = $doc->createElementNS($deployment->getNamespace(), 'embed', base64_encode(file_get_contents($submissionFile->getFilePath())));
117  $embedNode->setAttribute('encoding', 'base64');
118  $revisionNode->appendChild($embedNode);
119 
120  return $submissionFileNode;
121  }
122 
127  return 'submission_file';
128  }
129 }
130 
131 ?>
static & getDAO($name, $dbconn=null)
Base class that converts a submissionFile to a Native XML document.
setDisplayName($displayName)
Definition: Filter.inc.php:140
Base class that converts a DataObject to a Native XML document.
createLocalizedNodes($doc, $parentNode, $name, $values)