ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilForumAutoSaveAsyncDraftAction Class Reference

Class ilForumSaveAsyncDraftAction. More...

+ Collaboration diagram for ilForumAutoSaveAsyncDraftAction:

Public Member Functions

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

Protected Member Functions

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

Private Attributes

ilObjUser $actor
 
ilPropertyFormGUI $form
 
ilForumProperties $forumProperties
 
ilForumTopic $thread
 
ilForumPost $relatedPost
 
Closure $subjectFormatterCallable
 
int $relatedDraftId
 
int $relatedForumId
 
string $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 25 of file class.ilForumAutoSaveAsyncDraftAction.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

References $action, $actor, $form, $forumProperties, $relatedDraftId, $relatedForumId, $relatedPost, $subjectFormatterCallable, $thread, and ILIAS\Repository\form().

47  {
48  $this->actor = $actor;
49  $this->form = $form;
50  $this->forumProperties = $forumProperties;
51  $this->thread = $thread;
52  $this->relatedPost = $relatedPost;
53  $this->subjectFormatterCallable = $subjectFormatterCallable;
54 
55  $this->relatedDraftId = $relatedDraftId;
56  $this->relatedForumId = $relatedForumId;
57  $this->action = $action;
58  }
form( $class_path, string $cmd)
+ Here is the call graph for this function:

Member Function Documentation

◆ executeAndGetResponseObject()

ilForumAutoSaveAsyncDraftAction::executeAndGetResponseObject ( )

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

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

60  : stdClass
61  {
62  $response = new stdClass();
63  $response->draft_id = 0;
64 
65  if ($this->actor->isAnonymous() || !($this->actor->getId() > 0)) {
66  return $response;
67  }
68 
69  if ($this->thread->getId() > 0 && $this->thread->isClosed()) {
70  return $response;
71  }
72 
74  return $response;
75  }
76 
77  if (
78  $this->relatedPost instanceof ilForumPost && (
79  !$this->relatedPost->isActivated() || $this->relatedPost->isCensored()
80  )
81  ) {
82  return $response;
83  }
84 
85  $relatedPostId = 0;
86  if ($this->relatedPost instanceof ilForumPost) {
87  $relatedPostId = $this->relatedPost->getId();
88  }
89 
90  $this->form->checkInput();
91  $inputValues = $this->getInputValuesFromForm();
92 
93  if ($this->relatedDraftId > 0) {
94  $draftId = $this->relatedDraftId;
95  } else {
96  $draftId = (int) $this->form->getInput('draft_id');
97  }
98 
99  $subjectFormatterCallback = $this->subjectFormatterCallable;
100 
101  if ($draftId > 0) {
102  if ('showreply' === $this->action) {
103  $draftObj = ilForumPostDraft::newInstanceByDraftId($draftId);
104  $draftObj->setPostSubject($subjectFormatterCallback($inputValues['subject']));
105  $draftObj->setPostMessage(ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
106  $draftObj->setPostUserAlias($inputValues['alias']);
107  $draftObj->setNotificationStatus((bool) $inputValues['notify']);
108  $draftObj->setUpdateUserId($this->actor->getId());
109  $draftObj->setPostAuthorId($this->actor->getId());
110  $draftObj->setPostDisplayUserId(($this->forumProperties->isAnonymized() ? 0 : $this->actor->getId()));
111  $draftObj->updateDraft();
112 
113  $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
114  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $draftObj->getDraftId());
115  $curMediaObjects = ilRTE::_getMediaObjects($inputValues['message'], 0);
116 
117  $this->handleMedia(
119  $draftObj->getDraftId(),
120  $uploadedObjects,
121  $oldMediaObjects,
122  $curMediaObjects
123  );
124  } else {
125  $draftObj = new ilForumDraftsHistory();
126  $draftObj->setDraftId($draftId);
127  $draftObj->setPostSubject($subjectFormatterCallback($inputValues['subject']));
128  $draftObj->setPostMessage(ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
129  $draftObj->addDraftToHistory();
130 
131  $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
132  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $draftObj->getDraftId());
133  $curMediaObjects = ilRTE::_getMediaObjects($inputValues['message'], 0);
134 
135  $this->handleMedia(
137  $draftObj->getHistoryId(),
138  $uploadedObjects,
139  $oldMediaObjects,
140  $curMediaObjects
141  );
142  }
143  } else {
144  $draftObj = new ilForumPostDraft();
145  $draftObj->setForumId($this->relatedForumId);
146  $draftObj->setThreadId($this->thread->getId());
147  $draftObj->setPostId($relatedPostId);
148  $draftObj->setPostSubject($subjectFormatterCallback($inputValues['subject']));
149  $draftObj->setPostMessage(ilRTE::_replaceMediaObjectImageSrc($inputValues['message'], 0));
150  $draftObj->setPostUserAlias($inputValues['alias']);
151  $draftObj->setNotificationStatus((bool) $inputValues['notify']);
152  $draftObj->setPostAuthorId($this->actor->getId());
153  $draftObj->setPostDisplayUserId(($this->forumProperties->isAnonymized() ? 0 : $this->actor->getId()));
154  $draftObj->saveDraft();
155 
156  $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->actor->getId());
157  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $draftObj->getDraftId());
158  $curMediaObjects = ilRTE::_getMediaObjects($inputValues['message'], 0);
159 
160  $this->handleMedia(
162  $draftObj->getDraftId(),
163  $uploadedObjects,
164  $oldMediaObjects,
165  $curMediaObjects
166  );
167  }
168 
169  $response->draft_id = $draftObj->getDraftId();
170 
171  return $response;
172  }
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.
Class ilForumPostDraft.
handleMedia(string $type, int $draftId, array $uploadedObjects, array $oldMediaObjects, array $curMediaObjects)
Class ilForumDraftHistory.
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
form( $class_path, string $cmd)
static newInstanceByDraftId(int $draft_id)
$response
+ Here is the call graph for this function:

