ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Consumer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ilDBConstants;
24 use ilDBInterface;
28 use ilObjUser;
31 use Closure;
33 
34 class Consumer implements ConsumerInterface
35 {
36  private readonly Container $container;
37 
38  public const ID = 'tos';
39  public const GOTO_NAME = 'agreement';
40 
41  public function __construct(?Container $container = null)
42  {
43  $this->container = $container ?? $GLOBALS['DIC'] ?? new Container();
44  }
45 
46  public function id(): string
47  {
48  return self::ID;
49  }
50 
51  public function uses(UseSlot $slot, LazyProvide $provide): UseSlot
52  {
53  $blocks = new Blocks($this->id(), $this->container, $provide);
54  $default = $blocks->defaultMappings();
55  $global_settings = new Settings($blocks->selectSettingsFrom($blocks->readOnlyStore($blocks->globalStore())));
56  $is_active = $global_settings->enabled()->value();
57  $build_user = fn(ilObjUser $user) => $blocks->user($global_settings, new UserSettings($user, $blocks->selectSettingsFrom(
58  $blocks->userStore($user)
59  ), $this->container->refinery()), $user);
60  $public_api = new PublicApi($is_active, $build_user);
61  $slot = $slot->hasDocuments($default->contentAsComponent(), $default->conditionDefinitions())
62  ->hasHistory()
63  ->hasPublicApi($public_api);
64 
65  if (!$is_active) {
66  return $slot->hasPublicPage($blocks->notAvailable(...), self::GOTO_NAME);
67  }
68 
69  $user = $build_user($this->container->user());
70  $constraint = $this->container->refinery()->custom()->constraint(...);
71 
72  return $slot->canWithdraw($blocks->slot()->withdrawProcess($user, $global_settings, $this->userHasWithdrawn(...)))
73  ->hasAgreement($blocks->slot()->agreement($user), self::GOTO_NAME)
74  ->showInFooter($blocks->slot()->modifyFooter($user, self::GOTO_NAME))
75  ->showOnLoginPage($blocks->slot()->showOnLoginPage())
76  ->onSelfRegistration($blocks->slot()->selfRegistration($user, $build_user))
77  ->hasOnlineStatusFilter($blocks->slot()->onlineStatusFilter($this->usersWhoDidntAgree($this->container->database())))
78  ->hasUserManagementFields($blocks->userManagementAgreeDateField($build_user, 'tos_agree_date', 'tos'))
79  ->canReadInternalMails($blocks->slot()->canReadInternalMails($build_user))
80  ->canUseSoapApi($constraint(fn($u) => !$public_api->needsToAgree($u), 'TOS not accepted.'));
81  }
82 
83  private function userHasWithdrawn(): void
84  {
85  $this->container['ilAppEventHandler']->raise(
86  'components/ILIAS/TermsOfService',
87  'withdraw',
88  ['event' => $this->container->user()]
89  );
90  }
91 
92  private function usersWhoDidntAgree(ilDBInterface $database): Closure
93  {
94  return function (array $users) use ($database): array {
95  $users = $database->in('usr_id', $users, false, ilDBConstants::T_INTEGER);
96  $result = $database->query('SELECT usr_id FROM usr_data WHERE agree_date IS NULL AND ' . $users);
97 
98  return array_map(intval(...), array_column($database->fetchAll($result), 'usr_id'));
99  };
100  }
101 }
uses(UseSlot $slot, LazyProvide $provide)
A
Definition: Consumer.php:51
fetchAll(ilDBStatement $statement, int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
canWithdraw(WithdrawProcess $withdraw_process)
$GLOBALS["DIC"]
Definition: wac.php:53
readonly Container $container
Definition: Consumer.php:36
usersWhoDidntAgree(ilDBInterface $database)
Definition: Consumer.php:92
query(string $query)
Run a (read-only) Query on the database.
in(string $field, array $values, bool $negate=false, string $type="")
__construct(?Container $container=null)
Definition: Consumer.php:41
hasPublicPage(callable $public_page, ?string $goto_name=null)
hasDocuments(array $content_as_component=[], ?SelectionMap $available_conditions=null)