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
|
<?php
/**
* ExternPagePersons.php - Class to provide a list of members of institutes.
*
* 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 Peter Thienel <thienel@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 5.4
*/
class ExternPagePersons extends ExternPage
{
public $institute;
public function __construct($config)
{
parent::__construct($config);
$this->institute = Institute::find($this->page_config->range_id);
}
public function getSortFields(): array
{
return [
'vorname' => _('Vorname'),
'nachname' => _('Nachname'),
'email' => _('E-Mail'),
'title_front' => _('Titel vorangestellt'),
'title_rear' => _('Titel nachgestellt')
];
}
public function getDataFields($object_classes = []): array
{
return parent::getDataFields(
[
'user',
'userinstrole'
]
);
}
public function getConfigFields($as_array = false)
{
$args = '
sort option,
grouping bool,
language option,
groupsvisible intArray,
groupsalias getArray,
escaping option
';
return $as_array ? self::argsToArray($args) : $args;
}
public function getAllowedRequestParams($as_array = false)
{
$params = [
'grouping',
'language',
'sort',
];
return $as_array ? $params : implode(',', $params);
}
public function getMarkersContents(): array
{
if ($this->grouping) {
return [
'GROUPS' => $this->getGroupedContent()
];
} else {
return [
'PERSONS' => $this->getContentUsers()
];
}
}
protected function getContentUsers()
{
$content = [];
foreach ($this->institute->members->orderBy($this->sort) as $member) {
$content[] = $this->getUserContent($member);
}
return $content;
}
/**
* Returns all marker content for grouped view.
*
* @return array The array with all markers.
*/
protected function getGroupedContent()
{
$content = [];
foreach ($this->institute->status_groups->orderBy('position') as $top_group) {
foreach ($this->getAllChildren($top_group) as $group) {
if ($this->groupsvisible[$group->id]) {
if ($this->groupsalias[$group->id]) {
$grouptitle_substitute = $this->groupsalias[$group->id];
} else {
$grouptitle_substitute = '';
}
$content[] = [
'GROUPTITLE' => $group->name,
'GROUPTITLE_SUBSTITUTE' => $grouptitle_substitute,
'PERSONS' => $this->getContentGroupedUsers($group->members),
];
}
}
}
return $content;
}
private function getContentGroupedUsers($members)
{
$content = [];
foreach ($members as $member) {
$content[] = $this->getUserContent($member);
}
return $content;
}
/**
* Returns all child groups of a group.
*
* @param Statusgruppen $group The parent group.
* @return Statusgruppen[] All child groups.
*/
protected function getAllChildren(Statusgruppen $group)
{
$all_groups[] = $group;
foreach ($group->getChildren() as $child) {
$all_groups = array_merge($all_groups, $this->getAllChildren($child));
}
return $all_groups;
}
/**
* Get content of a single user.
*
* @param StatusgruppeUser $member
* @return array
*/
protected function getUserContent($member)
{
if (Visibility::verify('picture', $member->user_id) == 5) {
$avatar = Avatar::getAvatar($member->user_id);
} else {
$avatar = Avatar::getNobody();
}
$inst_member = $this->institute->members->findOneBy('user_id', $member->user_id);
$content = array_merge(
[
'FULLNAME' => $member->user->getFullName(),
'LASTNAME' => $member->user->Nachname,
'FIRSTNAME' => $member->user->Vorname,
'TITLEFRONT' => $member->user->title_front,
'TITLEREAR' => $member->user->title_rear,
'USERNAME' => $member->user->username,
'ID' => $member->user_id,
'IMAGE_URL_SMALL' => $avatar->getURL(Avatar::SMALL),
'IMAGE_URL_MEDIUM' => $avatar->getURL(Avatar::MEDIUM),
'IMAGE_URL_NORMAL' => $avatar->getURL(Avatar::NORMAL),
'PHONE' => $inst_member->telefon,
'ROOM' => $inst_member->raum,
'EMAIL' => get_visible_email($member->user->user_id),
'HOMEPAGE_URL' => Visibility::verify('homepage', $member->user_id) ? $member->user->home : '',
'OFFICEHOURS' => $inst_member->sprechzeiten
],
$this->getDatafieldMarkers($member->user),
$this->getDatafieldMarkers($member));
return $content;
}
public function getFullGroupNames()
{
$groups = [];
foreach ($this->institute->status_groups as $status_group) {
$groups[$status_group->id] = $status_group->name;
$groups = array_merge($groups, $this->getGroupPaths($status_group));
}
return $groups;
}
public function getGroupPaths($group, $seperator = ' > ', $pre = '')
{
$name = $pre
? $pre . $seperator . $group->getName()
: $group->getName();
$result[$group->id] = $name;
if ($group->children) {
foreach ($group->children as $child) {
$result = array_merge($result, $this->getGroupPaths($child, $seperator, $name));
}
}
return $result;
}
}
|