1<?php
2
3namespace dokuwiki\plugin\bez\mdl;
4
5class UserFactory {
6
7	private $model;
8
9	public function __construct($model) {
10		$this->model = $model;
11	}
12
13	public function get_all() {
14		$wikiusers = $this->model->dw_auth->retrieveUsers();
15
16		$a = array();
17		foreach ($wikiusers as $nick => $data) {
18			$a[$nick] = $data['name'];
19        }
20		asort($a);
21		return $a;
22	}
23
24    private function get_hidden_groups() {
25		$groups_s = $this->model->action->getConf('hidden_groups');
26		$groups = explode(',', $groups_s);
27
28		foreach($groups as &$group) {
29            $group = trim($group);
30        }
31
32		return $groups;
33	}
34
35    public function get_groups() {
36		global $auth;
37		$wikiusers = $auth->retrieveUsers();
38		$groups = array();
39		foreach ($wikiusers as $data) {
40			$groups = array_merge($groups, $data['grps']);
41		}
42		$groups = array_unique($groups);
43
44		$groups = array_diff($groups, $this->get_hidden_groups());
45
46		sort($groups);
47
48		return $groups;
49	}
50
51    public function users_of_group($groups) {
52		$wikiusers = $this->model->dw_auth->retrieveUsers();
53		if (is_string($groups)) {
54		    $groups = array($groups);
55        }
56
57		return array_keys(array_filter($wikiusers, function($data) use ($groups) {
58           return count(array_intersect($groups, $data['grps'])) > 0;
59        }));
60	}
61
62	public function exists($nick) {
63        if (!is_string($nick)) {
64            return false;
65        }
66
67		$users = $this->get_all();
68		if (array_key_exists($nick, $users)) {
69			return true;
70		} else {
71			return false;
72		}
73	}
74
75	public function get_user_full_name($nick) {
76		$users = $this->get_all();
77		return isset($users[$nick]) ? $users[$nick] : '';
78	}
79
80	public function get_user_email($nick) {
81		$wikiusers = $this->model->dw_auth->retrieveUsers();
82		return $wikiusers[$nick]['mail'];
83	}
84}
85