-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfirmMembershipPluginHandler.inc.php
185 lines (170 loc) · 8.36 KB
/
ConfirmMembershipPluginHandler.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
<?php
import('classes.handler.Handler');
import('classes.user.UserAction');
import('lib.pkp.classes.plugins.Plugin');
import('plugins.generic.RDLUser.RDLUserPlugin');
class ConfirmMembershipPluginHandler extends Handler
{
var $templateMgr;
var $plugin;
var $journalDao;
var $userSettingsDao;
var $subscriptionDao;
var $instituSubscriptionDao;
var $userDao;
var $stageAssignmentDao;
function __construct()
{
parent::__construct();
$this->plugin = PluginRegistry::getPlugin('generic', 'confirmmembershipplugin');
$this->journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */
$this->userSettingsDao = DAORegistry::getDAO('UserSettingsDAO');
$this->subscriptionDao = DAORegistry::getDAO('IndividualSubscriptionDAO');
$this->instituSubscriptionDao = DAORegistry::getDAO('InstitutionalSubscriptionDAO');
$this->stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
$this->userDao = DAORegistry::getDAO('UserDAO');
$this->addRoleAssignment(
[ROLE_ID_SITE_ADMIN],
[
'index',
]
);
}
/**
* @copydoc PKPHandler::initialize()
*/
function initialize($request, $args = null)
{
$this->templateMgr = TemplateManager::getManager($request);
AppLocale::requireComponents(
LOCALE_COMPONENT_PKP_ADMIN,
LOCALE_COMPONENT_APP_MANAGER,
LOCALE_COMPONENT_APP_ADMIN,
LOCALE_COMPONENT_APP_COMMON,
LOCALE_COMPONENT_PKP_USER,
LOCALE_COMPONENT_PKP_MANAGER
);
return parent::initialize($request);
}
/**
* @copydoc PKPHandler::authorize()
*/
function authorize($request, &$args, $roleAssignments)
{
import('lib.pkp.classes.security.authorization.PKPSiteAccessPolicy');
$this->addPolicy(new PKPSiteAccessPolicy($request, null, $roleAssignments));
$returner = parent::authorize($request, $args, $roleAssignments);
// Admin shouldn't access this page from a specific context
if ($request->getContext()) {
return false;
}
return $returner;
}
public function index($args, $request) {
$amountOfUsers = $this->plugin->getSetting(CONTEXT_SITE, 'amountofusers');
if (isset($request->_requestVars['userid'])) {
$userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
$mergesUserId = $userDao->getByUsername($this->plugin->getSetting(CONTEXT_SITE, 'mergeusername'))->getId();
$userAction = new UserAction();
$userAction->mergeUsers($request->_requestVars['userid'], $mergesUserId);
}
if (isset($request->_requestVars['next'])) {
$next = $amountOfUsers + ($request->_requestVars['next']);
}
elseif (isset($request->_requestVars['previous'])) {
$next = ($request->_requestVars['previous']) - $amountOfUsers;
}
else {
$next = $amountOfUsers;
}
$users = $this->getUsersToDelete($next);
$this->templateMgr->setupBackendPage();
$this->templateMgr->assign([
'total' => $this->getTotalCount(),
'users' => $users,
'next' => $next,
'show' => $amountOfUsers,
'mergesUser' => __("plugins.generic.confirmmembership.mergeuserpopup", ['merge_user' => $this->plugin->getSetting(CONTEXT_SITE, 'mergeusername')]),
]);
return $this->templateMgr->display($this->plugin->getTemplateResource('index.tpl'));
}
protected function getTotalCount()
{
$userSettingsDao = DAORegistry::getDAO('UserSettingsDAO');
$result = $userSettingsDao->retrieve("select count(*) from user_settings WHERE setting_name = ?", [SETTING_CAN_NOT_DELETE]);
return $result->current()->count;
}
protected function findAssignment($userId) {
$review = [];
$checkUserSubmissions = $this->stageAssignmentDao->retrieve("select submissions.submission_id, path, last_modified::date from journals join submissions on submissions.context_id = journals.journal_id join stage_assignments on submissions.submission_id = stage_assignments.submission_id and user_id= ?", [$userId]);
foreach ($checkUserSubmissions as $submission) {
$review[] = [
'url' => '/index.php/' . $submission->path . '/workflow/index/' . $submission->submission_id . '/1',
'date' => $submission->last_modified,
'review' => false
];
}
$checkUserSubmissions = $this->stageAssignmentDao->retrieve("select submissions.submission_id, path , review_assignments.last_modified::date from journals join submissions on submissions.context_id = journals.journal_id join review_assignments on submissions.submission_id = review_assignments.submission_id and reviewer_id= ?", [$userId]);
foreach ($checkUserSubmissions as $submission) {
$review[] = [
'url' => '/index.php/' . $submission->path . '/workflow/index/' . $submission->submission_id . '/1',
'date' => $submission->last_modified,
'review' => true
];
}
return $review;
}
private function getUsersToDelete($next) {
$roleNames = Application::getRoleNames();
$amountOfUsers = $this->plugin->getSetting(CONTEXT_SITE, 'amountofusers');
$offset = $next === $amountOfUsers? 0 : ($next - $amountOfUsers);
$result = $this->userSettingsDao->retrieve("select user_settings.user_id from user_settings join users on users.user_id=user_settings.user_id where setting_name=? and user_settings.user_id in (select user_id from user_settings where setting_name=?) order by setting_value DESC LIMIT ? OFFSET ?",
[SETTING_MEMBERSHIP_MAIL_SEND, SETTING_CAN_NOT_DELETE, $amountOfUsers, $offset]);
$deletUsers = [];
foreach ($result as $userId) {
$user = $this->userDao->getById($userId->user_id);
$deletUser = [];
$journals = $this->journalDao->getAll();
while ($journal = $journals->next()) {
$memberJournals = NULL;
$roles = [];
foreach ($user->getRoles($journal->getId()) as $role) {
$memberJournals = $journal->getName($journal->getPrimaryLocale());
$roles[] = __($roleNames[$role->getRoleId()]);
}
if (!is_null($memberJournals)) {
if ($this->subscriptionDao->subscriptionExistsByUserForJournal($user->getId(), $journal->getId()) || $this->instituSubscriptionDao->subscriptionExistsByUserForJournal($user->getId(), $journal->getId())) {
$deletUser['subscriber'] = true;
} else {
$deletUser['subscriber'] = false;
}
$deletUser['journals'] = $memberJournals;
$deletUser['name'] = $user->getFullName();
$deletUser['username'] = $user->getUsername();
$deletUser['email'] = $user->getEmail();
$deletUser['userid'] = $user->getId();
$deletUser['role'] = implode(', ', $roles);
$deletUser['journals'] = $memberJournals;
$deletUser['link'] = '/index.php/' . $journal->getPath() . '/management/settings/access';
$deletUser['assignment'] = $this->findAssignment($user->getId());
$deletUser['date'] = $user->getData(SETTING_MEMBERSHIP_MAIL_SEND);
$deletUsers[] = $deletUser;
}
}
if (count($deletUser) == 0) {
$deletUser['journals'] = 'none';
$deletUser['subscriber'] = false;
$deletUser['assignment'] = $this->findAssignment($user->getId());
$deletUser['name'] = $user->getFullName();
$deletUser['username'] = $user->getUsername();
$deletUser['email'] = $user->getEmail();
$deletUser['role'] = '';
$deletUser['link'] = '';
$deletUser['userid'] = $user->getId();
$deletUser['date'] = $user->getData(SETTING_MEMBERSHIP_MAIL_SEND);
$deletUsers[] = $deletUser;
}
}
return $deletUsers;
}
}