ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMStListUsers.php
Go to the documentation of this file.
1<?php
3
5
12{
13
17 protected $dic;
18
19
25 public function __construct(Container $dic)
26 {
27 $this->dic = $dic;
28 }
29
36 public function getData(array $arr_usr_ids = array(), array $options = array())
37 {
38 //Permissions
39 if (count($arr_usr_ids) == 0) {
40 if ($options['count']) {
41 return 0;
42 } else {
43 return array();
44 }
45 }
46
47 $_options = array(
48 'filters' => array(),
49 'sort' => array(),
50 'limit' => array(),
51 'count' => false,
52 );
53 $options = array_merge($_options, $options);
54
55 $select = 'SELECT
56 usr_id,
57 time_limit_owner,
58 login,
59 gender,
60 firstname,
61 lastname,
62 title,
63 institution,
64 department,
65 street,
66 zipcode,
67 city,
68 country,
69 sel_country,
70 hobby,
71 email,
72 matriculation,
73 phone_office,
74 phone_mobile,
75 active
76 FROM ' . $this->dic->database()->quoteIdentifier('usr_data') .
77
78 self::createWhereStatement($arr_usr_ids, $options['filters']);
79
80 if ($options['count']) {
81 $result = $this->dic->database()->query($select);
82
83 return $this->dic->database()->numRows($result);
84 }
85
86 if ($options['sort']) {
87 $select .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction'];
88 }
89
90 if (isset($options['limit']['start']) && isset($options['limit']['end'])) {
91 $select .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end'];
92 }
93
94 $result = $this->dic->database()->query($select);
95 $user_data = array();
96
97 while ($user = $this->dic->database()->fetchAssoc($result)) {
98 $list_user = new ilMStListUser();
99 $list_user->setUsrId($user['usr_id']);
100 $list_user->setGender($user['gender']);
101 $list_user->setTitle($user['title']);
102 $list_user->setInstitution($user['institution']);
103 $list_user->setDepartment($user['department']);
104 $list_user->setStreet($user['street']);
105 $list_user->setZipcode($user['zipcode']);
106 $list_user->setCity($user['city']);
107 $list_user->setCountry($user['country']);
108 $list_user->setSelCountry($user['sel_country']);
109 $list_user->setHobby($user['hobby']);
110 $list_user->setMatriculation($user['matriculation']);
111 $list_user->setActive($user['active']);
112 $list_user->setTimeLimitOwner($user['time_limit_owner']);
113 $list_user->setLogin($user['login']);
114 $list_user->setFirstname($user['firstname']);
115 $list_user->setLastname($user['lastname']);
116 $list_user->setEmail($user['email']);
117 $list_user->setPhone($user['phone_office']);
118 $list_user->setMobilePhone($user['phone_mobile']);
119
120 $user_data[] = $list_user;
121 }
122
123 return $user_data;
124 }
125
126
135 private function createWhereStatement(array $arr_usr_ids, array $arr_filter)
136 {
137 $where = array();
138
139 $where[] = $this->dic->database()->in('usr_data.usr_id', $arr_usr_ids, false, 'integer');
140
141 if (!empty($arr_filter['user'])) {
142 $where[] = "(" . $this->dic->database()->like("usr_data.login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
143 ->like("usr_data.firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
144 ->like("usr_data.lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
145 ->like("usr_data.email", "text", "%" . $arr_filter['user'] . "%") . ") ";
146 }
147
148 if (!empty($arr_filter['org_unit'])) {
149 $where[] = 'usr_data.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $this->dic->database()
150 ->quote($arr_filter['org_unit'], 'integer') . ')';
151 }
152
153 if (!empty($arr_filter['lastname'])) {
154 $where[] = '(lastname LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['lastname']) . '%', 'text') . ')';
155 }
156
157 if (!empty($arr_filter['firstname'])) {
158 $where[] = '(firstname LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['firstname']) . '%', 'text') . ')';
159 }
160
161 if (!empty($arr_filter['email'])) {
162 $where[] = '(email LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['email']) . '%', 'text') . ')';
163 }
164
165 if (!empty($arr_filter['title'])) {
166 $where[] = '(title LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['title']) . '%', 'text') . ')';
167 }
168
169 if ($arr_filter['activation']) {
170 if ($arr_filter['activation'] == 'active') {
171 $where[] = '(active = "1")';
172 }
173 if ($arr_filter['activation'] == 'inactive') {
174 $where[] = '(active = "0")';
175 }
176 }
177
178 if (!empty($where)) {
179 return ' WHERE ' . implode(' AND ', $where) . ' ';
180 } else {
181 return '';
182 }
183 }
184}
$result
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:18
createWhereStatement(array $arr_usr_ids, array $arr_filter)
Returns the WHERE Part for the Queries using parameter $user_ids AND local variable $filters.
getData(array $arr_usr_ids=array(), array $options=array())
__construct(Container $dic)
ilMStListUsers constructor.