ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilForumAutoSaveAsyncDraftAction Class Reference
+ Collaboration diagram for ilForumAutoSaveAsyncDraftAction:

Public Member Functions

 __construct (private readonly ilObjUser $actor, private readonly ilPropertyFormGUI $form, private readonly ilForumProperties $forumProperties, private readonly ilForumTopic $thread, private readonly ?ilForumPost $relatedPost, private Closure $subjectFormatterCallable, private int $relatedDraftId, private readonly int $relatedForumId, private readonly string $action)
 
 executeAndGetResponseObject ()
 

Protected Member Functions

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

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilForumAutoSaveAsyncDraftAction::__construct ( private readonly ilObjUser  $actor,
private readonly ilPropertyFormGUI  $form,
private readonly ilForumProperties  $forumProperties,
private readonly ilForumTopic  $thread,
private readonly ?ilForumPost  $relatedPost,
private Closure  $subjectFormatterCallable,
private int  $relatedDraftId,
private readonly int  $relatedForumId,
private readonly string  $action 
)

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

33  {
34  }

Member Function Documentation

◆ executeAndGetResponseObject()

ilForumAutoSaveAsyncDraftAction::executeAndGetResponseObject ( )

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

References $response, ilRTE\_getMediaObjects(), ilObjMediaObject\_getMobsOfObject(), ilRTE\_replaceMediaObjectImageSrc(), ILIAS\Repository\form(), getInputValuesFromForm(), handleMedia(), ILIAS\Repository\int(), ilForumPostDraft\isAutoSavePostDraftAllowed(), ilForumPostDraft\MEDIAOBJECT_TYPE, ilForumDraftsHistory\MEDIAOBJECT_TYPE, and ilForumPostDraft\newInstanceByDraftId().

