ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UserSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\TermsOfService;
22
23use ILIAS\LegalDocuments\ConsumerToolbox\UserSettings as UserSettingsInterface;
25use ilObjUser;
29use ILIAS\Refinery\Factory as Refinery;
30use DateTimeImmutable;
31
32class UserSettings implements UserSettingsInterface
33{
34 public function __construct(
35 private readonly ilObjUser $user,
36 private readonly SelectSetting $user_pref,
37 private readonly Refinery $refinery
38 ) {
39 }
40
44 public function withdrawalRequested(): Setting
45 {
46 return $this->user_pref->typed('consent_withdrawal_requested', fn(Marshal $m) => $m->boolean());
47 }
48
52 public function agreeDate(): Setting
53 {
54 return $this->setting($this->convert());
55 }
56
57 private function setting(Convert $convert): Setting
58 {
59 return new Setting(
60 fn() => $convert->fromString()->transform($this->user->getAgreeDate()),
61 function ($value) use ($convert): void {
62 $this->user->setAgreeDate($convert->toString()->transform($value));
63 $this->user->update();
64 }
65 );
66 }
67
68 private function convert(): Convert
69 {
70 $custom = $this->refinery->custom()->transformation(...);
71 $null_or = fn($next) => $this->refinery->byTrying([$this->refinery->null(), $next]);
72
73 return new Convert(
74 $null_or($this->refinery->to()->dateTime()),
75 $null_or($custom(fn(DateTimeImmutable $d): string => $d->format('Y-m-d H:i:s')))
76 );
77 }
78}
Builds data types.
Definition: Factory.php:36
__construct(private readonly ilObjUser $user, private readonly SelectSetting $user_pref, private readonly Refinery $refinery)
User class.