ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilForumThreadFormGUI.php
Go to the documentation of this file.
1<?php
2
19declare(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
33 private array $input_items = [];
36 private bool $allowPseudonyms;
37 private bool $allowNotification;
38 private bool $isDraftContext;
39 private int $draftId;
40
41 public function __construct(
46 bool $isDraftContext,
47 int $draftId
48 ) {
50
51 $this->delegatingGui = $delegatingGui;
52 $this->properties = $properties;
53 $this->allowPseudonyms = $allowPseudonyms;
54 $this->allowNotification = $allowNotification;
55 $this->isDraftContext = $isDraftContext;
56 $this->draftId = $draftId;
57 }
58
59 private function addAliasInput(): void
60 {
61 if ($this->allowPseudonyms) {
62 $alias = new ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
63 $alias->setInfo($this->lng->txt('forums_use_alias'));
64 $alias->setMaxLength(255);
65 $alias->setSize(50);
66 } else {
67 $alias = new ilNonEditableValueGUI($this->lng->txt('forums_your_name'), 'alias');
68 $alias->setValue($this->user->getLogin());
69 }
70 $this->addItem($alias);
71 }
72
73 private function addSubjectInput(): void
74 {
75 $subject = new ilTextInputGUI($this->lng->txt('forums_thread'), 'subject');
76 $subject->setMaxLength(255);
77 $subject->setSize(50);
78 $subject->setRequired(true);
79 $this->addItem($subject);
80 }
81
82 private function addMessageInput(): void
83 {
84 $message = new ilTextAreaInputGUI($this->lng->txt('forums_the_post'), 'message');
85 $message->setCols(50);
86 $message->setRows(15);
87 $message->setRequired(true);
88 $message->setUseRte(true);
89 $message->addPlugin('latex');
90 $message->addButton('latex');
91 $message->addButton('pastelatex');
92 $message->addPlugin('ilfrmquote');
93 $message->usePurifier(true);
94 $message->setRTERootBlockElement('');
95 $message->setRTESupport($this->user->getId(), 'frm~', 'frm_post', 'tpl.tinymce_frm_post.js', false, '5.6.0');
96 $message->disableButtons([
97 'charmap',
98 'undo',
99 'redo',
100 'alignleft',
101 'aligncenter',
102 'alignright',
103 'alignjustify',
104 'anchor',
105 'fullscreen',
106 'cut',
107 'copy',
108 'paste',
109 'pastetext',
110 'formatselect'
111 ]);
112 $message->setPurifier(ilHtmlPurifierFactory::getInstanceByType('frm_post'));
113 $this->addItem($message);
114 }
115
116 private function addFileUploadInput(): void
117 {
118 if ($this->properties->isFileUploadAllowed()) {
119 $files = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
120 $files->setFilenames([0 => '']);
121 $this->addItem($files);
122
123 if ($this->isDraftContext && $this->draftId > 0) {
124 $threadDraft = ilForumPostDraft::newInstanceByDraftId($this->draftId);
125 if ($threadDraft->getDraftId() > 0) {
126 $draftFileData = new ilFileDataForumDrafts(0, $threadDraft->getDraftId());
127 if (count($draftFileData->getFilesOfPost()) > 0) {
128 $existingFileSelection = new ilCheckboxGroupInputGUI(
129 $this->lng->txt('forums_delete_file'),
130 'del_file'
131 );
132 foreach ($draftFileData->getFilesOfPost() as $file) {
133 $existingFileSelection->addOption(new ilCheckboxOption($file['name'], $file['md5']));
134 }
135 $this->addItem($existingFileSelection);
136 }
137 }
138 }
139 }
140 }
141
142 private function addAllowNotificationInput(): void
143 {
144 if ($this->allowNotification) {
145 $notifyOnAnswer = new ilCheckboxInputGUI($this->lng->txt('forum_direct_notification'), 'notify');
146 $notifyOnAnswer->setInfo($this->lng->txt('forum_notify_me'));
147 $notifyOnAnswer->setValue('1');
148 $this->addItem($notifyOnAnswer);
149 }
150 }
151
152 private function generateInputItems(): void
153 {
154 $this->setTitleIcon(ilUtil::getImagePath('icon_frm.svg'));
155 $this->setTableWidth('100%');
156 $this->setTitle($this->lng->txt('forums_new_thread'));
157 if ($this->isDraftContext) {
158 $this->setTitle($this->lng->txt('edit_thread_draft'));
159 }
160
161 foreach ($this->input_items as $input_item) {
162 switch ($input_item) {
164 $this->addAliasInput();
165 break;
166
168 $this->addSubjectInput();
169 break;
170
172 $this->addMessageInput();
173 break;
174
176 $this->addFileUploadInput();
177 break;
178
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}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class handles all operations on files for the drafts of a forum object.
This class represents a file wizard property in a property form.
setFormAction(string $a_formaction)
static newInstanceByDraftId(int $draft_id)
Class ilForumThreadFormGUI.
__construct(ilObjForumGUI $delegatingGui, ilForumProperties $properties, bool $allowPseudonyms, bool $allowNotification, bool $isDraftContext, int $draftId)
static getInstanceByType(string $type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjForumGUI.
This class represents a property form user interface.
setTableWidth(string $a_width)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
setTitleIcon(string $a_titleicon)
This class represents a text area property in a property form.
This class represents a text property in a property form.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$message
Definition: xapiexit.php:32