ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Consumer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilLink;
30use ILIAS\LegalDocuments\Consumer as ConsumerInterface;
32use ilObjUser;
37use Closure;
41
42final class Consumer implements ConsumerInterface
43{
44 public const ID = 'dpro';
45 public const GOTO_NAME = 'data_protection';
46
47 private readonly Container $container;
48
49 public function __construct(?Container $container = null)
50 {
51 $this->container = $container ?? $GLOBALS['DIC'] ?? new Container();
52 }
53
54 public function id(): string
55 {
56 return self::ID;
57 }
58
59 public function uses(UseSlot $slot, LazyProvide $provide): UseSlot
60 {
61 $blocks = new Blocks($this->id(), $this->container, $provide);
62 $default = $blocks->defaultMappings();
63 $global_settings = new Settings($blocks->selectSettingsFrom($blocks->readOnlyStore($blocks->globalStore())));
64 $is_active = $global_settings->enabled()->value();
65 $build_user = fn(ilObjUser $user) => $blocks->user($global_settings, new UserSettings(
66 $blocks->selectSettingsFrom($blocks->userStore($user))
67 ), $user);
68 $public_api = new PublicApi($is_active, $build_user);
69 $slot = $slot->hasDocuments($default->contentAsComponent(), $default->conditionDefinitions())
70 ->hasHistory()
71 ->hasPublicApi($public_api);
72
73 if (!$is_active) {
74 return $slot->hasPublicPage($blocks->notAvailable(...), self::GOTO_NAME);
75 }
76
77 $user = $build_user($this->container->user());
78
79 $slot = $slot->showOnLoginPage($blocks->slot()->showOnLoginPage());
80
81 $agreement = $blocks->slot()->agreement($user);
82 $constraint = $this->container->refinery()->custom()->constraint(...);
83
84 if ($global_settings->noAcceptance()->value()) {
85 $slot = $slot->showInFooter($this->showMatchingDocument($user, $blocks->ui(), $provide))
86 ->hasPublicPage($agreement->showAgreement(...), self::GOTO_NAME);
87 } else {
88 $slot = $slot->canWithdraw($blocks->slot()->withdrawProcess($user, $global_settings, $this->userHasWithdrawn(...)))
89 ->hasAgreement($agreement, self::GOTO_NAME)
90 ->showInFooter($blocks->slot()->modifyFooter($user, self::GOTO_NAME))
91 ->onSelfRegistration($blocks->slot()->selfRegistration($user, $build_user))
92 ->hasOnlineStatusFilter($blocks->slot()->onlineStatusFilter($this->usersWhoDidntAgree($this->container->database())))
93 ->hasUserManagementFields($blocks->userManagementAgreeDateField($build_user, 'dpro_agree_date', 'dpro'))
94 ->canReadInternalMails($blocks->slot()->canReadInternalMails($build_user))
95 ->canUseSoapApi($constraint(fn($u) => !$public_api->needsToAgree($u), 'Data Protection not agreed.'));
96 }
97
98 return $slot;
99 }
100
101 private function showMatchingDocument(User $user, UI $ui, Provide $legal_documents): Closure
102 {
103 return function (Closure $footer) use ($user, $ui, $legal_documents) {
104 $in_footer = fn($v) => $footer('usr_agreement', $ui->txt('usr_agreement'), $v);
105 if (!$user->isLoggedIn()) {
106 return $in_footer(new URI(ilLink::_getLink(null, 'usr', [], self::GOTO_NAME)));
107 }
108 if ($user->cannotAgree()) {
109 return $footer;
110 }
111
112 $render = fn(Document $document): Closure => $in_footer($ui->create()->modal()->roundtrip(
113 $document->content()->title(),
114 [$legal_documents->document()->contentAsComponent($document->content())]
115 ));
116
117 return $user->matchingDocument()
118 ->map($render)
119 ->except(fn() => new Ok($footer))->value();
120 };
121 }
122
123 private function userHasWithdrawn(): void
124 {
125 $this->container['ilAppEventHandler']->raise(
126 'components/ILIAS/DataProtection',
127 'withdraw',
128 ['event' => $this->container->user()]
129 );
130 }
131
132 private function usersWhoDidntAgree(ilDBInterface $database): Closure
133 {
134 return function (array $users) use ($database): array {
135 $users = $database->in('usr_id', $users, false, ilDBConstants::T_INTEGER);
136 $result = $database->query(
137 'SELECT usr_id FROM usr_pref WHERE keyword = "dpro_agree_date" AND (value IS NULL OR value = "false" OR value = "") AND ' . $users
138 );
139
140 return array_map(intval(...), array_column($database->fetchAll($result), 'usr_id'));
141 };
142 }
143}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
uses(UseSlot $slot, LazyProvide $provide)
@template A
Definition: Consumer.php:59
__construct(?Container $container=null)
Definition: Consumer.php:49
usersWhoDidntAgree(ilDBInterface $database)
Definition: Consumer.php:132
readonly Container $container
Definition: Consumer.php:47
showMatchingDocument(User $user, UI $ui, Provide $legal_documents)
Definition: Consumer.php:101
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Class ilDBConstants.
User class.
showInFooter(callable $show)
hasPublicPage(callable $public_page, ?string $goto_name=null)
hasDocuments(array $content_as_component=[], ?SelectionMap $available_conditions=null)
canWithdraw(WithdrawProcess $withdraw_process)
showOnLoginPage(callable $show)
Interface ilDBInterface.
fetchAll(ilDBStatement $statement, int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
query(string $query)
Run a (read-only) Query on the database.
in(string $field, array $values, bool $negate=false, string $type="")
$GLOBALS["DIC"]
Definition: wac.php:54