ILIAS  release_8 Revision v8.24
class.ilOrgUnitUserRepository.php
Go to the documentation of this file.
1<?php
19namespace OrgUnit\User;
20
23
29{
30 protected \ILIAS\DI\Container $dic;
34 protected static array $instance;
38 protected array $orgu_users;
39 protected bool $with_superiors = false;
40 protected bool $with_positions = false;
41
45 public function __construct()
46 {
47 global $DIC;
48 $this->dic = $DIC;
49 }
50
55 {
56 $this->with_superiors = true;
57
58 return $this;
59 }
60
65 {
66 $this->with_positions = true;
67
68 return $this;
69 }
70
75 public function getOrgUnitUsers(array $arr_user_id): array
76 {
77 $this->orgu_users = $this->loadUsersByUserIds($arr_user_id);
78
79 if ($this->with_superiors === true) {
80 $this->loadSuperiors($arr_user_id);
81 }
82
83 if ($this->with_positions === true) {
84 $this->loadPositions($arr_user_id);
85 }
86
87 return $this->orgu_users;
88 }
89
94 public function getOrgUnitUser(int $user_id): ?ilOrgUnitUser
95 {
96 $this->orgu_users = $this->loadUsersByUserIds([$user_id]);
97
98 if (count($this->orgu_users) == 0) {
99 return null;
100 }
101
102 if ($this->with_superiors === true) {
103 $this->loadSuperiors([$user_id]);
104 }
105
106 return $this->orgu_users[0];
107 }
108
112 public function loadSuperiors(array $user_ids): void
113 {
114 global $DIC;
115
116 $st = $DIC->database()->query($this->getSuperiorsSql($user_ids));
117
118 $empl_id_sup_ids = [];
119 while ($data = $DIC->database()->fetchAssoc($st)) {
120 $org_unit_user = ilOrgUnitUser::getInstanceById($data['empl_usr_id']);
121 $superior = ilOrgUnitUser::getInstance(
122 $data['sup_usr_id'],
123 (string) $data['sup_login'],
124 (string) $data['sup_email'],
125 (string) $data['sup_second_email']
126 );
127 $org_unit_user->addSuperior($superior);
128 }
129 }
130
135 public function getEmailAdressesOfSuperiors(array $user_ids): array
136 {
137 global $DIC;
138
139 $st = $DIC->database()->query($this->getSuperiorsSql($user_ids));
140
141 $arr_email_sup = [];
142 while ($data = $DIC->database()->fetchAssoc($st)) {
143 $arr_email_sup[] = $data['sup_email'];
144 }
145
146 return $arr_email_sup;
147 }
148
153 protected function getSuperiorsSql(array $user_ids): string
154 {
155 global $DIC;
156
157 $sql = "SELECT
158 orgu_ua.orgu_id AS orgu_id,
159 orgu_ua.user_id AS empl_usr_id,
160 orgu_ua2.user_id as sup_usr_id,
161 superior.email as sup_email,
162 superior.second_email as sup_second_email,
163 superior.login as sup_login
164 FROM
165 il_orgu_ua as orgu_ua,
166 il_orgu_ua as orgu_ua2
167 inner join usr_data as superior on superior.usr_id = orgu_ua2.user_id
168 WHERE
169 orgu_ua.orgu_id = orgu_ua2.orgu_id
170 and orgu_ua.user_id <> orgu_ua2.user_id
171 and orgu_ua.position_id = " . \ilOrgUnitPosition::CORE_POSITION_EMPLOYEE . "
172 and orgu_ua2.position_id = " . \ilOrgUnitPosition::CORE_POSITION_SUPERIOR . "
173 AND " . $DIC->database()->in('orgu_ua.user_id', $user_ids, false, 'integer');
174
175 return $sql;
176 }
177
182 public function loadPositions(array $user_ids): array
183 {
187 $positions = [];
188
189 $assignments = ilOrgUnitUserAssignment::where(['user_id' => $user_ids])->get();
190 if (count($assignments) > 0) {
191 foreach ($assignments as $assignment) {
192 $org_unit_user = ilOrgUnitUser::getInstanceById($assignment->getUserId());
193 $org_unit_user->addPositions(ilOrgUnitPosition::find($assignment->getPositionId()));
194 }
195 }
196
197 return $positions;
198 }
199
204 private function loadUsersByUserIds(array $user_ids): array
205 {
206 $users = array();
207
208 $q = "SELECT * FROM usr_data WHERE " . $this->dic->database()->in('usr_id', $user_ids, false, 'int');
209
210 $set = $this->dic->database()->query($q);
211
212 while ($row = $this->dic->database()->fetchAssoc($set)) {
214 $row['usr_id'],
215 (string) $row['login'],
216 (string) $row['email'],
217 (string) $row['second_email']
218 );
219 }
220
221 return $users;
222 }
223}
static where($where, $operator=null)
__construct()
ilOrgUnitUserRepository constructor.
static getInstanceById(int $user_id)
static getInstance(int $user_id, string $login, string $email, string $second_email)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilOrgUnitUserAssignment.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...