ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilForumAutoSaveAsyncDraftAction Class Reference

Class ilForumSaveAsyncDraftAction. More...

+ Collaboration diagram for ilForumAutoSaveAsyncDraftAction:

Public Member Functions

 __construct (\ilObjUser $actor, \ilPropertyFormGUI $form, \ilForumProperties $forumProperties, \ilForumTopic $thread, $relatedPost, callable $subjectFormatterCallable, int $relatedDraftId, int $relatedForumId, string $action)
 ilForumAutoSaveAsyncDraftAction constructor. More...
 
 executeAndGetResponseObject ()
 

Protected Member Functions

 handleMedia (string $type, int $draftId, array $uploadedObjects, array $oldMediaObjects, array $curMediaObjects)
 
 getInputValuesFromForm ()
 

Private Attributes

 $actor
 
 $form
 
 $forumProperties
 
 $thread
 
 $relatedPost
 
 $subjectFormatterCallable
 
 $relatedDraftId = 0
 
 $relatedForumId
 
 $action = ''
 

Detailed Description

Class ilForumSaveAsyncDraftAction.

Author
Nadia Matuschek nmatu.nosp@m.sche.nosp@m.k@dat.nosp@m.abay.nosp@m..de

Definition at line 8 of file class.ilForumAutoSaveAsyncDraftAction.php.

Constructor & Destructor Documentation

◆ __construct()

ilForumAutoSaveAsyncDraftAction::__construct ( \ilObjUser  $actor,
\ilPropertyFormGUI  $form,
\ilForumProperties  $forumProperties,
\ilForumTopic  $thread,
  $relatedPost,
callable  $subjectFormatterCallable,
int  $relatedDraftId,
int  $relatedForumId,
string  $action 
)

ilForumAutoSaveAsyncDraftAction constructor.

Parameters
\ilObjUser$actor
\ilPropertyFormGUI$form
\ilForumProperties$forumProperties
\ilForumTopic$thread
\ilForumPost | null$relatedPost
callable$subjectFormatterCallable
int$relatedDraftId
int$relatedForumId
string$action

Definition at line 49 of file class.ilForumAutoSaveAsyncDraftAction.php.

References $action, $actor, $form, $forumProperties, $relatedDraftId, $relatedForumId, $relatedPost, $subjectFormatterCallable, and $thread.

Member Function Documentation

◆ executeAndGetResponseObject()

ilForumAutoSaveAsyncDraftAction::executeAndGetResponseObject ( )
Returns

Definition at line 75 of file class.ilForumAutoSaveAsyncDraftAction.php.

References $relatedDraftId, $response, $subjectFormatterCallable, ilRTE\_getMediaObjects(), ilObjMediaObject\_getMobsOfObject(), ilRTE\_replaceMediaObjectImageSrc(), getInputValuesFromForm(), handleMedia(), ilForumPostDraft\isAutoSavePostDraftAllowed(), ilForumPostDraft\MEDIAOBJECT_TYPE, ilForumDraftsHistory\MEDIAOBJECT_TYPE, and ilForumPostDraft\newInstanceByDraftId().

