ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjForumAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 {
30  private \ILIAS\DI\RBACServices $rbac;
32 
33  public function __construct($a_data, int $a_id, bool $a_call_by_reference = true, bool $a_prepare_output = true)
34  {
38  global $DIC;
39 
40  $this->rbac = $DIC->rbac();
41  $this->cronManager = $DIC->cron()->manager();
42 
43  $this->type = 'frma';
44  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
45  $this->lng->loadLanguageModule('forum');
46  }
47 
48  public function executeCommand(): void
49  {
50  if (!$this->rbac->system()->checkAccess('visible,read', $this->object->getRefId())) {
51  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
52  }
53 
54  $next_class = $this->ctrl->getNextClass($this);
55  $cmd = $this->ctrl->getCmd();
56 
57  $this->prepareOutput();
58 
59  switch ($next_class) {
60  case 'ilpermissiongui':
61  $this->tabs_gui->setTabActive('perm_settings');
62  $this->ctrl->forwardCommand(new ilPermissionGUI($this));
63  break;
64 
65  default:
66  if (!$cmd || $cmd === 'view') {
67  $cmd = 'editSettings';
68  }
69 
70  $this->$cmd();
71  break;
72  }
73  }
74 
75  public function getAdminTabs(): void
76  {
77  if ($this->rbac->system()->checkAccess('visible,read', $this->object->getRefId())) {
78  $this->tabs_gui->addTarget(
79  'settings',
80  $this->ctrl->getLinkTarget($this, 'editSettings'),
81  ['editSettings', 'view']
82  );
83  }
84 
85  if ($this->rbac->system()->checkAccess('edit_permission', $this->object->getRefId())) {
86  $this->tabs_gui->addTarget(
87  'perm_settings',
88  $this->ctrl->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
89  [],
90  'ilpermissiongui'
91  );
92  }
93  }
94 
95  public function editSettings(ilPropertyFormGUI $form = null): void
96  {
97  $this->tabs_gui->activateTab('settings');
98 
99  if (!$form) {
100  $form = $this->getSettingsForm();
101  $this->populateForm($form);
102  }
103 
104  $this->tpl->setContent($form->getHTML());
105  }
106 
107  public function saveSettings(): void
108  {
109  $this->checkPermission("write");
110 
111  $form = $this->getSettingsForm();
112  if (!$form->checkInput()) {
113  $form->setValuesByPost();
114  $this->editSettings($form);
115  return;
116  }
117 
118  $frma_set = new ilSetting('frma');
119  $frma_set->set('forum_overview', (string) $form->getInput('forum_overview'));
120  $this->settings->set('file_upload_allowed_fora', (string) ((int) $form->getInput('file_upload_allowed_fora')));
121  $this->settings->set('send_attachments_by_mail', (string) ((int) $form->getInput('send_attachments_by_mail')));
122  $this->settings->set('enable_fora_statistics', (string) ((int) $form->getInput('fora_statistics')));
123  $this->settings->set('enable_anonymous_fora', (string) ((int) $form->getInput('anonymous_fora')));
124 
125  if (!$this->cronManager->isJobActive('frm_notification')) {
126  $this->settings->set('forum_notification', (string) ((int) $form->getInput('forum_notification')));
127  }
128 
129  $this->settings->set('save_post_drafts', (string) ((int) $form->getInput('save_post_drafts')));
130  $this->settings->set('autosave_drafts', (string) ((int) $form->getInput('autosave_drafts')));
131  $this->settings->set('autosave_drafts_ival', (string) ((int) $form->getInput('autosave_drafts_ival')));
132 
133  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
134  $form->setValuesByPost();
135  $this->editSettings($form);
136  }
137 
138  protected function populateForm(ilPropertyFormGUI $form): void
139  {
140  $frma_set = new ilSetting('frma');
141 
142  $form->setValuesByArray([
143  'forum_overview' => (string) $frma_set->get('forum_overview', (string) ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS),
144  'fora_statistics' => (bool) $this->settings->get('enable_fora_statistics'),
145  'anonymous_fora' => (bool) $this->settings->get('enable_anonymous_fora'),
146  'forum_notification' => (int) $this->settings->get('forum_notification', '0') === 1,
147  'file_upload_allowed_fora' => (int) $this->settings->get(
148  'file_upload_allowed_fora',
150  ),
151  'save_post_drafts' => (int) $this->settings->get('save_post_drafts', '0'),
152  'autosave_drafts' => (int) $this->settings->get('autosave_drafts', '0'),
153  'autosave_drafts_ival' => (int) $this->settings->get('autosave_drafts_ival', '30'),
154  'send_attachments_by_mail' => (bool) $this->settings->get('send_attachments_by_mail')
155  ]);
156  }
157 
158  protected function getSettingsForm(): ilPropertyFormGUI
159  {
160  $form = new ilPropertyFormGUI();
161  $form->setFormAction($this->ctrl->getFormAction($this, 'saveSettings'));
162  $form->setTitle($this->lng->txt('settings'));
163 
164  $frm_radio = new ilRadioGroupInputGUI($this->lng->txt('frm_displayed_infos'), 'forum_overview');
165  $frm_radio->addOption(new ilRadioOption(
166  $this->lng->txt('frm_all_postings_stats') . ', ' . $this->lng->txt('unread') . ', ' . $this->lng->txt('new'),
168  ));
169  $frm_radio->addOption(new ilRadioOption(
170  $this->lng->txt('frm_all_postings_stats') . ', ' . $this->lng->txt('unread'),
172  ));
173  $frm_radio->setInfo($this->lng->txt('frm_disp_info_desc'));
174  $form->addItem($frm_radio);
175 
176  $check = new ilCheckboxInputGUI($this->lng->txt('enable_fora_statistics'), 'fora_statistics');
177  $check->setInfo($this->lng->txt('enable_fora_statistics_desc'));
178  $form->addItem($check);
179 
180  $check = new ilCheckboxInputGUI($this->lng->txt('enable_anonymous_fora'), 'anonymous_fora');
181  $check->setInfo($this->lng->txt('enable_anonymous_fora_desc'));
182  $form->addItem($check);
183 
184  $file_upload = new ilRadioGroupInputGUI(
185  $this->lng->txt('file_upload_allowed_fora'),
186  'file_upload_allowed_fora'
187  );
188  $option_all_forums = new ilRadioOption(
189  $this->lng->txt('file_upload_option_allow'),
191  $this->lng->txt('file_upload_option_allow_info')
192  );
193  $file_upload->addOption($option_all_forums);
194 
195  $option_per_forum = new ilRadioOption(
196  $this->lng->txt('file_upload_option_disallow'),
198  $this->lng->txt('file_upload_allowed_fora_desc')
199  );
200  $file_upload->addOption($option_per_forum);
201 
202  $form->addItem($file_upload);
203 
204  if ($this->cronManager->isJobActive('frm_notification')) {
207  $form,
208  $this
209  );
210  } else {
211  $notifications = new ilCheckboxInputGUI($this->lng->txt('cron_forum_notification'), 'forum_notification');
212  $notifications->setInfo($this->lng->txt('cron_forum_notification_desc'));
213  $notifications->setValue('1');
214  $form->addItem($notifications);
215  }
216 
217  $check = new ilCheckboxInputGUI($this->lng->txt('enable_send_attachments'), 'send_attachments_by_mail');
218  $check->setInfo($this->lng->txt('enable_send_attachments_desc'));
219  $check->setValue('1');
220  $form->addItem($check);
221 
222  $drafts = new ilCheckboxInputGUI($this->lng->txt('adm_save_drafts'), 'save_post_drafts');
223  $drafts->setInfo($this->lng->txt('adm_save_drafts_desc'));
224  $drafts->setValue('1');
225 
226  $autosave_drafts = new ilCheckboxInputGUI($this->lng->txt('adm_autosave_drafts'), 'autosave_drafts');
227  $autosave_drafts->setInfo($this->lng->txt('adm_autosave_drafts_desc'));
228  $autosave_drafts->setValue('1');
229 
230  $autosave_interval = new ilNumberInputGUI($this->lng->txt('adm_autosave_ival'), 'autosave_drafts_ival');
231  $autosave_interval->allowDecimals(false);
232  $autosave_interval->setMinValue(30);
233  $autosave_interval->setMaxValue(60 * 60);
234  $autosave_interval->setSize(10);
235  $autosave_interval->setRequired(true);
236  $autosave_interval->setSuffix($this->lng->txt('seconds'));
237  $autosave_drafts->addSubItem($autosave_interval);
238  $drafts->addSubItem($autosave_drafts);
239  $form->addItem($drafts);
240 
241  if ($this->checkPermissionBool('write')) {
242  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
243  }
244 
245  return $form;
246  }
247 
248  public function addToExternalSettingsForm(int $a_form_id): array
249  {
250  switch ($a_form_id) {
252 
253  $fields = [
254  'enable_fora_statistics' => [
255  (bool) $this->settings->get('enable_fora_statistics', '0'),
257  ],
258  'enable_anonymous_fora' => [
259  (bool) $this->settings->get('enable_anonymous_fora', '0'),
261  ]
262  ];
263 
264  return [['editSettings', $fields]];
265 
266  }
267  return [];
268  }
269 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct($data, int $id=0, bool $call_by_reference=true, bool $prepare_output=true)
prepareOutput(bool $show_sub_objects=true)
This class represents a checkbox property in a property form.
addOption(ilRadioOption $a_option)
global $DIC
Definition: feed.php:28
allowDecimals(bool $a_value)
This class represents a property in a property form.
editSettings(ilPropertyFormGUI $form=null)
This class represents a number property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
__construct(Container $dic, ilPlugin $plugin)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
$check
Definition: buildRTE.php:81
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)