-
Notifications
You must be signed in to change notification settings - Fork 43
/
QuickSubmitPlugin.php
263 lines (238 loc) · 7.42 KB
/
QuickSubmitPlugin.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
/**
* @file QuickSubmitPlugin.php
*
* Copyright (c) 2013-2023 Simon Fraser University
* Copyright (c) 2003-2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class QuickSubmitPlugin
*
* @brief Quick Submit one-page submission plugin
*/
namespace APP\plugins\importexport\quickSubmit;
use APP\notification\NotificationManager;
use APP\template\TemplateManager;
use PKP\core\JSONMessage;
use PKP\notification\PKPNotification;
class QuickSubmitPlugin extends \PKP\plugins\ImportExportPlugin
{
/**
* @copydoc Plugin::register()
*
* @param null|mixed $mainContextId
*/
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
$this->addLocaleData();
return $success;
}
/**
* @copydoc Plugin::getName()
*/
public function getName()
{
return 'QuickSubmitPlugin';
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName()
{
return __('plugins.importexport.quickSubmit.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription()
{
return __('plugins.importexport.quickSubmit.description');
}
/**
* @copydoc ImportExportPlugin::display()
*/
public function display($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$templateMgr->registerPlugin('function', 'plugin_url', [$this, 'smartyPluginUrl']);
$templateMgr->assign('quickSubmitPlugin', $this);
switch (array_shift($args)) {
case 'saveSubmit':
if ($request->getUserVar('reloadForm') == '1') {
$this->_reloadForm($request);
} else {
$this->_saveSubmit($request);
}
break;
case 'cancelSubmit':
$this->_cancelSubmit($request);
break;
case 'uploadCoverImage':
return $this->_showFileUploadForm($request);
case 'uploadImage':
return $this->_uploadImage($request);
case 'saveUploadedImage':
return $this->_saveUploadedImage($request);
case 'deleteCoverImage':
return $this->_deleteUploadedImage($request);
default:
$templateMgr->assign([
'pageTitle' => $this->getDisplayName(),
]);
$form = new QuickSubmitForm($this, $request);
$form->initData();
$form->display($request);
break;
}
}
/**
* Cancels the submission
*
* @param $request Request
*/
protected function _cancelSubmit($request)
{
$form = new QuickSubmitForm($this, $request);
$form->readInputData();
$form->cancel();
// Submission removal notification.
$notificationContent = __('notification.removedSubmission');
$currentUser = $request->getUser();
$notificationMgr = new NotificationManager();
$notificationMgr->createTrivialNotification($currentUser->getId(), PKPNotification::NOTIFICATION_TYPE_SUCCESS, ['contents' => $notificationContent]);
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign([
'pageTitle' => __('plugins.importexport.quickSubmit.cancel'),
]);
$templateMgr->display($this->getTemplateResource('submitCancel.tpl'));
}
/**
* Show the upload image form.
*
* @param $request Request
*
* @return JSONMessage JSON object
*/
protected function _showFileUploadForm($request)
{
$imageUploadForm = new classes\form\UploadImageForm($this, $request);
$imageUploadForm->initData();
return new JSONMessage(true, $imageUploadForm->fetch($request));
}
/**
* Upload the image to a temporary file
*
* @param $request Request
*
* @return JSONMessage JSON object
*/
protected function _uploadImage($request)
{
$imageUploadForm = new classes\form\UploadImageForm($this, $request);
$imageUploadForm->readInputData();
$temporaryFileId = $imageUploadForm->uploadFile($request);
if ($temporaryFileId) {
$json = new JSONMessage(true);
$json->setAdditionalAttributes([
'temporaryFileId' => $temporaryFileId
]);
return $json;
} else {
return new JSONMessage(false, __('common.uploadFailed'));
}
}
/**
* Save the new image file.
*
* @param $request Request.
*
* @return JSONMessage JSON object
*/
protected function _saveUploadedImage($request)
{
$imageUploadForm = new classes\form\UploadImageForm($this, $request);
$imageUploadForm->readInputData();
return $imageUploadForm->execute($request);
}
/**
* Delete the uploaded image
*
* @param $request Request.
*
* @return JSONMessage JSON object
*/
protected function _deleteUploadedImage($request)
{
$imageUploadForm = new classes\form\UploadImageForm($this, $request);
$imageUploadForm->readInputData();
return $imageUploadForm->deleteCoverImage($request);
}
/**
* Save the submitted form
*
* @param $request Request.
*/
protected function _saveSubmit($request)
{
$templateMgr = TemplateManager::getManager($request);
$form = new QuickSubmitForm($this, $request);
$form->readInputData();
if ($form->validate()) {
$form->execute();
$templateMgr->assign([
'pageTitle' => __('plugins.importexport.quickSubmit.success'),
'submissionId' => $form->getSubmission()->getId(),
'stageId' => WORKFLOW_STAGE_ID_PRODUCTION,
]);
$templateMgr->display($this->getTemplateResource('submitSuccess.tpl'));
} else {
$form->display($request);
}
}
/**
* Reloads the form
*
* @param $request Request.
*/
protected function _reloadForm($request)
{
$templateMgr = TemplateManager::getManager($request);
$form = new QuickSubmitForm($this, $request);
$form->readInputData();
$form->display($request);
}
/**
* Extend the {url ...} for smarty to support this plugin.
*/
public function smartyPluginUrl($params, $smarty)
{
$path = ['plugin',$this->getName()];
if (is_array($params['path'])) {
$params['path'] = array_merge($path, $params['path']);
} elseif (!empty($params['path'])) {
$params['path'] = array_merge($path, [$params['path']]);
} else {
$params['path'] = $path;
}
if (!empty($params['id'])) {
$params['path'] = array_merge($params['path'], [$params['id']]);
unset($params['id']);
}
return $smarty->smartyUrl($params, $smarty);
}
/**
* @copydoc PKPImportExportPlugin::usage
*/
public function usage($scriptName)
{
fatalError('Not implemented');
}
/**
* @copydoc PKPImportExportPlugin::executeCLI()
*/
public function executeCLI($scriptName, &$args)
{
fatalError('Not implemented');
}
}