|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Collection of list functions for OpenPSA |
|
4
|
|
|
* |
|
5
|
|
|
* @package org.openpsa.helpers |
|
6
|
|
|
* @author Eero af Heurlin, http://www.iki.fi/rambo |
|
7
|
|
|
* @copyright Nemein Oy, http://www.nemein.com |
|
8
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @package org.openpsa.helpers |
|
13
|
|
|
*/ |
|
14
|
|
|
class org_openpsa_helpers_list |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* List virtual groups of user |
|
18
|
|
|
*/ |
|
19
|
23 |
|
public static function workgroups(string $add_me = 'last', bool $show_members = false) : array |
|
20
|
|
|
{ |
|
21
|
23 |
|
if (!midcom::get()->auth->user) { |
|
22
|
|
|
return []; |
|
23
|
|
|
} |
|
24
|
23 |
|
static $cache = []; |
|
25
|
|
|
// List user's ACL groups for usage in DM arrays |
|
26
|
23 |
|
$array_name = $add_me . '_' . $show_members; |
|
27
|
23 |
|
if (!array_key_exists($array_name, $cache)) { |
|
28
|
2 |
|
$cache[$array_name] = []; |
|
29
|
2 |
|
if ($add_me == 'first') { |
|
30
|
1 |
|
$cache[$array_name][midcom::get()->auth->user->id] = midcom::get()->i18n->get_string('me', 'org.openpsa.contacts'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
2 |
|
$users_groups = midcom::get()->auth->user->list_memberships(); |
|
34
|
2 |
|
foreach ($users_groups as $key => $group) { |
|
35
|
|
|
$cache[$array_name][$key] = $group->name; |
|
36
|
|
|
if ($show_members) { |
|
37
|
|
|
foreach ($group->list_members() as $key2 => $person) { |
|
38
|
|
|
$cache[$array_name][$key2] = ' ' . $person->name; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
2 |
|
asort($cache[$array_name]); |
|
44
|
|
|
|
|
45
|
2 |
|
if ($add_me == 'last') { |
|
46
|
1 |
|
$cache[$array_name][midcom::get()->auth->user->id] = midcom::get()->i18n->get_string('me', 'org.openpsa.contacts'); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
23 |
|
return $cache[$array_name]; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|