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