ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilForumThreadFormGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
10 protected $delegatingGui;
11
13 protected $properties;
14
16 protected $allowPseudonyms = false;
17
19 protected $allowNotification = false;
20
22 protected $isDraftContext = false;
23
25 protected $draftId = 0;
26
36 public function __construct(
41 bool $isDraftContext,
42 int $draftId
43 ) {
45
46 $this->delegatingGui = $delegatingGui;
47 $this->properties = $properties;
48 $this->allowPseudonyms = $allowPseudonyms;
49 $this->allowNotification = $allowNotification;
50 $this->isDraftContext = $isDraftContext;
51 $this->draftId = $draftId;
52
53 $this->initForm();
54 }
55
59 protected function initForm()
60 {
61 $this->setTitleIcon(\ilUtil::getImagePath('icon_frm.svg'));
62 $this->setTableWidth('100%');
63 $this->setTitle($this->lng->txt('forums_new_thread'));
64 if ($this->isDraftContext) {
65 $this->setTitle($this->lng->txt('edit_thread_draft'));
66 }
67
68 if ($this->allowPseudonyms) {
69 $alias = new \ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
70 $alias->setInfo($this->lng->txt('forums_use_alias'));
71 $alias->setMaxLength(255);
72 $alias->setSize(50);
73 } else {
74 $alias = new \ilNonEditableValueGUI($this->lng->txt('forums_your_name'), 'alias');
75 $alias->setValue($this->user->getLogin());
76 }
77 $this->addItem($alias);
78
79 $subject = new \ilTextInputGUI($this->lng->txt('forums_thread'), 'subject');
80 $subject->setMaxLength(255);
81 $subject->setSize(50);
82 $subject->setRequired(true);
83 $this->addItem($subject);
84
85 $message = new ilTextAreaInputGUI($this->lng->txt('forums_the_post'), 'message');
86 $message->setCols(50);
87 $message->setRows(15);
88 $message->setRequired(true);
89 $message->setUseRte(true);
90 $message->addPlugin('latex');
91 $message->addButton('latex');
92 $message->addButton('pastelatex');
93 $message->addPlugin('ilfrmquote');
94
95 $message->usePurifier(true);
96 $message->setRTERootBlockElement('');
97 $message->setRTESupport($this->user->getId(), 'frm~', 'frm_post', 'tpl.tinymce_frm_post.js', false, '5.6.0');
98 $message->disableButtons(array(
99 'charmap',
100 'undo',
101 'redo',
102 'alignleft',
103 'aligncenter',
104 'alignright',
105 'alignjustify',
106 'anchor',
107 'fullscreen',
108 'cut',
109 'copy',
110 'paste',
111 'pastetext',
112 'formatselect'
113 ));
114 $message->setPurifier(\ilHtmlPurifierFactory::_getInstanceByType('frm_post'));
115 $this->addItem($message);
116
117 if ($this->properties->isFileUploadAllowed()) {
118 $files = new \ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
119 $files->setFilenames([0 => '']);
120 $this->addItem($files);
121
122 if ($this->isDraftContext) {
123 if ($this->draftId > 0) {
124 $threadDraft = \ilForumPostDraft::newInstanceByDraftId($this->draftId);
125 if ((int) $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 $currentAttachment = new \ilCheckboxInputGUI($file['name'], 'del_file');
134 $currentAttachment->setValue($file['md5']);
135 $existingFileSelection->addOption($currentAttachment);
136 }
137 $this->addItem($existingFileSelection);
138 }
139 }
140 }
141 }
142 }
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 if ($this->user->isAnonymous() && !$this->user->isCaptchaVerified() && \ilCaptchaUtil::isActiveForForum()) {
152 $captcha = new \ilCaptchaInputGUI($this->lng->txt('cont_captcha_code'), 'captcha_code');
153 $captcha->setRequired(true);
154 $this->addItem($captcha);
155 }
156
157 if (\ilForumPostDraft::isSavePostDraftAllowed() && !$this->user->isAnonymous()) {
158 $this->ctrl->setParameter($this->delegatingGui, 'draft_id', $this->draftId);
159 if (in_array($this->ctrl->getCmd(), ['publishThreadDraft', 'editThreadDraft', 'updateThreadDraft'])) {
160 $this->addCommandButton('publishThreadDraft', $this->lng->txt('publish'));
161 $this->addCommandButton('updateThreadDraft', $this->lng->txt('save_message'));
162 $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'updateThreadDraft'));
163 } else {
164 $this->addCommandButton('addThread', $this->lng->txt('create'));
165 $this->addCommandButton('saveThreadAsDraft', $this->lng->txt('save_message'));
166 $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'saveThreadAsDraft'));
167 }
168 $this->addCommandButton('cancelDraft', $this->lng->txt('cancel'));
169 } else {
170 $this->addCommandButton('addThread', $this->lng->txt('create'));
171 $this->addCommandButton('showThreads', $this->lng->txt('cancel'));
172 $this->setFormAction($this->ctrl->getFormAction($this->delegatingGui, 'addThread'));
173 }
174 }
175}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
setFormAction($a_formaction)
Set FormAction.
static newInstanceByDraftId($draft_id)
Class ilForumThreadFormGUI.
__construct(\ilObjForumGUI $delegatingGui, \ilForumProperties $properties, bool $allowPseudonyms, bool $allowNotification, bool $isDraftContext, int $draftId)
ilForumThreadFormGUI constructor.
static _getInstanceByType(string $type)
Factory method for creating purifier instances.
Class ilObjForumGUI.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
setTableWidth($a_width)
Set table width.
setTitleIcon($a_titleicon)
Set TitleIcon.
setTitle($a_title)
Set Title.
This class represents a text area property in a property form.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$message
Definition: xapiexit.php:14