ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PublicApi.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 use ilObjUser;
27 use WeakMap;
28 use Closure;
29 
30 class PublicApi implements PublicApiInterface
31 {
35  private readonly WeakMap $cache;
36 
37  public function __construct(private readonly bool $active, private readonly Closure $build_user)
38  {
39  $this->cache = new WeakMap();
40  }
41 
46  public function active(): bool
47  {
48  return $this->active;
49  }
50 
51  public function agreed(ilObjUser $user): bool
52  {
53  return $this->everAgreed($user);
54  }
55 
56  public function agreedToCurrentlyMatchingDocument(ilObjUser $user): bool
57  {
58  return !$this->user($user)->needsToAcceptNewDocument();
59  }
60 
61  public function everAgreed(ilObjUser $user): bool
62  {
63  return !$this->user($user)->neverAgreed();
64  }
65 
66  public function canAgree(ilObjUser $user): bool
67  {
68  return !$this->user($user)->cannotAgree();
69  }
70 
71  public function needsToAgree(ilObjUser $user): bool
72  {
73  return $this->canAgree($user)
74  && $this->user($user)->needsToAcceptNewDocument();
75  }
76 
77  public function agreeDate(ilObjUser $user): ?DateTimeImmutable
78  {
79  return $this->user($user)->agreeDate()->value();
80  }
81 
82  private function user(ilObjUser $user): User
83  {
84  if (!isset($this->cache[$user])) {
85  $this->cache[$user] = ($this->build_user)($user);
86  }
87 
88  return $this->cache[$user];
89  }
90 }
active()
Returns wether or not the corresponding consumer is active.
Definition: PublicApi.php:46
__construct(private readonly bool $active, private readonly Closure $build_user)
Definition: PublicApi.php:37