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