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