ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NewMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\Refinery\Factory as Refinery;
30
32{
34 private array $mail_options_by_user = [];
35
36 public function getIdentifier(): string
37 {
38 return 'new_mail_notification';
39 }
40
41 public function isAvailable(): bool
42 {
43 $settings = new \ilSetting();
44
45 return
46 $settings->get('mail_notification') === '1' &&
47 $settings->get('show_mail_settings') === '1';
48 }
49
50 public function getLabel(Language $lng): string
51 {
52 return $lng->txt('cron_mail_notification');
53 }
54
56 {
57 return AvailablePages::MainSettings;
58 }
59
60 public function getSection(): AvailableSections
61 {
62 return AvailableSections::Communication;
63 }
64
65 public function getInput(
66 FieldFactory $field_factory,
69 \ilSetting $settings,
70 ?\ilObjUser $user = null
71 ): Input {
72 $lng->loadLanguageModule('mail');
73
74 return $field_factory->checkbox(
75 $this->getLabel($lng),
76 $lng->txt('mail_cronjob_notification_info')
77 )->withValue(
78 $user !== null && $this->retrieveValueFromUser($user)
79 );
80 }
81
82 public function getLegacyInput(
84 \ilSetting $settings,
85 ?\ilObjUser $user = null
87 $lng->loadLanguageModule('mail');
88
89 $input = new \ilCheckboxInputGUI($this->getLabel($lng));
90 $input->setInfo($lng->txt('mail_cronjob_notification_info'));
91 $input->setChecked(
92 $user !== null && $this->retrieveValueFromUser($user)
93 );
94 $input->setValue('1');
95
96 return $input;
97 }
98
101 \ilSetting $settings
102 ): string {
103 return $lng->txt('no');
104 }
105
107 \ilSetting $settings,
108 \ilObjUser $user
109 ): bool {
110 $value = $this->retrieveValueFromUser($user);
111 return $value !== false;
112 }
113
114 public function persistUserInput(
115 \ilObjUser $user,
116 mixed $input,
117 ?\ilPropertyFormGUI $form = null
118 ): \ilObjUser {
119 $mail_options = $this->mailOptionsFor($user);
120 $mail_options->setIsCronJobNotificationStatus($input === true || $input === '1');
121 $mail_options->updateOptions();
122
123 return $user;
124 }
125
126 public function retrieveValueFromUser(\ilObjUser $user): bool
127 {
128 return $this->mailOptionsFor($user)->isCronJobNotificationEnabled();
129 }
130
131 private function mailOptionsFor(\ilObjUser $user): \ilMailOptions
132 {
133 if (!\array_key_exists($user->getId(), $this->mail_options_by_user)) {
134 $this->mail_options_by_user[$user->getId()] = new \ilMailOptions($user->getId());
135 }
136
137 return $this->mail_options_by_user[$user->getId()];
138 }
139}
Builds data types.
Definition: Factory.php:36
hasUserPersonalizedSetting(\ilSetting $settings, \ilObjUser $user)
getDefaultValueForDisplay(Language $lng, \ilSetting $settings)
persistUserInput(\ilObjUser $user, mixed $input, ?\ilPropertyFormGUI $form=null)
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
This class represents a property in a property form.
User class.
This class represents a property form user interface.
ILIAS Setting Class.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
global $lng
Definition: privfeed.php:31