forked from kaschioudi/sword
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSwordSettingsTabHandler.php
83 lines (72 loc) · 2.06 KB
/
SwordSettingsTabHandler.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
<?php
/**
* @file SwordSettingsTabHandler.php
*
* Copyright (c) 2003-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class SwordSettingsTabHandler
* @brief Responds to requests for SWORD settings page
*/
namespace APP\plugins\generic\sword;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\db\DAORegistry;
use PKP\plugins\PluginRegistry;
use PKP\security\Role;
use PKP\i18n\Locale;
use PKP\core\JSONMessage;
use APP\handler\Handler;
use APP\template\TemplateManager;
use APP\notification\NotificationManager;
use APP\plugins\generic\sword\SwordSettingsForm;
use APP\plugins\generic\sword\SwordPlugin;
class SwordSettingsTabHandler extends Handler {
/** @var SwordPlugin Reference to SWORD plugin */
protected $_plugin = null;
/**
* Constructor
*/
public function __construct(SwordPlugin $plugin) {
parent::__construct();
$this->_plugin = $plugin;
$this->addRoleAssignment(
[Role::ROLE_ID_MANAGER],
['swordSettings']
);
}
/**
* @copydoc PKPHandler::authorize()
*/
function authorize($request, &$args, $roleAssignments) {
$this->addPolicy(new ContextAccessPolicy($request, $roleAssignments));
return parent::authorize($request, $args, $roleAssignments);
}
/**
* SWORD plugin settings page
* @param $args array
* @param $request PKPRequest
*
* @return JSONMessage
*/
public function swordSettings($args, $request) {
$context = $request->getContext();
$templateMgr = TemplateManager::getManager($request);
$form = new SwordSettingsForm($this->_plugin, $context);
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
$form->execute();
$notificationManager = new NotificationManager();
$notificationManager->createTrivialNotification(
$request->getUser()->getId(),
NOTIFICATION_TYPE_SUCCESS,
array('contents' => __('plugins.generic.sword.settings.saved'))
);
}
} else {
$form->initData();
}
return new JSONMessage(true, $form->fetch($request));
}
}