ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMailOptionsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  private readonly ilGlobalTemplateInterface $tpl;
27  private readonly ilCtrlInterface $ctrl;
28  private readonly ilLanguage $lng;
29  private readonly ilSetting $settings;
30  private readonly ilObjUser $user;
32  protected Refinery $refinery;
35 
36  public function __construct(
38  ?ilCtrlInterface $ctrl = null,
39  ?ilLanguage $lng = null,
40  ?ilObjUser $user = null,
41  ?GlobalHttpState $http = null,
42  ?Refinery $refinery = null,
43  ?ilMailOptions $mail_options = null
44  ) {
45  global $DIC;
46  $this->tpl = $tpl ?? $DIC->ui()->mainTemplate();
47  $this->ctrl = $ctrl ?? $DIC->ctrl();
48  $this->lng = $lng ?? $DIC->language();
49  $this->user = $user ?? $DIC->user();
50  $this->http = $http ?? $DIC->http();
51  $this->refinery = $refinery ?? $DIC->refinery();
52  $this->mail_options = $mail_options ?? new ilMailOptions($this->user->getId());
53 
54  $this->lng->loadLanguageModule('mail');
55  $this->ctrl->saveParameter($this, 'mobj_id');
56  }
57 
58  public function executeCommand(): void
59  {
60  if (!$this->mail_options->mayManageInvididualSettings()) {
61  $referrer = '';
62  if ($this->http->wrapper()->query()->has('referrer')) {
63  $referrer = $this->http->wrapper()->query()->retrieve(
64  'referrer',
65  $this->refinery->kindlyTo()->string()
66  );
67  }
68  if (strtolower(ilPersonalSettingsGUI::class) === strtolower((string) $referrer)) {
69  $this->ctrl->redirectByClass(ilPersonalSettingsGUI::class);
70  }
71  $this->ctrl->redirectByClass(ilMailGUI::class);
72  }
73 
74  if (!($cmd = $this->ctrl->getCmd())) {
75  $cmd = 'showOptions';
76  }
77  $this->$cmd();
78  }
79 
80  public function setForm(ilMailOptionsFormGUI $form): void
81  {
82  $this->form = $form;
83  }
84 
85  protected function getForm(): ilMailOptionsFormGUI
86  {
87  return $this->form ?? new ilMailOptionsFormGUI(
88  $this->mail_options,
89  $this,
90  'saveOptions'
91  );
92  }
93 
94  protected function saveOptions(): void
95  {
96  $this->tpl->setTitle($this->lng->txt('mail'));
97 
98  $form = $this->getForm();
99  if ($form->save()) {
100  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_options_saved'), true);
101  $this->ctrl->redirect($this, 'showOptions');
102  }
103 
104  $this->showOptions($form);
105  }
106 
107  protected function showOptions(?ilMailOptionsFormGUI $form = null): void
108  {
109  if (null === $form) {
110  $form = $this->getForm();
111  $form->populate();
112  } else {
113  $form->setValuesByPost();
114  }
115 
116  $this->tpl->setContent($form->getHTML());
117  $this->tpl->printToStdout();
118  }
119 }
ilMailOptionsFormGUI $form
setForm(ilMailOptionsFormGUI $form)
readonly ilCtrlInterface $ctrl
__construct(?ilGlobalTemplateInterface $tpl=null, ?ilCtrlInterface $ctrl=null, ?ilLanguage $lng=null, ?ilObjUser $user=null, ?GlobalHttpState $http=null, ?Refinery $refinery=null, ?ilMailOptions $mail_options=null)
readonly ilGlobalTemplateInterface $tpl
readonly ilLanguage $lng
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
readonly ilSetting $settings
global $DIC
Definition: shib_login.php:26
form( $class_path, string $cmd, string $submit_caption="")
showOptions(?ilMailOptionsFormGUI $form=null)
readonly ilObjUser $user