36  : stdClass
37  {
38  $response = new stdClass();
39  $response->draft_id = 0;
40 
41  if ($this->actor->isAnonymous() || $this->actor->getId() <= 0) {
42  return $response;
43  }
44 
45  if ($this->thread->getId() > 0 && $this->thread->isClosed()) {
46  return $response;
47  }
48 
50  return $response;
51  }
52 
53  if (
54  $this->relatedPost instanceof ilForumPost && (
55  !$this->relatedPost->isActivated() || $this->relatedPost->isCensored()
56  )
57  ) {
58  return $response;
59  }
60 
61  $relatedPostId = 0;
62  if ($this->relatedPost instanceof ilForumPost) {
63  $relatedPostId = $this->relatedPost->getId();
64  }
65 
66  $this->form->checkInput();
67  $inputValues = $this->getInputValuesFromForm();
68 
69  if ($this->relatedDraftId > 0) {
70  $draftId = $this->relatedDraftId;
71  } else {
72  $draftId = (int) $this->form->getInput('draft_id');
73  }
74 
75  $subjectFormatterCallback = $this->subjectFormatterCallable;
76 
77  if ($draftId > 0) {
78  if ('showreply' === $this->action) {
79  $draft = ilForumPostDraft::newInstanceByDraftId($draftId);
80 
81  if ($draft->getPostAuthorId() !== $this->actor->getId()) {
82  return $response;
83  }
84 
85  $draft->setPostSubject($subjectFormatterCallback($inputValues['subject']));
86  $draft->setPostMessage(ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
87  $draft->setPostUserAlias($inputValues['alias']);
88  $draft->setNotificationStatus((bool) $inputValues['notify']);
89  $draft->setUpdateUserId($this->actor->getId());
90  $draft->setPostAuthorId($this->actor->getId());
91  $draft->setPostDisplayUserId(($this->forumProperties->isAnonymized() ? 0 : $this->actor->getId()));
92  $draft->updateDraft();
93 
94  $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
95  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $draft->getDraftId());
96  $curMediaObjects = ilRTE::_getMediaObjects($inputValues['message'], 0);
97 
98  $this->handleMedia(
100  $draft->getDraftId(),
101  $uploadedObjects,
102  $oldMediaObjects,
103  $curMediaObjects
104  );
105  } else {
106  $draft = ilForumPostDraft::newInstanceByDraftId($draftId);
107  if ($draft->getPostAuthorId() !== $this->actor->getId()) {
108  return $response;
109  }
110 
111  $history_entry = new ilForumDraftsHistory();
112  $history_entry->setDraftId($draft->getDraftId());
113  $history_entry->setPostSubject($subjectFormatterCallback($inputValues['subject']));
114  $history_entry->setPostMessage(ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
115  $history_entry->addDraftToHistory();
116 
117  $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
118  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $history_entry->getDraftId());
119  $curMediaObjects = ilRTE::_getMediaObjects($inputValues['message'], 0);
120 
121  $this->handleMedia(
123  $history_entry->getHistoryId(),
124  $uploadedObjects,
125  $oldMediaObjects,
126  $curMediaObjects
127  );
128  }
129  } else {
130  $draft = new ilForumPostDraft();
131  $draft->setForumId($this->relatedForumId);
132  $draft->setThreadId($this->thread->getId());
133  $draft->setPostId($relatedPostId);
134  $draft->setPostSubject($subjectFormatterCallback($inputValues['subject']));
135  $draft->setPostMessage(ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
136  $draft->setPostUserAlias($inputValues['alias']);
137  $draft->setNotificationStatus((bool) $inputValues['notify']);
138  $draft->setPostAuthorId($this->actor->getId());
139  $draft->setPostDisplayUserId(($this->forumProperties->isAnonymized() ? 0 : $this->actor->getId()));
140  $draft->saveDraft();
141 
142  $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
143  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $draft->getDraftId());
144  $curMediaObjects = ilRTE::_getMediaObjects($inputValues['message'], 0);
145 
146  $this->handleMedia(
148  $draft->getDraftId(),
149  $uploadedObjects,
150  $oldMediaObjects,
151  $curMediaObjects
152  );
153  }
154 
155  $response->draft_id = $draft->getDraftId();
156 
157  return $response;
158  }
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static _getMediaObjects(string $a_text, int $a_direction=0)
Returns all media objects found in the passed string.
handleMedia(string $type, int $draftId, array $uploadedObjects, array $oldMediaObjects, array $curMediaObjects)
$response
Definition: xapitoken.php:93
Class ilForumDraftHistory.
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
form( $class_path, string $cmd, string $submit_caption="")
static newInstanceByDraftId(int $draft_id)
+ Here is the call graph for this function:

◆ getInputValuesFromForm()

ilForumAutoSaveAsyncDraftAction::getInputValuesFromForm ( )
protected
Returns
array{subject: string, message: string, notify: int, alias: string}

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

References ILIAS\Repository\form(), ilForumUtil\getPublicUserAlias(), and ILIAS\Repository\int().

Referenced by executeAndGetResponseObject().

189  : array
190  {
191  return [
192  'subject' => (string) $this->form->getInput('subject'),
193  'message' => (string) $this->form->getInput('message'),
194  'notify' => (int) $this->form->getInput('notify'),
196  $this->form->getInput('alias'),
197  $this->forumProperties->isAnonymized()
198  )
199  ];
200  }
static getPublicUserAlias(string $user_alias, bool $is_anonymized)
form( $class_path, string $cmd, string $submit_caption="")
+ 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
int[]$uploadedObjects
int[]$oldMediaObjects
int[]$curMediaObjects

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

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

Referenced by executeAndGetResponseObject().

171  : void {
172  foreach ($uploadedObjects as $mob) {
173  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $this->actor->getId());
174  ilObjMediaObject::_saveUsage($mob, $type, $draftId);
175  }
176 
177  foreach ($oldMediaObjects as $mob) {
178  ilObjMediaObject::_saveUsage($mob, $type, $draftId);
179  }
180 
181  foreach ($curMediaObjects as $mob) {
182  ilObjMediaObject::_saveUsage($mob, $type, $draftId);
183  }
184  }
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
static _removeUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Remove usage of mob in another container.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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