-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetadataExportHandler.inc.php
149 lines (122 loc) · 3.79 KB
/
MetadataExportHandler.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* @file plugins/generic/metadataExport/MetadataExportHandler.inc.php
*
* Copyright (c) 2013-2015 Simon Fraser University Library
* Copyright (c) 2003-2015 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @package plugins.generic.metadataExport
* @class MetadataExportHandler
*/
import('classes.handler.Handler');
class MetadataExportHandler extends Handler {
/* @var journal object Current journal */
var $journal;
/* @var array Articles of the exported issue/journal */
var $articles;
/* @var publishedArticleDAO object */
var $publishedArticleDao;
/* @var issueDAO object */
var $issueDao;
/* @var array Plugins of the metadataexport category */
var $metadataExportPlugins;
/* @var string Function defining the scope of the export (article/issue/journal) */
var $exportFunction;
/* @var string Name of the current export plugin */
var $exportPluginName;
/* @var metadataExportPlugin object Current export plugin object */
var $exportPlugin;
/* @var int Id of the current article/issue */
var $elementId;
/* @var string URL of the previously visited page */
var $referrer;
/**
* Call the respective export function (for article, issue or journal).
* @param $args Array
*/
function export($args) {
$scope = Request::getUserVar('exportScope');
$this->exportPluginName = Request::getUserVar('exportPluginName');
$this->elementId = Request::getUserVar('elementId');
$this->referrer = Request::getUserVar('referrer');
$this->metadataExportPlugins = PluginRegistry::loadCategory('generic/metadataExport/metadataExportFormats');
$this->exportPlugin = $this->metadataExportPlugins[$this->exportPluginName];
$this->journal = Request::getJournal();
$this->publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
$this->issueDao = DAORegistry::getDAO('IssueDAO');
switch ($scope) {
case 'exportArticle':
$this->_exportArticle();
break;
case 'exportIssue':
$this->_exportIssue();
break;
case 'exportJournal':
$this->_exportJournal();
break;
default:
assert(false);
}
}
/**
* Export the current article
*/
function _exportArticle() {
$journalId = $this->journal->getId();
$articleId = $this->elementId;
$article = $this->publishedArticleDao->getPublishedArticleByArticleId($articleId, $journalId);
if ($article) {
$this->articles = array($article);
$this->_createFile();
} else {
Request::redirectUrl($this->referrer);
}
}
/**
* Export the current issue
*/
function _exportIssue() {
$journalId = $this->journal->getId();
$issueId = $this->elementId;
$issue = $this->issueDao->getIssueById($issueId, $journalId);
if ($issue->getPublished()) {
$this->articles = $this->publishedArticleDao->getPublishedArticles($issueId);
$this->_createFile();
} else {
Request::redirectUrl($this->referrer);
}
}
/**
* Export the current journal
*/
function _exportJournal() {
$journalId = $this->journal->getId();
$articleIterator = $this->publishedArticleDao->getPublishedArticlesByJournalId($journalId);
$this->articles = array();
while ($article = $articleIterator->next()) {
$this->articles[] = $article;
}
unset($articleIterator);
$this->_createFile();
}
/**
* Create text or xml file
*/
function _createFile() {
if ($this->exportPlugin->isXML()) {
$this->exportPlugin->createXmlFile($this->journal, $this->articles);
} else {
$this->exportPlugin->createTextFile($this->journal, $this->articles);
}
}
/**
* Display plugin info page
*/
function info() {
$metadataExportPlugin = PluginRegistry::getPlugin('generic', METADATA_EXPORT_PLUGIN_NAME);
$templateMgr = TemplateManager::getManager();
$templateMgr->display($metadataExportPlugin->getTemplatePath() . '/info.tpl');
}
}
?>