ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilForumThreadFormGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public const ALIAS_INPUT = 'alias';
24  public const SUBJECT_INPUT = 'subject';
25  public const MESSAGE_INPUT = 'message';
26  public const FILE_UPLOAD_INPUT = 'file_upload';
27  public const ALLOW_NOTIFICATION_INPUT = 'allow_notification';
28  public const AUTOSAVE_INFO = 'autosave_info';
29 
31  private array $input_items = [];
32 
33  public function __construct(
34  private readonly ilObjForumGUI $delegatingGui,
35  private readonly ilForumProperties $properties,
36  private readonly bool $allowPseudonyms,
37  private readonly bool $allowNotification,
38  private readonly bool $isDraftContext,
39  private readonly int $draftId
40  ) {
42  }
43 
44  private function addAliasInput(): void
45  {
46  if ($this->allowPseudonyms) {
47  $alias = new ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
48  $alias->setInfo($this->lng->txt('forums_use_alias'));
49  $alias->setMaxLength(255);
50  $alias->setSize(50);
51  } else {
52  $alias = new ilNonEditableValueGUI($this->lng->txt('forums_your_name'), 'alias');
53  $alias->setValue($this->user->getLogin());
54  }
55  $this->addItem($alias);
56  }
57 
58  private function addSubjectInput(): void
59  {
60  $subject = new ilTextInputGUI($this->lng->txt('forums_thread'), 'subject');
61  $subject->setMaxLength(255);
62  $subject->setSize(50);
63  $subject->setRequired(true);
64  $this->addItem($subject);
65  }
66 
67  private function addMessageInput(): void
68  {
69  $message = new ilTextAreaInputGUI($this->lng->txt('forums_the_post'), 'message');
70  $message->setCols(50);
71  $message->setRows(15);
72  $message->setRequired(true);
73  $message->setUseRte(true);
74  $message->usePurifier(true);
75  $message->setRTERootBlockElement('');
76  $message->setRTESupport($this->user->getId(), 'frm~', 'frm_post', 'tpl.tinymce_frm_post.js', false, '5.6.0');
77  $message->disableButtons([
78  'charmap',
79  'undo',
80  'redo',
81  'alignleft',
82  'aligncenter',
83  'alignright',
84  'alignjustify',
85  'anchor',
86  'fullscreen',
87  'cut',
88  'copy',
89  'paste',
90  'pastetext',
91  'formatselect'
92  ]);
93  $message->setPurifier(ilHtmlPurifierFactory::getInstanceByType('frm_post'));
94  $this->addItem($message);
95  }
96 
97  private function addAutosaveInfo(): void
98  {
100  $draftInfoGUI = new ilNonEditableValueGUI('', 'autosave_info', true);
101  $draftInfoGUI->setValue(
102  sprintf(
103  $this->lng->txt('autosave_draft_info'),
105  )
106  );
107  $this->addItem($draftInfoGUI);
108  }
109  }
110 
111  private function addFileUploadInput(): void
112  {
113  if ($this->properties->isFileUploadAllowed()) {
114  $files = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
115  $files->setFilenames([0 => '']);
116  $this->addItem($files);
117 
118  if ($this->isDraftContext && $this->draftId > 0) {
119  $threadDraft = ilForumPostDraft::newInstanceByDraftId($this->draftId);
120  if ($threadDraft->getDraftId() > 0) {
121  //
122  $draftFileData = new ilFileDataForumDrafts(0, $threadDraft->getDraftId());
123  if ($draftFileData->getFilesOfPost() !== []) {
124  $existingFileSelection = new ilCheckboxGroupInputGUI(
125  $this->lng->txt('forums_delete_file'),
126  'del_file'
127  );
128  foreach ($draftFileData->getFilesOfPost() as $file) {
129  $existingFileSelection->addOption(new ilCheckboxOption($file['name'], $file['md5']));
130  }
131  $this->addItem($existingFileSelection);
132  }
133  }
134  }
135  }
136  }
137 
138  private function addAllowNotificationInput(): void
139  {
140  if ($this->allowNotification) {
141  $notifyOnAnswer = new ilCheckboxInputGUI($this->lng->txt('forum_direct_notification'), 'notify');
142  $notifyOnAnswer->setInfo($this->lng->txt('forum_notify_me'));
143  $notifyOnAnswer->setValue('1');
144  $this->addItem($notifyOnAnswer);
145  }
146  }
147 
148  private function generateInputItems(): void
149  {
150  $this->setTitleIcon(ilUtil::getImagePath('standard/icon_frm.svg'));
151  $this->setTableWidth('100%');
152  $this->setTitle($this->lng->txt('forums_new_thread'));
153  if ($this->isDraftContext) {
154  $this->setTitle($this->lng->txt('edit_thread_draft'));
155  }
156 
157  foreach ($this->input_items as $input_item) {
158  switch ($input_item) {
159  case self::ALIAS_INPUT:
160  $this->addAliasInput();
161  break;
162 
163  case self::SUBJECT_INPUT:
164  $this->addSubjectInput();
165  break;
166 
167  case self::MESSAGE_INPUT:
168  $this->addMessageInput();
169  break;
170 
171  case self::FILE_UPLOAD_INPUT:
172  $this->addFileUploadInput();
173  break;
174 
175  case self::ALLOW_NOTIFICATION_INPUT:
176  $this->addAllowNotificationInput();
177  break;
178 
179  case self::AUTOSAVE_INFO:
180  $this->addAutosaveInfo();
181  break;
182  }
183  }
184  }
185 
186  public function addInputItem(string $input_item): void
187  {
188  $this->input_items[] = $input_item;
189  }
190 
191  public function generateDefaultForm(): void
192  {
193  $this->generateInputItems();
194 
195  if (ilForumPostDraft::isSavePostDraftAllowed() && !$this->user->isAnonymous()) {
196  $this->ctrl->setParameter($this->delegatingGui, 'draft_id', $this->draftId);
197  if (in_array($this->ctrl->getCmd(), ['publishThreadDraft', 'editThreadDraft', 'updateThreadDraft'])) {
198  $this->addCommandButton('publishThreadDraft', $this->lng->txt('publish'));
199  $this->addCommandButton('updateThreadDraft', $this->lng->txt('save_message'));
200  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'updateThreadDraft'));
201  } else {
202  $this->addCommandButton('addThread', $this->lng->txt('create'));
203  $this->addCommandButton('saveThreadAsDraft', $this->lng->txt('save_message'));
204  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'saveThreadAsDraft'));
205  }
206  $this->addCommandButton('cancelDraft', $this->lng->txt('cancel'));
207  } else {
208  $this->addCommandButton('addThread', $this->lng->txt('create'));
209  $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
210  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'addThread'));
211  }
212  }
213 
214  public function generateMinimalForm(): void
215  {
216  $this->generateInputItems();
217 
218  $this->addCommandButton('addEmptyThread', $this->lng->txt('create'));
219  $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
220  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'addThread'));
221  }
222 }
setFilenames(array $a_filenames)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file wizard property in a property form.
setFormAction(string $a_formaction)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getInstanceByType(string $type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitleIcon(string $a_titleicon)
setTableWidth(string $a_width)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
__construct(private readonly ilObjForumGUI $delegatingGui, private readonly ilForumProperties $properties, private readonly bool $allowPseudonyms, private readonly bool $allowNotification, private readonly bool $isDraftContext, private readonly int $draftId)
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
static newInstanceByDraftId(int $draft_id)