◆ getInputValuesFromForm()

ilForumAutoSaveAsyncDraftAction::getInputValuesFromForm ( )
protected

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

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

Referenced by executeAndGetResponseObject().

202  : array
203  {
204  $inputValues = [];
205 
206  $inputValues['subject'] = $this->form->getInput('subject');
207  $inputValues['message'] = $this->form->getInput('message');
208  $inputValues['notify'] = (int) $this->form->getInput('notify');
209  $inputValues['alias'] = ilForumUtil::getPublicUserAlias(
210  $this->form->getInput('alias'),
211  $this->forumProperties->isAnonymized()
212  );
213 
214  return $inputValues;
215  }
static getPublicUserAlias(string $user_alias, bool $is_anonymized)
form( $class_path, string $cmd)
+ 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 181 of file class.ilForumAutoSaveAsyncDraftAction.php.

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

Referenced by executeAndGetResponseObject().

187  : void {
188  foreach ($uploadedObjects as $mob) {
189  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $this->actor->getId());
190  ilObjMediaObject::_saveUsage($mob, $type, $draftId);
191  }
192 
193  foreach ($oldMediaObjects as $mob) {
194  ilObjMediaObject::_saveUsage($mob, $type, $draftId);
195  }
196 
197  foreach ($curMediaObjects as $mob) {
198  ilObjMediaObject::_saveUsage($mob, $type, $draftId);
199  }
200  }
$type
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:

Field Documentation

◆ $action

string ilForumAutoSaveAsyncDraftAction::$action
private

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

Referenced by __construct().

◆ $actor

ilObjUser ilForumAutoSaveAsyncDraftAction::$actor
private

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

Referenced by __construct().

◆ $form

ilPropertyFormGUI ilForumAutoSaveAsyncDraftAction::$form
private

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

Referenced by __construct().

◆ $forumProperties

ilForumProperties ilForumAutoSaveAsyncDraftAction::$forumProperties
private

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

Referenced by __construct().

◆ $relatedDraftId

int ilForumAutoSaveAsyncDraftAction::$relatedDraftId
private

◆ $relatedForumId

int ilForumAutoSaveAsyncDraftAction::$relatedForumId
private

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

Referenced by __construct().

◆ $relatedPost

ilForumPost ilForumAutoSaveAsyncDraftAction::$relatedPost
private

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

Referenced by __construct().

◆ $subjectFormatterCallable

Closure ilForumAutoSaveAsyncDraftAction::$subjectFormatterCallable
private

◆ $thread

ilForumTopic ilForumAutoSaveAsyncDraftAction::$thread
private

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

Referenced by __construct().


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