ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  $message->setInfo($this->lng->txt('latex_edit_info'));
95  $this->addItem($message);
96  }
97 
98  private function addAutosaveInfo(): void
99  {
101  $draftInfoGUI = new ilNonEditableValueGUI('', 'autosave_info', true);
102  $draftInfoGUI->setValue(
103  sprintf(
104  $this->lng->txt('autosave_draft_info'),
106  )
107  );
108  $this->addItem($draftInfoGUI);
109  }
110  }
111 
112  private function addFileUploadInput(): void
113  {
114  if ($this->properties->isFileUploadAllowed()) {
115  $files = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
116  $files->setFilenames([0 => '']);
117  $this->addItem($files);
118 
119  if ($this->isDraftContext && $this->draftId > 0) {
120  $threadDraft = ilForumPostDraft::newInstanceByDraftId($this->draftId);
121  if ($threadDraft->getDraftId() > 0) {
122  //
123  $draftFileData = new ilFileDataForumDrafts(0, $threadDraft->getDraftId());
124  if ($draftFileData->getFilesOfPost() !== []) {
125  $existingFileSelection = new ilCheckboxGroupInputGUI(
126  $this->lng->txt('forums_delete_file'),
127  'del_file'
128  );
129  foreach ($draftFileData->getFilesOfPost() as $file) {
130  $existingFileSelection->addOption(new ilCheckboxOption($file['name'], $file['md5']));
131  }
132  $this->addItem($existingFileSelection);
133  }
134  }
135  }
136  }
137  }
138 
139  private function addAllowNotificationInput(): void
140  {
141  if ($this->allowNotification) {
142  $notifyOnAnswer = new ilCheckboxInputGUI($this->lng->txt('forum_direct_notification'), 'notify');
143  $notifyOnAnswer->setInfo($this->lng->txt('forum_notify_me'));
144  $notifyOnAnswer->setValue('1');
145  $this->addItem($notifyOnAnswer);
146  }
147  }
148 
149  private function generateInputItems(): void
150  {
151  $this->setTitleIcon(ilUtil::getImagePath('standard/icon_frm.svg'));
152  $this->setTableWidth('100%');
153  $this->setTitle($this->lng->txt('forums_new_thread'));
154  if ($this->isDraftContext) {
155  $this->setTitle($this->lng->txt('edit_thread_draft'));
156  }
157 
158  foreach ($this->input_items as $input_item) {
159  switch ($input_item) {
160  case self::ALIAS_INPUT:
161  $this->addAliasInput();
162  break;
163 
164  case self::SUBJECT_INPUT:
165  $this->addSubjectInput();
166  break;
167 
168  case self::MESSAGE_INPUT:
169  $this->addMessageInput();
170  break;
171 
172  case self::FILE_UPLOAD_INPUT:
173  $this->addFileUploadInput();
174  break;
175 
176  case self::ALLOW_NOTIFICATION_INPUT:
177  $this->addAllowNotificationInput();
178  break;
179 
180  case self::AUTOSAVE_INFO:
181  $this->addAutosaveInfo();
182  break;
183  }
184  }
185  }
186 
187  public function addInputItem(string $input_item): void
188  {
189  $this->input_items[] = $input_item;
190  }
191 
192  public function generateDefaultForm(): void
193  {
194  $this->generateInputItems();
195 
196  if (ilForumPostDraft::isSavePostDraftAllowed() && !$this->user->isAnonymous()) {
197  $this->ctrl->setParameter($this->delegatingGui, 'draft_id', $this->draftId);
198  if (in_array($this->ctrl->getCmd(), ['publishThreadDraft', 'editThreadDraft', 'updateThreadDraft'])) {
199  $this->addCommandButton('publishThreadDraft', $this->lng->txt('publish'));
200  $this->addCommandButton('updateThreadDraft', $this->lng->txt('save_message'));
201  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'updateThreadDraft'));
202  } else {
203  $this->addCommandButton('addThread', $this->lng->txt('create'));
204  $this->addCommandButton('saveThreadAsDraft', $this->lng->txt('save_message'));
205  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'saveThreadAsDraft'));
206  }
207  $this->addCommandButton('cancelDraft', $this->lng->txt('cancel'));
208  } else {
209  $this->addCommandButton('addThread', $this->lng->txt('create'));
210  $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
211  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'addThread'));
212  }
213  }
214 
215  public function generateMinimalForm(): void
216  {
217  $this->generateInputItems();
218 
219  $this->addCommandButton('addEmptyThread', $this->lng->txt('create'));
220  $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
221  $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'addThread'));
222  }
223 }
setFilenames(array $a_filenames)
This class represents an option in a checkbox group.
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 class represents a property in a property form.
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.
$message
Definition: xapiexit.php:31
static newInstanceByDraftId(int $draft_id)