forked from pkp/quickSubmit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
QuickSubmitPlugin.inc.php
239 lines (213 loc) · 6.41 KB
/
QuickSubmitPlugin.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
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
<?php
/**
* @file QuickSubmitPlugin.inc.php
*
* Copyright (c) 2013-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class QuickSubmitPlugin
* @ingroup plugins_importexport_quickSubmit
*
* @brief Quick Submit one-page submission plugin
*/
use PKP\core\JSONMessage;
class QuickSubmitPlugin extends \PKP\plugins\ImportExportPlugin {
/**
* @copydoc Plugin::register()
*/
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', array($this, 'smartyPluginUrl'));
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:
$this->import('QuickSubmitForm');
$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) {
$this->import('QuickSubmitForm');
$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(), NOTIFICATION_TYPE_SUCCESS, array('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) {
import('plugins.importexport.quickSubmit.classes.form.UploadImageForm');
$imageUploadForm = new UploadImageForm($this, $request);
$imageUploadForm->initData($request);
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) {
import('plugins.importexport.quickSubmit.classes.form.UploadImageForm');
$imageUploadForm = new UploadImageForm($this, $request);
$imageUploadForm->readInputData();
$temporaryFileId = $imageUploadForm->uploadFile($request);
if ($temporaryFileId) {
$json = new JSONMessage(true);
$json->setAdditionalAttributes(array(
'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) {
import('plugins.importexport.quickSubmit.classes.form.UploadImageForm');
$imageUploadForm = new UploadImageForm($this, $request);
$imageUploadForm->readInputData();
return $imageUploadForm->execute($request);
}
/**
* Delete the uploaded image
* @param $request Request.
* @return JSONMessage JSON object
*/
protected function _deleteUploadedImage($request) {
import('plugins.importexport.quickSubmit.classes.form.UploadImageForm');
$imageUploadForm = new UploadImageForm($this, $request);
$imageUploadForm->readInputData();
return $imageUploadForm->deleteCoverImage($request);
}
/**
* Save the submitted form
* @param $request Request.
*/
protected function _saveSubmit($request) {
$templateMgr = TemplateManager::getManager($request);
$this->import('QuickSubmitForm');
$form = new QuickSubmitForm($this, $request);
$form->readInputData();
if($form->validate()){
$form->execute();
$templateMgr->assign(array(
'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);
$this->import('QuickSubmitForm');
$form = new QuickSubmitForm($this, $request);
$form->readInputData();
$form->display($request);
}
/**
* Extend the {url ...} for smarty to support this plugin.
*/
function smartyPluginUrl($params, $smarty) {
$path = array('plugin',$this->getName());
if (is_array($params['path'])) {
$params['path'] = array_merge($path, $params['path']);
} elseif (!empty($params['path'])) {
$params['path'] = array_merge($path, array($params['path']));
} else {
$params['path'] = $path;
}
if (!empty($params['id'])) {
$params['path'] = array_merge($params['path'], array($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');
}
}