ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilOrgUnitUserRepository.php
Go to the documentation of this file.
1<?php
2
19namespace OrgUnit\User;
20
23
29{
30 protected \ILIAS\DI\Container $dic;
31 protected \ilOrgUnitPositionDBRepository $positionRepo;
32
36 protected static array $instance;
40 protected array $orgu_users;
41 protected bool $with_superiors = false;
42 protected bool $with_positions = false;
43 protected \ilOrgUnitUserAssignmentDBRepository $assignmentRepo;
44
48 public function __construct()
49 {
50 global $DIC;
51 $this->dic = $DIC;
52 }
53
55 {
56 if (!isset($this->positionRepo)) {
58 $this->positionRepo = $dic["repo.Positions"];
59 }
60
62 }
63
65 {
66 if (!isset($this->assignmentRepo)) {
68 $this->assignmentRepo = $dic["repo.UserAssignments"];
69 }
70
72 }
73
78 {
79 $this->with_superiors = true;
80
81 return $this;
82 }
83
88 {
89 $this->with_positions = true;
90
91 return $this;
92 }
93
98 public function getOrgUnitUsers(array $arr_user_id): array
99 {
100 $this->orgu_users = $this->loadUsersByUserIds($arr_user_id);
101
102 if ($this->with_superiors === true) {
103 $this->loadSuperiors($arr_user_id);
104 }
105
106 if ($this->with_positions === true) {
107 $this->loadPositions($arr_user_id);
108 }
109
110 return $this->orgu_users;
111 }
112
117 public function getOrgUnitUser(int $user_id): ?ilOrgUnitUser
118 {
119 $this->orgu_users = $this->loadUsersByUserIds([$user_id]);
120
121 if (count($this->orgu_users) == 0) {
122 return null;
123 }
124
125 if ($this->with_superiors === true) {
126 $this->loadSuperiors([$user_id]);
127 }
128
129 return $this->orgu_users[0];
130 }
131
135 public function loadSuperiors(array $user_ids): void
136 {
137 global $DIC;
138
139 $st = $DIC->database()->query($this->getSuperiorsSql($user_ids));
140
141 $empl_id_sup_ids = [];
142 while ($data = $DIC->database()->fetchAssoc($st)) {
143 $org_unit_user = ilOrgUnitUser::getInstanceById($data['empl_usr_id']);
144 $superior = ilOrgUnitUser::getInstance(
145 $data['sup_usr_id'],
146 (string) $data['sup_login'],
147 (string) $data['sup_email'],
148 (string) $data['sup_second_email']
149 );
150 $org_unit_user->addSuperior($superior);
151 }
152 }
153
158 public function getEmailAdressesOfSuperiors(array $user_ids): array
159 {
160 global $DIC;
161
162 $st = $DIC->database()->query($this->getSuperiorsSql($user_ids));
163
164 $arr_email_sup = [];
165 while ($data = $DIC->database()->fetchAssoc($st)) {
166 $arr_email_sup[] = $data['sup_email'];
167 }
168
169 return $arr_email_sup;
170 }
171
176 protected function getSuperiorsSql(array $user_ids): string
177 {
178 global $DIC;
179
180 $sql = "SELECT
181 orgu_ua.orgu_id AS orgu_id,
182 orgu_ua.user_id AS empl_usr_id,
183 orgu_ua2.user_id as sup_usr_id,
184 superior.email as sup_email,
185 superior.second_email as sup_second_email,
186 superior.login as sup_login
187 FROM
188 il_orgu_ua as orgu_ua,
189 il_orgu_ua as orgu_ua2
190 inner join usr_data as superior on superior.usr_id = orgu_ua2.user_id
191 WHERE
192 orgu_ua.orgu_id = orgu_ua2.orgu_id
193 and orgu_ua.user_id <> orgu_ua2.user_id
194 and orgu_ua.position_id = " . \ilOrgUnitPosition::CORE_POSITION_EMPLOYEE . "
195 and orgu_ua2.position_id = " . \ilOrgUnitPosition::CORE_POSITION_SUPERIOR . "
196 AND " . $DIC->database()->in('orgu_ua.user_id', $user_ids, false, 'integer');
197
198 return $sql;
199 }
200
201 public function loadPositions(array $user_ids): void
202 {
203 $assignments = $this->getAssignmentRepo()
204 ->getByUsers($user_ids);
205 foreach ($assignments as $assignment) {
206 $org_unit_user = ilOrgUnitUser::getInstanceById($assignment->getUserId());
207 $org_unit_user->addPositions($this->getPositionRepo()->getSingle($assignment->getPositionId(), 'id'));
208 }
209 }
210
215 private function loadUsersByUserIds(array $user_ids): array
216 {
217 $users = array();
218
219 $q = "SELECT * FROM usr_data WHERE " . $this->dic->database()->in('usr_id', $user_ids, false, 'int');
220
221 $set = $this->dic->database()->query($q);
222
223 while ($row = $this->dic->database()->fetchAssoc($set)) {
225 $row['usr_id'],
226 (string) $row['login'],
227 (string) $row['email'],
228 (string) $row['second_email']
229 );
230 }
231
232 return $users;
233 }
234}
__construct()
ilOrgUnitUserRepository constructor.
ilOrgUnitUserAssignmentDBRepository $assignmentRepo
static getInstanceById(int $user_id)
static getInstance(int $user_id, string $login, string $email, string $second_email)
Class ilOrgUnitPosition.
Class ilOrgUnitUserAssignment.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23