ILIAS  release_8 Revision v8.24
class.ilOrgUnitUser.php
Go to the documentation of this file.
1<?php
19namespace OrgUnit\User;
20
21use Exception;
22use function PHPUnit\Framework\throwException;
23
25{
27 protected static array $instances;
28 private int $user_id;
29 private string $login;
30 private string $email;
31 private string $second_email;
35 private array $org_unit_positions = [];
39 private array $superiors = [];
40
41 private function __construct(int $user_id, string $login, string $email, string $second_email)
42 {
43 $this->user_id = $user_id;
44 $this->login = $login;
45 $this->email = $email;
46 $this->second_email = $second_email;
47 }
48
52 public static function getInstanceById(int $user_id): self
53 {
54 if (null === static::$instances[$user_id]) {
55 $org_unit_user_repository = new ilOrgUnitUserRepository();
56 $orgUnitUser = $org_unit_user_repository->getOrgUnitUser($user_id);
57 if ($orgUnitUser === null) {
58 throw new Exception('no OrgUnitUser found with user_id ' . $user_id);
59 }
60
61 static::$instances[$user_id] = $org_unit_user_repository->getOrgUnitUser($user_id);
62 }
63
64 return static::$instances[$user_id];
65 }
66
67 public static function getInstance(int $user_id, string $login, string $email, string $second_email): self
68 {
69 if (!isset(static::$instances) ||
70 !array_key_exists($user_id, static::$instances) ||
71 is_null(static::$instances[$user_id])
72 ) {
73 static::$instances[$user_id] = new self($user_id, $login, $email, $second_email);
74 }
75
76 return static::$instances[$user_id];
77 }
78
79
80 public function addSuperior(ilOrgUnitUser $org_unit_user): void
81 {
82 $this->superiors[] = $org_unit_user;
83 }
84
85 public function addPositions(\ilOrgUnitPosition $org_unit_position)
86 {
87 $this->org_unit_positions[] = $org_unit_position;
88 }
89
94 public function getSuperiors(): array
95 {
96 if (count($this->superiors) === 0) {
97 $this->loadSuperiors();
98 }
99
100 return $this->superiors;
101 }
102
103 public function loadSuperiors(): void
104 {
105 $org_unit_user_repository = new ilOrgUnitUserRepository();
106 $org_unit_user_repository->loadSuperiors([$this->user_id]);
107 }
108
113 public function getOrgUnitPositions(): array
114 {
115 if (count($this->org_unit_positions) == 0) {
116 $this->loadOrgUnitPositions();
117 }
118
120 }
121
126 protected function loadOrgUnitPositions(): array
127 {
128 $org_unit_user_repository = new ilOrgUnitUserRepository();
129 $org_unit_user_repository->loadPositions([$this->user_id]);
130 }
131
132 public function getUserId(): int
133 {
134 return $this->user_id;
135 }
136
137 public function getLogin(): string
138 {
139 return $this->login;
140 }
141
142 public function getEmail(): string
143 {
144 return $this->email;
145 }
146
147 public function getSecondEmail(): string
148 {
149 return $this->second_email;
150 }
151
152 public function setSecondEmail(string $second_email): void
153 {
154 $this->second_email = $second_email;
155 }
156}
__construct(int $user_id, string $login, string $email, string $second_email)
static getInstanceById(int $user_id)
addSuperior(ilOrgUnitUser $org_unit_user)
setSecondEmail(string $second_email)
addPositions(\ilOrgUnitPosition $org_unit_position)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...