-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubmissionsCitationsReportPlugin.php
69 lines (56 loc) · 2.1 KB
/
SubmissionsCitationsReportPlugin.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
<?php
namespace APP\plugins\reports\submissionsCitationsReport;
use PKP\plugins\ReportPlugin;
use APP\core\Application;
use PKP\plugins\Hook;
use PKP\core\PKPString;
use APP\plugins\reports\submissionsCitationsReport\classes\SubmissionsCitationsReportBuilder;
class SubmissionsCitationsReportPlugin extends ReportPlugin
{
public function register($category, $path, $mainContextId = null): bool
{
$success = parent::register($category, $path, $mainContextId);
if (Application::isUnderMaintenance()) {
return $success;
}
if ($success && $this->getEnabled($mainContextId)) {
$this->addLocaleData();
Hook::add('AcronPlugin::parseCronTab', [$this, 'addTasksToCrontab']);
}
return $success;
}
public function getName()
{
return 'submissionscitationsreportplugin';
}
public function getDisplayName()
{
return __('plugins.reports.submissionsCitationsReport.displayName');
}
public function getDescription()
{
return __('plugins.reports.submissionsCitationsReport.description');
}
public function display($args, $request)
{
$context = $request->getContext();
$submissionsCitationsReportBuilder = new SubmissionsCitationsReportBuilder();
$report = $submissionsCitationsReportBuilder->createReport($context);
$this->emitHttpHeaders($request);
$csvFile = fopen('php://output', 'wt');
$report->buildCSV($csvFile);
}
private function emitHttpHeaders($request)
{
$context = $request->getContext();
header('content-type: text/comma-separated-values');
$acronym = PKPString::regexp_replace("/[^A-Za-z0-9 ]/", '', $context->getLocalizedAcronym());
header('content-disposition: attachment; filename=submissions_citations_' . $acronym . '_' . date('YmdHis') . '.csv');
}
public function addTasksToCrontab($hookName, $params)
{
$taskFilesPath = &$params[0];
$taskFilesPath[] = $this->getPluginPath() . DIRECTORY_SEPARATOR . 'scheduledTasks.xml';
return false;
}
}