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
|
<?php
/**
* userlist.php - Controller for user list administration. User lists
* are lists of persons who get different chances at course seat distribution
* than "normal" applicants.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Thomas Hackl <thomas.hackl@uni-passau.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class Admission_UserlistController extends AuthenticatedController
{
/**
* @see AuthenticatedController::before_filter
*/
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
PageLayout::setTitle(_('Personenlisten'));
Navigation::activateItem('/browse/coursesets/userlists');
Sidebar::get()->addWidget(new ActionsWidget())->addLink(
_('Personenliste anlegen'),
$this->configureURL(),
Icon::create('add')
);
}
/**
* Show the user lists the current user has access to.
*/
public function index_action()
{
$this->userlists = [];
foreach (AdmissionUserList::getUserLists($GLOBALS['user']->id) as $list) {
$this->userlists[$list->getId()] = $list;
}
}
/**
* Show a configuration form for the given user list.
*
* @param String $userlistId user list to load settings from (or empty
* if it is a new user list)
*/
public function configure_action($userlistId = '')
{
if ($userlistId) {
$this->userlist = new AdmissionUserList($userlistId);
$this->userlist_id = $userlistId;
PageLayout::setTitle(_('Personenliste bearbeiten'));
} else {
PageLayout::setTitle(_('Personenliste anlegen'));
$this->userlist = new AdmissionUserList();
$this->userlist_id = '';
}
$this->users = User::findMany(array_keys($this->userlist->getUsers()));
if ($this->flash['name'] || $this->flash['factor'] || $this->flash['users'] || $this->flash['deleted_member']) {
if (!empty($this->flash['name'])) {
$this->userlist->setName($this->flash['name']);
}
if (!empty($this->flash['factor'])) {
$this->userlist->setFactor($this->flash['factor']);
}
if (!empty($this->flash['users']) || !empty($this->flash['deleted_member'])) {
$this->users = User::findMany($this->flash['cleared_users'] ?: $this->flash['users'] ?: []);
}
}
usort($this->users, function($a, $b) {
if ($a->nachname == $b->nachname) {
if ($a->vorname == $b->vorname) {
return strnatcasecmp($a->username, $b->username);
} else {
return strnatcasecmp($a->vorname, $b->vorname);
}
} else {
return strnatcasecmp($a->nachname, $b->nachname);
}
});
$uids = array_map(function($u) { return $u->id; }, $this->users);
$this->userSearch = new PermissionSearch('user', 'Person hinzufügen', 'user_id',
[
'permission' => ['user', 'autor', 'tutor', 'dozent'],
'exclude_user' => $uids
]);
$this->flash['listusers'] = $uids;
}
/**
* Saves the given user list to database.
*
* @param String $userlistId user list to save
*/
public function save_action($userlistId = '')
{
CSRFProtection::verifyUnsafeRequest();
$userlist = new AdmissionUserList($userlistId);
$userlist->setName(Request::get('name'))
->setFactor(Request::float('factor', 0))
->setUsers(Request::getArray('users'))
->setOwnerId($GLOBALS['user']->id);
if ($userlist->store()) {
PageLayout::postSuccess(_('Die Personenliste wurde gespeichert.'));
} else {
PageLayout::postError(_('Die Personenliste konnte nicht gespeichert werden.'));
}
$this->redirect('admission/userlist');
}
/**
* Deletes the given user list.
*
* @param String $userlistId the user list to delete
*/
public function delete_action($userlistId)
{
CSRFProtection::verifyUnsafeRequest();
$userlist = new AdmissionUserList($userlistId);
$userlist->delete();
$this->redirect($this->indexURL());
}
/**
* Deletes the given user from the given user list.
* @param $userlistId
* @param $userId
*/
public function delete_member_action($userlistId, $userId)
{
$newusers = array_filter($this->flash['listusers'], function($u) use ($userId) { return $u != $userId; });
$this->flash['cleared_users'] = $newusers;
$this->flash['deleted_member'] = true;
PageLayout::postInfo(
sprintf(_('%s wurde von der Liste entfernt, die Liste ist aber noch nicht gespeichert.'),
User::find($userId)->getFullName()));
$this->redirect($this->url_for('admission/userlist/configure', $userlistId));
}
/**
* Landing page for mulitpersonsearch, adds the selected users to the
* user list.
* @param $userlistId string ID of the userlist to edit
*/
public function add_members_action($userlistId)
{
$mp = MultiPersonSearch::load("add_userlist_member_" . $userlistId);
$users = $mp->getDefaultSelectedUsersIDs();
$oldsize = count($users);
foreach ($mp->getAddedUsers() as $u) {
$users[] = $u;
}
$newsize = count($users);
$this->flash['users'] = $users;
PageLayout::postInfo(
sprintf(ngettext('Eine Person wurde der Liste hinzugefügt.',
'%u Personen wurden der Liste hinzugefügt, die Liste ist aber noch nicht gespeichert.',
$newsize - $oldsize), $newsize - $oldsize));
$this->redirect($this->url_for('admission/userlist/configure', $userlistId));
}
}
|