-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDataversePlugin.php
148 lines (127 loc) · 4.76 KB
/
DataversePlugin.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
<?php
/**
* @file plugins/generic/dataverse/DataversePlugin.inc.php
*
* Copyright (c) 2019 - 2024 Lepidus Tecnologia
* Copyright (c) 2020 - 2024 SciELO
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class DataversePlugin
* @ingroup plugins_generic_dataverse
*
* @brief dataverse plugin class
*/
namespace APP\plugins\generic\dataverse;
use PKP\plugins\GenericPlugin;
use PKP\plugins\PluginRegistry;
use APP\core\Application;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use APP\notification\NotificationManager;
use PKP\core\JSONMessage;
use PKP\db\DAORegistry;
use APP\plugins\generic\dataverse\classes\migrations\DataverseMigration;
use APP\plugins\generic\dataverse\classes\dataverseConfiguration\DataverseConfigurationDAO;
use APP\plugins\generic\dataverse\DataverseSettingsForm;
use APP\plugins\generic\dataverse\report\DataverseReportPlugin;
class DataversePlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
if (Application::isUnderMaintenance()) {
return true;
}
$dataverseConfigurationDAO = new DataverseConfigurationDAO();
DAORegistry::registerDAO('DataverseConfigurationDAO', $dataverseConfigurationDAO);
$context = Application::get()->getRequest()->getContext();
if (!is_null($context) and $dataverseConfigurationDAO->hasConfiguration($context->getId())) {
$this->loadDispatcherClasses();
PluginRegistry::register('reports', $this->getReportPlugin(), $this->getPluginPath());
}
return $success;
}
private function loadDispatcherClasses(): void
{
$dispatcherClasses = [
'DataStatementDispatcher',
'DataStatementTabDispatcher',
'DraftDatasetFilesDispatcher',
'DatasetMetadataDispatcher',
'DatasetInformationDispatcher',
'DatasetTabDispatcher',
'DatasetReviewDispatcher',
'DataverseEventsDispatcher'
];
foreach ($dispatcherClasses as $dispatcherClass) {
$dispatcherClass = 'APP\plugins\generic\dataverse\classes\dispatchers\\' . $dispatcherClass;
$dispatcher = new $dispatcherClass($this);
}
}
public function getDisplayName()
{
return __('plugins.generic.dataverse.displayName');
}
public function getDescription()
{
return __('plugins.generic.dataverse.description');
}
public function getReportPlugin()
{
return new DataverseReportPlugin();
}
public function getInstallEmailTemplatesFile()
{
return $this->getPluginPath() . DIRECTORY_SEPARATOR . 'emailTemplates.xml';
}
public function getPluginFullPath(): string
{
$request = Application::get()->getRequest();
return $request->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getPluginPath();
}
public function getActions($request, $actionArgs)
{
$router = $request->getRouter();
return array_merge(
$this->getEnabled() ? array(
new LinkAction(
'settings',
new AjaxModal(
$router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
),
) : array(),
parent::getActions($request, $actionArgs)
);
}
public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
$context = $request->getContext();
$contextId = ($context == null) ? 0 : $context->getId();
$form = new DataverseSettingsForm($this, $contextId);
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
$form->execute();
$notificationManager = new NotificationManager();
$notificationManager->createTrivialNotification($request->getUser()->getId());
return new JSONMessage(true);
}
} else {
$form->initData();
$form->display($request);
}
return new JSONMessage(true, $form->fetch($request));
}
return parent::manage($args, $request);
}
public function getInstallMigration(): DataverseMigration
{
return new DataverseMigration();
}
}