ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailOptionsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
29 {
32  private ilLanguage $lng;
34  private ilObjUser $user;
36  protected Refinery $refinery;
39 
40  public function __construct(
41  ilGlobalTemplateInterface $tpl = null,
42  ilCtrlInterface $ctrl = null,
43  ilLanguage $lng = null,
44  ilObjUser $user = null,
45  GlobalHttpState $http = null,
46  Refinery $refinery = null,
47  ilMailOptions $mail_options = null
48  ) {
49  global $DIC;
50  $this->tpl = $tpl ?? $DIC->ui()->mainTemplate();
51  $this->ctrl = $ctrl ?? $DIC->ctrl();
52  $this->lng = $lng ?? $DIC->language();
53  $this->user = $user ?? $DIC->user();
54  $this->http = $http ?? $DIC->http();
55  $this->refinery = $refinery ?? $DIC->refinery();
56  $this->mail_options = $mail_options ?? new ilMailOptions($this->user->getId());
57 
58  $this->lng->loadLanguageModule('mail');
59  $this->ctrl->saveParameter($this, 'mobj_id');
60  }
61 
62  public function executeCommand(): void
63  {
64  if (!$this->mail_options->mayManageInvididualSettings()) {
65  $referrer = '';
66  if ($this->http->wrapper()->query()->has('referrer')) {
67  $referrer = $this->http->wrapper()->query()->retrieve(
68  'referrer',
69  $this->refinery->kindlyTo()->string()
70  );
71  }
72  if (strtolower(ilPersonalSettingsGUI::class) === strtolower($referrer)) {
73  $this->ctrl->redirectByClass(ilPersonalSettingsGUI::class);
74  }
75  $this->ctrl->redirectByClass(ilMailGUI::class);
76  }
77 
78  $nextClass = $this->ctrl->getNextClass($this);
79  switch ($nextClass) {
80  default:
81  if (!($cmd = $this->ctrl->getCmd())) {
82  $cmd = 'showOptions';
83  }
84 
85  $this->$cmd();
86  break;
87  }
88  }
89 
90  public function setForm(ilMailOptionsFormGUI $form): void
91  {
92  $this->form = $form;
93  }
94 
95  protected function getForm(): ilMailOptionsFormGUI
96  {
97  return $this->form ?? new ilMailOptionsFormGUI(
98  $this->mail_options,
99  $this,
100  'saveOptions'
101  );
102  }
103 
104  protected function saveOptions(): void
105  {
106  $this->tpl->setTitle($this->lng->txt('mail'));
107 
108  $form = $this->getForm();
109  if ($form->save()) {
110  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_options_saved'), true);
111  $this->ctrl->redirect($this, 'showOptions');
112  }
113 
114  $this->showOptions($form);
115  }
116 
117  protected function showOptions(ilMailOptionsFormGUI $form = null): void
118  {
119  if (null === $form) {
120  $form = $this->getForm();
121  $form->populate();
122  } else {
123  $form->setValuesByPost();
124  }
125 
126  $this->tpl->setContent($form->getHTML());
127  $this->tpl->printToStdout();
128  }
129 }
Interface GlobalHttpState.
Class ilMailOptions this class handles user mails.
ilMailOptionsFormGUI $form
setForm(ilMailOptionsFormGUI $form)
showOptions(ilMailOptionsFormGUI $form=null)
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
Class ilMailOptionsFormGUI.
ilGlobalTemplateInterface $tpl
__construct(ilGlobalTemplateInterface $tpl=null, ilCtrlInterface $ctrl=null, ilLanguage $lng=null, ilObjUser $user=null, GlobalHttpState $http=null, Refinery $refinery=null, ilMailOptions $mail_options=null)
form( $class_path, string $cmd)