75  : \stdClass
76  {
77  $response = new \stdClass();
78  $response->draft_id = 0;
79 
80  if ($this->actor->isAnonymous() || !($this->actor->getId() > 0)) {
81  return $response;
82  }
83 
84  if ($this->thread->getId() > 0 && $this->thread->isClosed()) {
85  return $response;
86  }
87 
89  return $response;
90  }
91 
92  if (
93  $this->relatedPost instanceof \ilForumPost && (
94  !$this->relatedPost->isActivated() || $this->relatedPost->isCensored()
95  )
96  ) {
97  return $response;
98  }
99 
100  $relatedPostId = 0;
101  if ($this->relatedPost instanceof \ilForumPost) {
102  $relatedPostId = $this->relatedPost->getId();
103  }
104 
105  $this->form->checkInput();
106  $inputValues = $this->getInputValuesFromForm();
107 
108  if ($this->relatedDraftId > 0) {
109  $draftId = $this->relatedDraftId;
110  } else {
111  $draftId = (int) $this->form->getInput('draft_id');
112  }
113 
114  $subjectFormatterCallback = $this->subjectFormatterCallable;
115 
116  if ($draftId > 0) {
117  if ('showreply' === $this->action) {
118  $draftObj = \ilForumPostDraft::newInstanceByDraftId($draftId);
119  $draftObj->setPostSubject($subjectFormatterCallback($inputValues['subject']));
120  $draftObj->setPostMessage(\ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
121  $draftObj->setPostUserAlias($inputValues['alias']);
122  $draftObj->setNotify($inputValues['notify']);
123  $draftObj->setUpdateUserId($this->actor->getId());
124  $draftObj->setPostAuthorId($this->actor->getId());
125  $draftObj->setPostDisplayUserId(($this->forumProperties->isAnonymized() ? 0 : $this->actor->getId()));
126  $draftObj->updateDraft();
127 
128  $uploadedObjects = \ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
129  $oldMediaObjects = \ilObjMediaObject::_getMobsOfObject('frm~d:html', $draftObj->getDraftId());
130  $curMediaObjects = \ilRTE::_getMediaObjects($inputValues['message'], 0);
131 
132  $this->handleMedia(
134  $draftObj->getDraftId(),
135  $uploadedObjects,
136  $oldMediaObjects,
137  $curMediaObjects
138  );
139  } else {
140  $draftObj = new \ilForumDraftsHistory();
141  $draftObj->setDraftId($draftId);
142  $draftObj->setPostSubject($subjectFormatterCallback($inputValues['subject']));
143  $draftObj->setPostMessage(\ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
144  $draftObj->addDraftToHistory();
145 
146  $uploadedObjects = \ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
147  $oldMediaObjects = \ilObjMediaObject::_getMobsOfObject('frm~d:html', $draftObj->getDraftId());
148  $curMediaObjects = \ilRTE::_getMediaObjects($inputValues['message'], 0);
149 
150  $this->handleMedia(
152  $draftObj->getHistoryId(),
153  $uploadedObjects,
154  $oldMediaObjects,
155  $curMediaObjects
156  );
157  }
158  } else {
159  $draftObj = new \ilForumPostDraft();
160  $draftObj->setForumId($this->relatedForumId);
161  $draftObj->setThreadId($this->thread->getId());
162  $draftObj->setPostId($relatedPostId);
163  $draftObj->setPostSubject($subjectFormatterCallback($inputValues['subject']));
164  $draftObj->setPostMessage(\ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
165  $draftObj->setPostUserAlias($inputValues['alias']);
166  $draftObj->setNotify($inputValues['notify']);
167  $draftObj->setPostAuthorId($this->actor->getId());
168  $draftObj->setPostDisplayUserId(($this->forumProperties->isAnonymized() ? 0 : $this->actor->getId()));
169  $draftObj->saveDraft();
170 
171  $uploadedObjects = \ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
172  $oldMediaObjects = \ilObjMediaObject::_getMobsOfObject('frm~d:html', $draftObj->getDraftId());
173  $curMediaObjects = \ilRTE::_getMediaObjects($inputValues['message'], 0);
174 
175  $this->handleMedia(
177  $draftObj->getDraftId(),
178  $uploadedObjects,
179  $oldMediaObjects,
180  $curMediaObjects
181  );
182  }
183 
184  $response->draft_id = $draftObj->getDraftId();
185 
186  return $response;
187  }
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
handleMedia(string $type, int $draftId, array $uploadedObjects, array $oldMediaObjects, array $curMediaObjects)
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static newInstanceByDraftId($draft_id)
$response
+ Here is the call graph for this function:

◆ getInputValuesFromForm()

ilForumAutoSaveAsyncDraftAction::getInputValuesFromForm ( )
protected
Returns
array

Definition at line 220 of file class.ilForumAutoSaveAsyncDraftAction.php.

References ilForumUtil\getPublicUserAlias().

Referenced by executeAndGetResponseObject().

220  : array
221  {
222  $inputValues = [];
223 
224  $inputValues['subject'] = (string) $this->form->getInput('subject');
225  $inputValues['message'] = (string) $this->form->getInput('message');
226  $inputValues['notify'] = (int) $this->form->getInput('notify');
227  $inputValues['alias'] = \ilForumUtil::getPublicUserAlias(
228  (string) $this->form->getInput('alias'),
229  $this->forumProperties->isAnonymized()
230  );
231 
232  return $inputValues;
233  }
static getPublicUserAlias($user_alias, $is_anonymized=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleMedia()

ilForumAutoSaveAsyncDraftAction::handleMedia ( string  $type,
int  $draftId,
array  $uploadedObjects,
array  $oldMediaObjects,
array  $curMediaObjects 
)
protected
Parameters
string$type
int$draftId
int[]$uploadedObjects
int[]$oldMediaObjects
int[]$curMediaObjects

Definition at line 196 of file class.ilForumAutoSaveAsyncDraftAction.php.

References ilObjMediaObject\_removeUsage(), and ilObjMediaObject\_saveUsage().

Referenced by executeAndGetResponseObject().

202  {
203  foreach ($uploadedObjects as $mob) {
204  \ilObjMediaObject::_removeUsage($mob, 'frm~:html', $this->actor->getId());
205  \ilObjMediaObject::_saveUsage($mob, $type, $draftId);
206  }
207 
208  foreach ($oldMediaObjects as $mob) {
209  \ilObjMediaObject::_saveUsage($mob, $type, $draftId);
210  }
211 
212  foreach ($curMediaObjects as $mob) {
213  \ilObjMediaObject::_saveUsage($mob, $type, $draftId);
214  }
215  }
$type
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $action

ilForumAutoSaveAsyncDraftAction::$action = ''
private

Definition at line 35 of file class.ilForumAutoSaveAsyncDraftAction.php.

Referenced by __construct().

◆ $actor

ilForumAutoSaveAsyncDraftAction::$actor
private

Definition at line 11 of file class.ilForumAutoSaveAsyncDraftAction.php.

Referenced by __construct().

◆ $form

ilForumAutoSaveAsyncDraftAction::$form
private

Definition at line 14 of file class.ilForumAutoSaveAsyncDraftAction.php.

Referenced by __construct().

◆ $forumProperties

ilForumAutoSaveAsyncDraftAction::$forumProperties
private

Definition at line 17 of file class.ilForumAutoSaveAsyncDraftAction.php.

Referenced by __construct().

◆ $relatedDraftId

ilForumAutoSaveAsyncDraftAction::$relatedDraftId = 0
private

◆ $relatedForumId

ilForumAutoSaveAsyncDraftAction::$relatedForumId
private

Definition at line 32 of file class.ilForumAutoSaveAsyncDraftAction.php.

Referenced by __construct().

◆ $relatedPost

ilForumAutoSaveAsyncDraftAction::$relatedPost
private

Definition at line 23 of file class.ilForumAutoSaveAsyncDraftAction.php.

Referenced by __construct().

◆ $subjectFormatterCallable

ilForumAutoSaveAsyncDraftAction::$subjectFormatterCallable
private

◆ $thread

ilForumAutoSaveAsyncDraftAction::$thread
private

Definition at line 20 of file class.ilForumAutoSaveAsyncDraftAction.php.

Referenced by __construct().


The documentation for this class was generated from the following file: