ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
UserSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\TermsOfService;
22 
25 use ilObjUser;
31 
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 }
__construct(private readonly ilObjUser $user, private readonly SelectSetting $user_pref, private readonly Refinery $refinery)