ILIAS  release_7 Revision v7.30-3-g800a261c036
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 login,
58 gender,
59 firstname,
60 lastname,
61 title,
62 institution,
63 department,
64 street,
65 zipcode,
66 city,
67 country,
68 sel_country,
69 hobby,
70 email,
71 second_email,
72 matriculation,
73 active
74 FROM ' . $this->dic->database()->quoteIdentifier('usr_data') .
75
76 self::createWhereStatement($arr_usr_ids, $options['filters']);
77
78 if ($options['count']) {
79 $result = $this->dic->database()->query($select);
80
81 return $this->dic->database()->numRows($result);
82 }
83
84 if ($options['sort']) {
85 $select .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction'];
86 }
87
88 if (isset($options['limit']['start']) && isset($options['limit']['end'])) {
89 $select .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end'];
90 }
91
92 $result = $this->dic->database()->query($select);
93 $user_data = array();
94
95 while ($user = $this->dic->database()->fetchAssoc($result)) {
96 $list_user = new ilMStListUser();
97 $list_user->setUsrId($user['usr_id']);
98 $list_user->setGender($user['gender']);
99 $list_user->setTitle($user['title']);
100 $list_user->setInstitution($user['institution']);
101 $list_user->setDepartment($user['department']);
102 $list_user->setStreet($user['street']);
103 $list_user->setZipcode($user['zipcode']);
104 $list_user->setCity($user['city']);
105 $list_user->setCountry($user['country']);
106 $list_user->setSelCountry($user['sel_country']);
107 $list_user->setHobby($user['hobby']);
108 $list_user->setMatriculation($user['matriculation']);
109 $list_user->setActive($user['active']);
110 $list_user->setLogin($user['login']);
111 $list_user->setFirstname($user['firstname']);
112 $list_user->setLastname($user['lastname']);
113 $list_user->setEmail($user['email']);
114 $list_user->setSecondEmail($user['second_email']);
115
116 $user_data[] = $list_user;
117 }
118
119 return $user_data;
120 }
121
122
131 private function createWhereStatement(array $arr_usr_ids, array $arr_filter)
132 {
133 $where = array();
134
135 $where[] = $this->dic->database()->in('usr_data.usr_id', $arr_usr_ids, false, 'integer');
136
137 if (!empty($arr_filter['user'])) {
138 $where[] = "(" . $this->dic->database()->like("usr_data.login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
139 ->like("usr_data.firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
140 ->like("usr_data.lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
141 ->like("usr_data.email", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
142 ->like("usr_data.second_email", "text", "%" . $arr_filter['user'] . "%") . ") ";
143 }
144
145 if (!empty($arr_filter['org_unit'])) {
146 $where[] = 'usr_data.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $this->dic->database()
147 ->quote($arr_filter['org_unit'], 'integer') . ')';
148 }
149
150 if (!empty($arr_filter['lastname'])) {
151 $where[] = '(lastname LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['lastname']) . '%', 'text') . ')';
152 }
153
154 if (!empty($arr_filter['firstname'])) {
155 $where[] = '(firstname LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['firstname']) . '%', 'text') . ')';
156 }
157
158 if (!empty($arr_filter['email'])) {
159 $where[] = '(email LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['email']) . '%', 'text') . ')';
160 }
161
162 if (!empty($arr_filter['second_email'])) {
163 $where[] = '(second_email LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['second_email']) . '%', 'text') . ')';
164 }
165
166 if (!empty($arr_filter['title'])) {
167 $where[] = '(title LIKE ' . $this->dic->database()->quote('%' . str_replace('*', '%', $arr_filter['title']) . '%', 'text') . ')';
168 }
169
170 if ($arr_filter['activation']) {
171 if ($arr_filter['activation'] == 'active') {
172 $where[] = '(active = "1")';
173 }
174 if ($arr_filter['activation'] == 'inactive') {
175 $where[] = '(active = "0")';
176 }
177 }
178
179 if (!empty($where)) {
180 return ' WHERE ' . implode(' AND ', $where) . ' ';
181 } else {
182 return '';
183 }
184 }
185}
$result
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
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.