ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilRTESettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 {
31 
32  public function __construct(
33  private readonly int $ref_id,
34  private readonly ilGlobalTemplateInterface $tpl,
35  private readonly ilCtrlInterface $ctrl,
36  private readonly Language $lng,
37  private readonly ilAccessHandler $access,
38  ilObjUser $current_user,
39  ilTabsGUI $tabs_gui
40  ) {
41  $this->settings = new ilRTESettings($this->lng, $current_user);
42  $this->addSubTabs($tabs_gui);
43  }
44 
45  private function addSubtabs(ilTabsGUI $tabs_gui): void
46  {
47  $tabs_gui->addSubTabTarget(
48  'adve_general_settings',
49  $this->ctrl->getLinkTargetByClass([ilObjAdvancedEditingGUI::class, self::class], 'settings'),
50  ['settings', 'saveSettings'],
51  '',
52  ''
53  );
54  $tabs_gui->addSubTabTarget(
55  'adve_assessment_settings',
56  $this->ctrl->getLinkTargetByClass([ilObjAdvancedEditingGUI::class, self::class], 'assessment'),
57  ['assessment', 'saveAssessmentSettings'],
58  '',
59  ''
60  );
61  $tabs_gui->addSubTabTarget(
62  'adve_frm_post_settings',
63  $this->ctrl->getLinkTargetByClass([ilObjAdvancedEditingGUI::class, self::class], 'frmPost'),
64  ['frmPost', 'saveFrmPostSettings'],
65  '',
66  ''
67  );
68  }
69 
70  public function settings(): void
71  {
72  $tpl = $this->tpl;
73  $form = $this->getTinyForm();
74  $tpl->setContent($form->getHTML());
75  }
76 
77  public function getTinyForm(): ilPropertyFormGUI
78  {
79  $form = new ilPropertyFormGUI();
80  $form->setFormAction($this->ctrl->getFormAction($this));
81  $form->setTitle($this->lng->txt("adve_activation"));
82  $cb = new ilCheckboxInputGUI($this->lng->txt("adve_use_tiny_mce"), "use_tiny");
83  if ($this->settings->getRichTextEditor() === "tinymce") {
84  $cb->setChecked(true);
85  }
86  $form->addItem($cb);
87  if ($this->access->checkAccess('write', '', $this->ref_id)) {
88  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
89  }
90 
91  return $form;
92  }
93 
94  public function saveSettings(): void
95  {
96  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
97  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_read'), true);
98  return;
99  }
100 
101  $form = $this->getTinyForm();
102  $form->checkInput();
103 
104  if ($form->getInput('use_tiny')) {
105  $this->settings->setRichTextEditor('tinymce');
106  } else {
107  $this->settings->setRichTextEditor('');
108  }
109  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
110 
111  $this->ctrl->redirect($this, 'settings');
112  }
113 
114  public function assessment(): void
115  {
116  $form = $this->initTagsForm(
117  "assessment",
118  "saveAssessmentSettings",
119  "advanced_editing_assessment_settings"
120  );
121 
122  $this->tpl->setContent($form->getHTML());
123  }
124 
125  public function saveAssessmentSettings(): void
126  {
127  $form = $this->initTagsForm(
128  "assessment",
129  "saveAssessmentSettings",
130  "advanced_editing_assessment_settings"
131  );
132  if (!$this->saveTags("assessment", "assessment", $form)) {
133  $form->setValuesByPost();
134  $this->tpl->setContent($form->getHTML());
135  }
136  }
137 
138  public function frmPost(): void
139  {
140  $form = $this->initTagsForm(
141  "frm_post",
142  "saveFrmPostSettings",
143  "advanced_editing_frm_post_settings"
144  );
145 
146  $this->tpl->setContent($form->getHTML());
147  }
148 
149  public function saveFrmPostSettings(): void
150  {
151  $form = $this->initTagsForm(
152  "frm_post",
153  "saveFrmPostSettings",
154  "advanced_editing_frm_post_settings"
155  );
156  if (!$this->saveTags("frm_post", "frmPost", $form)) {
157  $form->setValuesByPost();
158  $this->tpl->setContent($form->getHTML());
159  }
160  }
161 
162  protected function initTagsForm(
163  string $a_id,
164  string $a_cmd,
165  string $a_title
166  ): ilPropertyFormGUI {
167  $form = new ilPropertyFormGUI();
168  $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
169  $form->setTitle($this->lng->txt($a_title));
170 
171  $tags = new ilMultiSelectInputGUI($this->lng->txt("advanced_editing_allow_html_tags"), "html_tags");
172  $tags->setHeight(400);
173  $tags->enableSelectAll(true);
174  $tags->enableSelectedFirst(true);
175  $tags->setOptions(
176  array_combine($this->settings->getAllAvailableHTMLTags(), $this->settings->getAllAvailableHTMLTags())
177  );
178  $tags->setValue(ilRTESettings::_getUsedHTMLTags($a_id));
179  $form->addItem($tags);
180 
181  if ($this->access->checkAccess('write', '', $this->ref_id)) {
182  $form->addCommandButton($a_cmd, $this->lng->txt("save"));
183  }
184 
185  return $form;
186  }
187 
188  protected function saveTags(
189  string $a_id,
190  string $a_cmd,
191  ilPropertyFormGUI $form
192  ): bool {
193  if (!$this->access->checkAccess('write', '', $this->ref_id)) {
194  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_read'), true);
195  return false;
196  }
197  try {
198  if ($form->checkInput()) {
199  $html_tags = $form->getInput("html_tags");
200  // get rid of select all
201  if (array_key_exists(0, $html_tags) && (string) $html_tags[0] === '') {
202  unset($html_tags[0]);
203  }
204  $this->settings->setUsedHTMLTags((array) $html_tags, $a_id);
205  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
206  } else {
207  return false;
208  }
210  $this->tpl->setOnScreenMessage('info', $e->getMessage(), true);
211  }
212  $this->ctrl->redirect($this, $a_cmd);
213  return true;
214  }
215 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addSubtabs(ilTabsGUI $tabs_gui)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addSubTabTarget(string $a_text, string $a_link, $a_cmd="", $a_cmdClass="", string $a_frame="", bool $a_activate=false, bool $a_dir_text=false)
static _getUsedHTMLTags(string $module='')
This class represents a multi selection list property in a property form.
$ref_id
Definition: ltiauth.php:65
initTagsForm(string $a_id, string $a_cmd, string $a_title)
__construct(private readonly int $ref_id, private readonly ilGlobalTemplateInterface $tpl, private readonly ilCtrlInterface $ctrl, private readonly Language $lng, private readonly ilAccessHandler $access, ilObjUser $current_user, ilTabsGUI $tabs_gui)
global $lng
Definition: privfeed.php:31
saveTags(string $a_id, string $a_cmd, ilPropertyFormGUI $form)
Class ilObjAdvancedEditingGUI.