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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
<?php
/**
* @file ArticleReportPlugin.inc.php
*
* Copyright (c) 2003-2009 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ArticleReportPlugin
* @ingroup plugins_reports_article
*
* @brief Article report plugin
*/
// $Id$
import('classes.plugins.ReportPlugin');
class ArticleReportPlugin extends ReportPlugin {
/**
* Called as a plugin is registered to the registry
* @param $category String Name of category plugin was registered to
* @return boolean True if plugin initialized successfully; if false,
* the plugin will not be registered.
*/
function register($category, $path) {
$success = parent::register($category, $path);
if ($success) {
$this->import('ArticleReportDAO');
$articleReportDAO =& new ArticleReportDAO();
DAORegistry::registerDAO('ArticleReportDAO', $articleReportDAO);
}
$this->addLocaleData();
return $success;
}
/**
* Get the name of this plugin. The name must be unique within
* its category.
* @return String name of plugin
*/
function getName() {
return 'ArticleReportPlugin';
}
function getDisplayName() {
return Locale::translate('plugins.reports.articles.displayName');
}
function getDescription() {
return Locale::translate('plugins.reports.articles.description');
}
function display(&$args) {
$journal =& Request::getJournal();
header('content-type: text/comma-separated-values');
header('content-disposition: attachment; filename=report.csv');
$articleReportDao =& DAORegistry::getDAO('ArticleReportDAO');
list($articlesIterator, $authorsIterator, $decisionsIteratorsArray) = $articleReportDao->getArticleReport($journal->getJournalId());
$maxAuthors = $this->getMaxAuthorCount($authorsIterator);
$decisions = array();
foreach ($decisionsIteratorsArray as $decisionsIterator) {
while ($row =& $decisionsIterator->next()) {
$decisions[$row['article_id']] = $row['decision'];
}
}
import('classes.article.Article');
$decisionMessages = array(
SUBMISSION_EDITOR_DECISION_ACCEPT => Locale::translate('editor.article.decision.accept'),
SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS => Locale::translate('editor.article.decision.pendingRevisions'),
SUBMISSION_EDITOR_DECISION_RESUBMIT => Locale::translate('editor.article.decision.resubmit'),
SUBMISSION_EDITOR_DECISION_DECLINE => Locale::translate('editor.article.decision.decline'),
null => Locale::translate('plugins.reports.articles.nodecision')
);
$columns = array(
'article_id' => Locale::translate('article.submissionId'),
'title' => Locale::translate('article.title'),
'abstract' => Locale::translate('article.abstract')
);
for ($a = 1; $a <= $maxAuthors; $a++) {
$columns = array_merge($columns, array(
'fname' . $a => Locale::translate('user.firstName') . " (" . Locale::translate('user.role.author') . " $a)",
'mname' . $a => Locale::translate('user.middleName') . " (" . Locale::translate('user.role.author') . " $a)",
'lname' . $a => Locale::translate('user.lastName') . " (" . Locale::translate('user.role.author') . " $a)",
'country' . $a => Locale::translate('common.country') . " (" . Locale::translate('user.role.author') . " $a)",
'affiliation' . $a => Locale::translate('user.affiliation') . " (" . Locale::translate('user.role.author') . " $a)",
'email' . $a => Locale::translate('user.email') . " (" . Locale::translate('user.role.author') . " $a)",
'url' . $a => Locale::translate('user.url') . " (" . Locale::translate('user.role.author') . " $a)",
'biography' . $a => Locale::translate('user.biography') . " (" . Locale::translate('user.role.author') . " $a)"
));
}
$columns = array_merge($columns, array(
'section_title' => Locale::translate('section.title'),
'language' => Locale::translate('common.language'),
'editor_decision' => Locale::translate('submission.editorDecision'),
'status' => Locale::translate('common.status')
));
$fp = fopen('php://output', 'wt');
String::fputcsv($fp, array_values($columns));
import('article.Article'); // Bring in getStatusMap function
$statusMap =& Article::getStatusMap();
$authorIndex = 0;
while ($row =& $articlesIterator->next()) {
$authors = $this->mergeAuthors($authorsIterator[$row['article_id']]->toArray());
foreach ($columns as $index => $junk) {
if ($index == 'editor_decision') {
if (isset($decisions[$row['article_id']])) {
$columns[$index] = $decisionMessages[$decisions[$row['article_id']]];
} else {
$columns[$index] = $decisionMessages[null];
}
} elseif ($index == 'status') {
$columns[$index] = Locale::translate($statusMap[$row[$index]]);
} elseif ($index == 'abstract') {
$columns[$index] = html_entity_decode(strip_tags($row[$index]));
} elseif (strstr($index, 'biography') !== false) {
// "Convert" HTML to text for export
$columns[$index] = isset($authors[$index])?html_entity_decode(strip_tags($authors[$index])):'';
} else {
if (isset($row[$index])) {
$columns[$index] = $row[$index];
} else if (isset($authors[$index])) {
$columns[$index] = $authors[$index];
} else $columns[$index] = '';
}
}
String::fputcsv($fp, $columns);
unset($row);
$authorIndex++;
}
fclose($fp);
}
/**
* Get the highest author count for any article (to determine how many columns to set)
* @param $authorsIterator DBRowIterator
* @return int
*/
function getMaxAuthorCount($authorsIterator) {
$maxAuthors = 0;
foreach ($authorsIterator as $authorIterator) {
$maxAuthors = $authorIterator->getCount() > $maxAuthors ? $authorIterator->getCount() : $maxAuthors;
}
return $maxAuthors;
}
/**
* Flatten an array of author information into one array and append author sequence to each key
* @param $authors array
* @return array
*/
function mergeAuthors($authors) {
$returner = array();
$seq = 0;
foreach($authors as $author) {
$seq++;
$returner['fname' . $seq] = isset($author['fname']) ? $author['fname'] : '';
$returner['mname' . $seq] = isset($author['mname']) ? $author['mname'] : '';
$returner['lname' . $seq] = isset($author['lname']) ? $author['lname'] : '';
$returner['email' . $seq] = isset($author['email']) ? $author['email'] : '';
$returner['affiliation'] = isset($author['affiliation']) ? $author['affiliation'] : '';
$returner['country' . $seq] = isset($author['country']) ? $author['country'] : '';
$returner['url' . $seq] = isset($author['url']) ? $author['url'] : '';
$returner['biography' . $seq] = isset($author['biography']) ? $author['biography'] : '';
}
return $returner;
}
}
?>
|